8
8
9
9
namespace Magento \TwoFactorAuth \Test \Unit \Model \Provider \Engine ;
10
10
11
+ use Magento \User \Api \Data \UserInterface ;
11
12
use Magento \Framework \App \Config \ScopeConfigInterface ;
12
13
use Magento \TwoFactorAuth \Model \Provider \Engine \DuoSecurity ;
13
14
use PHPUnit \Framework \MockObject \MockObject ;
@@ -21,20 +22,32 @@ class DuoSecurityTest extends TestCase
21
22
*/
22
23
private $ model ;
23
24
25
+ /**
26
+ * @var DuoSecurity
27
+ */
28
+ private $ modelWithForcedDuoAuth ;
29
+
24
30
/**
25
31
* @var ScopeConfigInterface|MockObject
26
32
*/
27
33
private $ configMock ;
28
34
35
+ /**
36
+ * @var UserInterface|MockObject
37
+ */
38
+ private $ user ;
39
+
29
40
/**
30
41
* @inheritDoc
31
42
*/
32
43
protected function setUp (): void
33
44
{
34
45
$ objectManager = new ObjectManager ($ this );
35
46
$ this ->configMock = $ this ->getMockBuilder (ScopeConfigInterface::class)->disableOriginalConstructor ()->getMock ();
47
+ $ this ->user = $ this ->getMockBuilder (UserInterface::class)->disableOriginalConstructor ()->getMock ();
36
48
37
49
$ this ->model = $ objectManager ->getObject (DuoSecurity::class, ['scopeConfig ' => $ this ->configMock ]);
50
+ $ this ->modelWithForcedDuoAuth = new DuoSecurity ($ this ->configMock , $ this ->model ::DUO_PREFIX );
38
51
}
39
52
40
53
/**
@@ -119,4 +132,26 @@ public function testIsEnabled(
119
132
120
133
$ this ->assertEquals ($ expected , $ this ->model ->isEnabled ());
121
134
}
135
+
136
+ public function testGetRequestSignature () : void
137
+ {
138
+ $ this ->user ->expects ($ this ->any ())
139
+ ->method ('getUserName ' )
140
+ ->willReturn ('admin ' );
141
+ $ this ->configMock ->expects ($ this ->any ())
142
+ ->method ('getValue ' )
143
+ ->willReturn ('SECRET ' );
144
+
145
+ $ this ->assertStringContainsString ($ this ->model ::AUTH_PREFIX , $ this ->model ->getRequestSignature ($ this ->user ));
146
+ $ this ->assertStringNotContainsString ($ this ->model ::DUO_PREFIX , $ this ->model ->getRequestSignature ($ this ->user ));
147
+
148
+ $ this ->assertStringContainsString (
149
+ $ this ->model ::DUO_PREFIX ,
150
+ $ this ->modelWithForcedDuoAuth ->getRequestSignature ($ this ->user )
151
+ );
152
+ $ this ->assertStringNotContainsString (
153
+ $ this ->model ::AUTH_PREFIX ,
154
+ $ this ->modelWithForcedDuoAuth ->getRequestSignature ($ this ->user )
155
+ );
156
+ }
122
157
}
0 commit comments