1
1
<?php
2
2
/**
3
- * Copyright 2024 Adobe
4
- * All rights reserved.
5
- * See COPYING.txt for license details.
3
+ * Copyright 2020 Adobe
4
+ * All Rights Reserved.
6
5
*/
7
6
8
7
declare (strict_types=1 );
9
8
10
9
namespace Magento \TwoFactorAuth \Test \Unit \Model \Provider \Engine ;
11
10
12
- use Magento \User \Api \Data \UserInterface ;
13
11
use Magento \Framework \App \Config \ScopeConfigInterface ;
12
+ use Magento \Framework \DataObject ;
13
+ use Magento \Framework \UrlInterface ;
14
14
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 ;
15
18
use PHPUnit \Framework \MockObject \MockObject ;
16
19
use PHPUnit \Framework \TestCase ;
17
- use Magento \Framework \TestFramework \Unit \Helper \ObjectManager ;
18
20
19
21
class DuoSecurityTest extends TestCase
20
22
{
21
- /**
22
- * @var DuoSecurity
23
- */
24
- private $ model ;
23
+ /** @var MockObject|ScopeConfigInterface */
24
+ private $ configMock ;
25
25
26
- /**
27
- * @var DuoSecurity
28
- */
29
- private $ modelWithForcedDuoAuth ;
26
+ /** @var MockObject|UrlInterface */
27
+ private $ urlMock ;
30
28
31
- /**
32
- * @var ScopeConfigInterface|MockObject
33
- */
34
- private $ configMock ;
29
+ /** @var MockObject|Client */
30
+ private $ clientMock ;
35
31
36
32
/**
37
- * @var UserInterface |MockObject
33
+ * @var DuoAuth |MockObject
38
34
*/
39
- private $ user ;
35
+ private $ duoAuthMock ;
36
+
37
+ /** @var DuoSecurity */
38
+ private $ model ;
40
39
41
- /**
42
- * @inheritDoc
43
- */
44
40
protected function setUp (): void
45
41
{
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 ();
49
45
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
+ );
52
59
}
53
60
54
61
/**
@@ -60,46 +67,11 @@ public static function getIsEnabledTestDataSet(): array
60
67
{
61
68
return [
62
69
[
63
- 'value ' ,
64
- 'value ' ,
65
- 'value ' ,
66
- 'value ' ,
70
+ 'test.duosecurity.com ' ,
71
+ 'ABCDEFGHIJKLMNOPQRST ' ,
72
+ 'abcdefghijklmnopqrstuvwxyz0123456789abcd ' ,
73
+ 'google,duo_security,authy ' ,
67
74
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
103
75
]
104
76
];
105
77
}
@@ -108,51 +80,28 @@ public static function getIsEnabledTestDataSet(): array
108
80
* Check that the provider is available based on configuration.
109
81
*
110
82
* @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
114
85
* @param bool $expected
115
86
* @return void
116
87
* @dataProvider getIsEnabledTestDataSet
117
88
*/
118
89
public function testIsEnabled (
119
90
?string $ apiHostname ,
120
- ?string $ appKey ,
121
- ?string $ secretKey ,
122
- ? string $ integrationKey ,
91
+ ?string $ clientId ,
92
+ ?string $ clientSecret ,
93
+ string $ forceProviders ,
123
94
bool $ expected
124
95
): void {
125
96
$ this ->configMock ->method ('getValue ' )->willReturnMap (
126
97
[
127
98
[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 ]
131
102
]
132
103
);
133
104
134
105
$ this ->assertEquals ($ expected , $ this ->model ->isEnabled ());
135
106
}
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
- }
158
107
}
0 commit comments