Skip to content

Commit 0c8a8a1

Browse files
Merge pull request #15 from magento-cia/MC-37956
Bugfixes
2 parents 2986d8c + c31096a commit 0c8a8a1

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

TwoFactorAuth/Controller/Adminhtml/Tfa/Requestconfig.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ class Requestconfig extends AbstractAction implements HttpGetActionInterface, Ht
3030
*/
3131
public const ADMIN_RESOURCE = 'Magento_TwoFactorAuth::tfa';
3232

33+
private const TFA_EMAIL_SENT = 'tfa_email_sent';
34+
3335
/**
3436
* @var UserConfigRequestManagerInterface
3537
*/
@@ -89,7 +91,10 @@ public function execute()
8991
}
9092

9193
try {
92-
$this->configRequestManager->sendConfigRequestTo($user);
94+
if (!$this->session->getData(self::TFA_EMAIL_SENT)) {
95+
$this->configRequestManager->sendConfigRequestTo($user);
96+
$this->session->setData(self::TFA_EMAIL_SENT, true);
97+
}
9398
} catch (AuthorizationException $exception) {
9499
$this->messageManager->addErrorMessage(
95100
'Please ask an administrator with sufficient access to configure 2FA first'

TwoFactorAuth/Test/Integration/Controller/Adminhtml/Tfa/RequestconfigTest.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
use Magento\TwoFactorAuth\Api\TfaInterface;
1414
use Magento\TwoFactorAuth\Api\UserConfigTokenManagerInterface;
1515
use Magento\TwoFactorAuth\Model\Provider\Engine\Google;
16+
use Magento\Backend\Model\Auth\Session;
1617

1718
/**
1819
* Testing the controller for the page that requests 2FA config from users.
@@ -37,6 +38,11 @@ class RequestconfigTest extends AbstractBackendController
3738
*/
3839
private $tokenManager;
3940

41+
/**
42+
* @var Session
43+
*/
44+
private $session;
45+
4046
/**
4147
* @inheritDoc
4248
*/
@@ -46,6 +52,7 @@ protected function setUp(): void
4652

4753
$this->tfa = Bootstrap::getObjectManager()->get(TfaInterface::class);
4854
$this->tokenManager = Bootstrap::getObjectManager()->get(UserConfigTokenManagerInterface::class);
55+
$this->session = Bootstrap::getObjectManager()->get(Session::class);
4956
}
5057

5158
/**
@@ -117,4 +124,21 @@ public function testRedirectToUserConfig(): void
117124
$this->dispatch($this->uri);
118125
$this->assertRedirect($this->stringContains('tfa/index'));
119126
}
127+
128+
/**
129+
* Verify that session flag is set when 2FA config email is sent to the user.
130+
*
131+
* @return void
132+
* @magentoConfigFixture default/twofactorauth/general/force_providers google
133+
*/
134+
public function testUserConfigRequestedFlag(): void
135+
{
136+
$this->assertNull($this->session->getData('tfa_email_sent'));
137+
$this->dispatch($this->uri);
138+
self::assertMatchesRegularExpression(
139+
'/You need to configure Two\-Factor Authorization/',
140+
$this->getResponse()->getBody()
141+
);
142+
$this->assertTrue($this->session->getData('tfa_email_sent'));
143+
}
120144
}

0 commit comments

Comments
 (0)