Skip to content

Commit 3164218

Browse files
committed
Merge branch 'AC-11762-8MAY' of https://github.com/magento-gl/security-package into AC-11762-8MAY
2 parents 94c2dae + 245f6fe commit 3164218

File tree

3 files changed

+50
-2
lines changed

3 files changed

+50
-2
lines changed

TwoFactorAuth/Model/Provider/Engine/DuoSecurity.php

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,13 +77,21 @@ class DuoSecurity implements EngineInterface
7777
*/
7878
private $scopeConfig;
7979

80+
/**
81+
* @var string
82+
*/
83+
private $duoSignaturePrefix;
84+
8085
/**
8186
* @param ScopeConfigInterface $scopeConfig
87+
* @param string $duoSignaturePrefix
8288
*/
8389
public function __construct(
84-
ScopeConfigInterface $scopeConfig
90+
ScopeConfigInterface $scopeConfig,
91+
string $duoSignaturePrefix = self::AUTH_PREFIX
8592
) {
8693
$this->scopeConfig = $scopeConfig;
94+
$this->duoSignaturePrefix = $duoSignaturePrefix;
8795
}
8896

8997
/**
@@ -208,7 +216,7 @@ public function getRequestSignature(UserInterface $user): string
208216
$duoSignature = $this->signValues(
209217
$this->getSecretKey(),
210218
$values,
211-
static::DUO_PREFIX,
219+
$this->duoSignaturePrefix,
212220
static::DUO_EXPIRE,
213221
$time
214222
);

TwoFactorAuth/Test/Unit/Model/Provider/Engine/DuoSecurityTest.php

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
namespace Magento\TwoFactorAuth\Test\Unit\Model\Provider\Engine;
1010

11+
use Magento\User\Api\Data\UserInterface;
1112
use Magento\Framework\App\Config\ScopeConfigInterface;
1213
use Magento\TwoFactorAuth\Model\Provider\Engine\DuoSecurity;
1314
use 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
}

TwoFactorAuth/etc/adminhtml/di.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,9 @@
2121
<type name="Magento\Backend\Model\Auth">
2222
<plugin name="delete_tfat_cookie" type="Magento\TwoFactorAuth\Plugin\DeleteCookieOnLogout"/>
2323
</type>
24+
<type name="Magento\TwoFactorAuth\Model\Provider\Engine\DuoSecurity">
25+
<arguments>
26+
<argument name="duoSignaturePrefix" xsi:type="const">Magento\TwoFactorAuth\Model\Provider\Engine\DuoSecurity::DUO_PREFIX</argument>
27+
</arguments>
28+
</type>
2429
</config>

0 commit comments

Comments
 (0)