Skip to content

Commit 19c76d2

Browse files
committed
MC-22950: Enable 2FA by default for Admins
- Removed redundant code - Fixed corner case with skipping configuration - fixed tests that don't cleanup
1 parent ffaf7a9 commit 19c76d2

19 files changed

+38
-29
lines changed

TwoFactorAuth/Controller/Adminhtml/Tfa/Index.php

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,9 @@ public function execute()
118118
$providerCode = '';
119119

120120
$defaultProviderCode = $this->userConfigManager->getDefaultProvider((int) $user->getId());
121-
if ($this->tfa->getProviderIsAllowed((int) $user->getId(), $defaultProviderCode)) {
121+
if ($this->tfa->getProviderIsAllowed((int) $user->getId(), $defaultProviderCode)
122+
&& $this->tfa->getProvider($defaultProviderCode)->isActive((int) $user->getId())
123+
) {
122124
//If default provider was configured - select it.
123125
$providerCode = $defaultProviderCode;
124126
}
@@ -128,8 +130,16 @@ public function execute()
128130
$providers = $this->tfa->getUserProviders((int) $user->getId());
129131
if (!empty($providers)) {
130132
foreach ($providers as $enabledProvider) {
131-
$providerCode = $enabledProvider->getCode();
132-
break;
133+
/*
134+
* The user has skipped all providers that need to be configured but there is
135+
* also at least one already configured
136+
*/
137+
if (!in_array($enabledProvider->getCode(), $currentlySkipped)
138+
&& !in_array($enabledProvider->getCode(), $toActivateCodes)
139+
) {
140+
$providerCode = $enabledProvider->getCode();
141+
break;
142+
}
133143
}
134144
}
135145
}

TwoFactorAuth/Test/Integration/Block/ChangeProviderTest.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@
2020
use Magento\TwoFactorAuth\Model\Provider\Engine\Google;
2121
use PHPUnit\Framework\TestCase;
2222

23+
/**
24+
* @magentoDbIsolation enabled
25+
*/
2326
class ChangeProviderTest extends TestCase
2427
{
2528
/**

TwoFactorAuth/Test/Integration/Controller/Adminhtml/Authy/ConfigureTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
* Test for the configure authy 2FA form page.
1111
*
1212
* @magentoAppArea adminhtml
13+
* @magentoDbIsolation enabled
1314
*/
1415
class ConfigureTest extends AbstractConfigureBackendController
1516
{

TwoFactorAuth/Test/Integration/Controller/Adminhtml/Authy/ConfigurepostTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
* Test for the configure authy 2FA form processor.
1111
*
1212
* @magentoAppArea adminhtml
13+
* @magentoDbIsolation enabled
1314
*/
1415
class ConfigurepostTest extends AbstractConfigureBackendController
1516
{

TwoFactorAuth/Test/Integration/Controller/Adminhtml/Authy/ConfigureverifypostTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
* Test for the configure authy 2FA form processor.
1111
*
1212
* @magentoAppArea adminhtml
13+
* @magentoDbIsolation enabled
1314
*/
1415
class ConfigureverifypostTest extends AbstractConfigureBackendController
1516
{

TwoFactorAuth/Test/Integration/Controller/Adminhtml/Duo/AuthTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
* Test for the DuoSecurity form.
1111
*
1212
* @magentoAppArea adminhtml
13+
* @magentoDbIsolation enabled
1314
*/
1415
class AuthTest extends AbstractConfigureBackendController
1516
{

TwoFactorAuth/Test/Integration/Controller/Adminhtml/Duo/AuthpostTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
* Test for the DuoSecurity form processor.
1111
*
1212
* @magentoAppArea adminhtml
13+
* @magentoDbIsolation enabled
1314
*/
1415
class AuthpostTest extends AbstractConfigureBackendController
1516
{

TwoFactorAuth/Test/Integration/Controller/Adminhtml/Google/ConfigureTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
* Test for the configure google 2FA form page.
1111
*
1212
* @magentoAppArea adminhtml
13+
* @magentoDbIsolation enabled
1314
*/
1415
class ConfigureTest extends AbstractConfigureBackendController
1516
{

TwoFactorAuth/Test/Integration/Controller/Adminhtml/Google/ConfigurepostTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
* Test for the configure google 2FA form page processor.
1111
*
1212
* @magentoAppArea adminhtml
13+
* @magentoDbIsolation enabled
1314
*/
1415
class ConfigurepostTest extends AbstractConfigureBackendController
1516
{

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
* Testing the controller for the page that presents forced providers list to users.
1313
*
1414
* @magentoAppArea adminhtml
15+
* @magentoDbIsolation enabled
1516
*/
1617
class ConfigureTest extends AbstractBackendController
1718
{

0 commit comments

Comments
 (0)