Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…package into develop
  • Loading branch information
mage-os-ci committed May 10, 2024
2 parents 73e52db + 412fa64 commit c8fe8b7
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 2 deletions.
12 changes: 10 additions & 2 deletions TwoFactorAuth/Model/Provider/Engine/DuoSecurity.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,13 +77,21 @@ class DuoSecurity implements EngineInterface
*/
private $scopeConfig;

/**
* @var string
*/
private $duoSignaturePrefix;

/**
* @param ScopeConfigInterface $scopeConfig
* @param string $duoSignaturePrefix
*/
public function __construct(
ScopeConfigInterface $scopeConfig
ScopeConfigInterface $scopeConfig,
string $duoSignaturePrefix = self::AUTH_PREFIX
) {
$this->scopeConfig = $scopeConfig;
$this->duoSignaturePrefix = $duoSignaturePrefix;
}

/**
Expand Down Expand Up @@ -208,7 +216,7 @@ public function getRequestSignature(UserInterface $user): string
$duoSignature = $this->signValues(
$this->getSecretKey(),
$values,
static::DUO_PREFIX,
$this->duoSignaturePrefix,
static::DUO_EXPIRE,
$time
);
Expand Down
35 changes: 35 additions & 0 deletions TwoFactorAuth/Test/Unit/Model/Provider/Engine/DuoSecurityTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

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

use Magento\User\Api\Data\UserInterface;
use Magento\Framework\App\Config\ScopeConfigInterface;
use Magento\TwoFactorAuth\Model\Provider\Engine\DuoSecurity;
use PHPUnit\Framework\MockObject\MockObject;
Expand All @@ -21,20 +22,32 @@ class DuoSecurityTest extends TestCase
*/
private $model;

/**
* @var DuoSecurity
*/
private $modelWithForcedDuoAuth;

/**
* @var ScopeConfigInterface|MockObject
*/
private $configMock;

/**
* @var UserInterface|MockObject
*/
private $user;

/**
* @inheritDoc
*/
protected function setUp(): void
{
$objectManager = new ObjectManager($this);
$this->configMock = $this->getMockBuilder(ScopeConfigInterface::class)->disableOriginalConstructor()->getMock();
$this->user = $this->getMockBuilder(UserInterface::class)->disableOriginalConstructor()->getMock();

$this->model = $objectManager->getObject(DuoSecurity::class, ['scopeConfig' => $this->configMock]);
$this->modelWithForcedDuoAuth = new DuoSecurity($this->configMock, $this->model::DUO_PREFIX);
}

/**
Expand Down Expand Up @@ -119,4 +132,26 @@ public function testIsEnabled(

$this->assertEquals($expected, $this->model->isEnabled());
}

public function testGetRequestSignature() : void
{
$this->user->expects($this->any())
->method('getUserName')
->willReturn('admin');
$this->configMock->expects($this->any())
->method('getValue')
->willReturn('SECRET');

$this->assertStringContainsString($this->model::AUTH_PREFIX, $this->model->getRequestSignature($this->user));
$this->assertStringNotContainsString($this->model::DUO_PREFIX, $this->model->getRequestSignature($this->user));

$this->assertStringContainsString(
$this->model::DUO_PREFIX,
$this->modelWithForcedDuoAuth->getRequestSignature($this->user)
);
$this->assertStringNotContainsString(
$this->model::AUTH_PREFIX,
$this->modelWithForcedDuoAuth->getRequestSignature($this->user)
);
}
}
5 changes: 5 additions & 0 deletions TwoFactorAuth/etc/adminhtml/di.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,9 @@
<type name="Magento\Backend\Model\Auth">
<plugin name="delete_tfat_cookie" type="Magento\TwoFactorAuth\Plugin\DeleteCookieOnLogout"/>
</type>
<type name="Magento\TwoFactorAuth\Model\Provider\Engine\DuoSecurity">
<arguments>
<argument name="duoSignaturePrefix" xsi:type="const">Magento\TwoFactorAuth\Model\Provider\Engine\DuoSecurity::DUO_PREFIX</argument>
</arguments>
</type>
</config>

0 comments on commit c8fe8b7

Please sign in to comment.