Skip to content

Commit ee9dcee

Browse files
cia-2.4.8-beta2-develop-2.4-develop-sync-01132025: resolve conflict
1 parent 9a260da commit ee9dcee

File tree

1 file changed

+46
-97
lines changed

1 file changed

+46
-97
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,61 @@
11
<?php
22
/**
3-
* Copyright 2024 Adobe
4-
* All rights reserved.
5-
* See COPYING.txt for license details.
3+
* Copyright 2020 Adobe
4+
* All Rights Reserved.
65
*/
76

87
declare(strict_types=1);
98

109
namespace Magento\TwoFactorAuth\Test\Unit\Model\Provider\Engine;
1110

12-
use Magento\User\Api\Data\UserInterface;
1311
use Magento\Framework\App\Config\ScopeConfigInterface;
12+
use Magento\Framework\DataObject;
13+
use Magento\Framework\UrlInterface;
1414
use Magento\TwoFactorAuth\Model\Provider\Engine\DuoSecurity;
15+
use Magento\User\Api\Data\UserInterface;
16+
use Duo\DuoUniversal\Client;
17+
use DuoAPI\Auth as DuoAuth;
1518
use PHPUnit\Framework\MockObject\MockObject;
1619
use PHPUnit\Framework\TestCase;
17-
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
1820

1921
class DuoSecurityTest extends TestCase
2022
{
21-
/**
22-
* @var DuoSecurity
23-
*/
24-
private $model;
23+
/** @var MockObject|ScopeConfigInterface */
24+
private $configMock;
2525

26-
/**
27-
* @var DuoSecurity
28-
*/
29-
private $modelWithForcedDuoAuth;
26+
/** @var MockObject|UrlInterface */
27+
private $urlMock;
3028

31-
/**
32-
* @var ScopeConfigInterface|MockObject
33-
*/
34-
private $configMock;
29+
/** @var MockObject|Client */
30+
private $clientMock;
3531

3632
/**
37-
* @var UserInterface|MockObject
33+
* @var DuoAuth|MockObject
3834
*/
39-
private $user;
35+
private $duoAuthMock;
36+
37+
/** @var DuoSecurity */
38+
private $model;
4039

41-
/**
42-
* @inheritDoc
43-
*/
4440
protected function setUp(): void
4541
{
46-
$objectManager = new ObjectManager($this);
47-
$this->configMock = $this->getMockBuilder(ScopeConfigInterface::class)->disableOriginalConstructor()->getMock();
48-
$this->user = $this->getMockBuilder(UserInterface::class)->disableOriginalConstructor()->getMock();
42+
$this->configMock = $this->getMockBuilder(ScopeConfigInterface::class)
43+
->disableOriginalConstructor()
44+
->getMock();
4945

50-
$this->model = $objectManager->getObject(DuoSecurity::class, ['scopeConfig' => $this->configMock]);
51-
$this->modelWithForcedDuoAuth = new DuoSecurity($this->configMock, $this->model::DUO_PREFIX);
46+
$this->urlMock = $this->getMockBuilder(UrlInterface::class)
47+
->disableOriginalConstructor()
48+
->getMock();
49+
50+
$this->clientMock = $this->createMock(Client::class);
51+
$this->duoAuthMock = $this->createMock(DuoAuth::class);
52+
53+
$this->model = new DuoSecurity(
54+
$this->configMock,
55+
$this->urlMock,
56+
$this->clientMock,
57+
$this->duoAuthMock
58+
);
5259
}
5360

5461
/**
@@ -60,46 +67,11 @@ public static function getIsEnabledTestDataSet(): array
6067
{
6168
return [
6269
[
63-
'value',
64-
'value',
65-
'value',
66-
'value',
70+
'test.duosecurity.com',
71+
'ABCDEFGHIJKLMNOPQRST',
72+
'abcdefghijklmnopqrstuvwxyz0123456789abcd',
73+
'google,duo_security,authy',
6774
true
68-
],
69-
[
70-
null,
71-
null,
72-
null,
73-
null,
74-
false
75-
],
76-
[
77-
'value',
78-
null,
79-
null,
80-
null,
81-
false
82-
],
83-
[
84-
null,
85-
'value',
86-
null,
87-
null,
88-
false
89-
],
90-
[
91-
null,
92-
null,
93-
'value',
94-
null,
95-
false
96-
],
97-
[
98-
null,
99-
null,
100-
null,
101-
'value',
102-
false
10375
]
10476
];
10577
}
@@ -108,51 +80,28 @@ public static function getIsEnabledTestDataSet(): array
10880
* Check that the provider is available based on configuration.
10981
*
11082
* @param string|null $apiHostname
111-
* @param string|null $appKey
112-
* @param string|null $secretKey
113-
* @param string|null $integrationKey
83+
* @param string|null $clientId
84+
* @param string|null $clientSecret
11485
* @param bool $expected
11586
* @return void
11687
* @dataProvider getIsEnabledTestDataSet
11788
*/
11889
public function testIsEnabled(
11990
?string $apiHostname,
120-
?string $appKey,
121-
?string $secretKey,
122-
?string $integrationKey,
91+
?string $clientId,
92+
?string $clientSecret,
93+
string $forceProviders,
12394
bool $expected
12495
): void {
12596
$this->configMock->method('getValue')->willReturnMap(
12697
[
12798
[DuoSecurity::XML_PATH_API_HOSTNAME, 'default', null, $apiHostname],
128-
[DuoSecurity::XML_PATH_APPLICATION_KEY, 'default', null, $appKey],
129-
[DuoSecurity::XML_PATH_SECRET_KEY, 'default', null, $secretKey],
130-
[DuoSecurity::XML_PATH_INTEGRATION_KEY, 'default', null, $integrationKey]
99+
[DuoSecurity::XML_PATH_CLIENT_ID, 'default', null, $clientId],
100+
[DuoSecurity::XML_PATH_CLIENT_SECRET, 'default', null, $clientSecret],
101+
['twofactorauth/general/force_providers', 'default', null, $forceProviders]
131102
]
132103
);
133104

134105
$this->assertEquals($expected, $this->model->isEnabled());
135106
}
136-
137-
public function testGetRequestSignature() : void
138-
{
139-
$this->user->expects($this->any())
140-
->method('getUserName')
141-
->willReturn('admin');
142-
$this->configMock->expects($this->any())
143-
->method('getValue')
144-
->willReturn('SECRET');
145-
146-
$this->assertStringContainsString($this->model::AUTH_PREFIX, $this->model->getRequestSignature($this->user));
147-
$this->assertStringNotContainsString($this->model::DUO_PREFIX, $this->model->getRequestSignature($this->user));
148-
149-
$this->assertStringContainsString(
150-
$this->model::DUO_PREFIX,
151-
$this->modelWithForcedDuoAuth->getRequestSignature($this->user)
152-
);
153-
$this->assertStringNotContainsString(
154-
$this->model::AUTH_PREFIX,
155-
$this->modelWithForcedDuoAuth->getRequestSignature($this->user)
156-
);
157-
}
158107
}

0 commit comments

Comments
 (0)