88
99namespace Magento \TwoFactorAuth \Test \Unit \Model \Provider \Engine ;
1010
11+ use Magento \User \Api \Data \UserInterface ;
1112use Magento \Framework \App \Config \ScopeConfigInterface ;
1213use Magento \TwoFactorAuth \Model \Provider \Engine \DuoSecurity ;
1314use PHPUnit \Framework \MockObject \MockObject ;
@@ -21,20 +22,32 @@ class DuoSecurityTest extends TestCase
2122 */
2223 private $ model ;
2324
25+ /**
26+ * @var DuoSecurity
27+ */
28+ private $ modelWithForcedDuoAuth ;
29+
2430 /**
2531 * @var ScopeConfigInterface|MockObject
2632 */
2733 private $ configMock ;
2834
35+ /**
36+ * @var UserInterface|MockObject
37+ */
38+ private $ user ;
39+
2940 /**
3041 * @inheritDoc
3142 */
3243 protected function setUp (): void
3344 {
3445 $ objectManager = new ObjectManager ($ this );
3546 $ this ->configMock = $ this ->getMockBuilder (ScopeConfigInterface::class)->disableOriginalConstructor ()->getMock ();
47+ $ this ->user = $ this ->getMockBuilder (UserInterface::class)->disableOriginalConstructor ()->getMock ();
3648
3749 $ this ->model = $ objectManager ->getObject (DuoSecurity::class, ['scopeConfig ' => $ this ->configMock ]);
50+ $ this ->modelWithForcedDuoAuth = new DuoSecurity ($ this ->configMock , $ this ->model ::DUO_PREFIX );
3851 }
3952
4053 /**
@@ -119,4 +132,26 @@ public function testIsEnabled(
119132
120133 $ this ->assertEquals ($ expected , $ this ->model ->isEnabled ());
121134 }
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+ }
122157}
0 commit comments