Skip to content

Commit 170cd75

Browse files
committed
#AC-11762::Update 2FA OTP window field with correct description and default value after BiC change-command logic changes and upgrade data script for otp window with Bic changes
1 parent 1531ec2 commit 170cd75

File tree

7 files changed

+15
-15
lines changed

7 files changed

+15
-15
lines changed

TwoFactorAuth/Model/Config/Backend/OtpWindow.php renamed to TwoFactorAuth/Model/Config/Backend/Leeway.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
use Magento\Framework\Exception\ValidatorException;
1313
use OTPHP\TOTPInterface;
1414

15-
class OtpWindow extends Value implements ProcessorInterface
15+
class Leeway extends Value implements ProcessorInterface
1616
{
1717
/**
1818
* Fetch Totp default period value
@@ -34,7 +34,7 @@ private function getDefaultPeriod(): int
3434
public function processValue($value)
3535
{
3636
if (!is_numeric($value)) {
37-
throw new ValidatorException(__('The OTP window must be a numeric value.'));
37+
throw new ValidatorException(__('The Leeway must be a numeric value.'));
3838
}
3939
$numericValue = (int) $value;
4040
return $numericValue;
@@ -52,7 +52,7 @@ public function beforeSave()
5252
if (!is_numeric($value) || $value < 1 || $value >= $period) {
5353
throw new ValidatorException(
5454
__(
55-
'Invalid OTP window value. It must be between 1 and %1 as default period is %2',
55+
'Invalid Leeway value. It must be between 1 and %1 as default period is %2',
5656
$period-1,
5757
$period
5858
)

TwoFactorAuth/Model/Provider/Engine/Google.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ class Google implements EngineInterface
3535
/**
3636
* Config path for the OTP window
3737
*/
38-
const XML_PATH_OTP_WINDOW = 'twofactorauth/google/otp_window';
38+
public const XML_PATH_LEEWAY = 'twofactorauth/google/leeway';
3939

4040
/**
4141
* Engine code
@@ -199,7 +199,7 @@ public function verify(UserInterface $user, DataObject $request): bool
199199
return $totp->verify(
200200
$token,
201201
null,
202-
$config['window'] ?? (int)$this->scopeConfig->getValue(self::XML_PATH_OTP_WINDOW) ?: null
202+
$config['window'] ?? (int)$this->scopeConfig->getValue(self::XML_PATH_LEEWAY) ?: null
203203
);
204204
}
205205

TwoFactorAuth/Setup/Patch/Data/UpdateOtpWindow.php renamed to TwoFactorAuth/Setup/Patch/Data/UpdateLeeway.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
use Magento\Framework\Setup\ModuleDataSetupInterface;
1212
use OTPHP\TOTPInterface;
1313

14-
class UpdateOtpWindow implements DataPatchInterface
14+
class UpdateLeeway implements DataPatchInterface
1515
{
1616
/**
1717
* @var ModuleDataSetupInterface
@@ -45,7 +45,7 @@ public function apply()
4545
$setup->startSetup();
4646
$select = $setup->select()
4747
->from('core_config_data', ['path'])
48-
->where('path = ?', 'twofactorauth/google/otp_window');
48+
->where('path = ?', 'twofactorauth/google/leeway');
4949

5050
$existingValue = $setup->fetchOne($select);
5151
$period = $this->getDefaultPeriod();
@@ -54,7 +54,7 @@ public function apply()
5454
$setup->update(
5555
'core_config_data',
5656
['value' => $newWindowValue],
57-
'path = "twofactorauth/google/otp_window"'
57+
'path = "twofactorauth/google/leeway"'
5858
);
5959
}
6060
$setup->endSetup();

TwoFactorAuth/Test/Api/GoogleActivateTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ public function testAlreadyActivatedProvider()
129129
/**
130130
* @magentoConfigFixture twofactorauth/general/force_providers google
131131
* @magentoApiDataFixture Magento/User/_files/user_with_custom_role.php
132-
* @magentoConfigFixture twofactorauth/google/otp_window 20
132+
* @magentoConfigFixture twofactorauth/google/leeway 29
133133
*/
134134
public function testActivate()
135135
{

TwoFactorAuth/Test/Api/GoogleAuthenticateTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ public function testNotConfiguredProvider(): void
223223
/**
224224
* @magentoConfigFixture twofactorauth/general/force_providers google
225225
* @magentoApiDataFixture Magento/User/_files/user_with_custom_role.php
226-
* @magentoConfigFixture twofactorauth/google/otp_window 20
226+
* @magentoConfigFixture twofactorauth/google/leeway 29
227227
*
228228
* @return void
229229
*/

TwoFactorAuth/etc/adminhtml/system.xml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,11 @@
3939
<group id="google" translate="label" type="text" sortOrder="30" showInDefault="1" showInWebsite="0"
4040
showInStore="0">
4141
<label>Google</label>
42-
<field id="otp_window" translate="label comment" type="text" sortOrder="10" showInDefault="1"
42+
<field id="leeway" translate="label comment" type="text" sortOrder="10" showInDefault="1"
4343
showInWebsite="0" showInStore="0" canRestore="1">
44-
<label>OTP Window</label>
45-
<comment>This determines how long the one-time-passwords are valid for. An OTP Window of 1 will result in the current OTP value plus 1 code in the past and 1 code in the future to be valid at any given point in time.</comment>
46-
<backend_model>Magento\TwoFactorAuth\Model\Config\Backend\OtpWindow</backend_model>
44+
<label>Leeway</label>
45+
<comment>This sets the time drift leeway for OTPs. A leeway of 29 with a period of 30 means OTPs are valid within ±29 seconds from the current time. The leeway must be smaller than the period</comment>
46+
<backend_model>Magento\TwoFactorAuth\Model\Config\Backend\Leeway</backend_model>
4747
</field>
4848
</group>
4949
<group id="duo" translate="label" type="text" sortOrder="40" showInDefault="1" showInWebsite="0"

TwoFactorAuth/etc/config.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
<application_key backend_model="Magento\Config\Model\Config\Backend\Encrypted"/>
2222
</duo>
2323
<google>
24-
<otp_window backend_model="Magento\TwoFactorAuth\Model\Config\Backend\OtpWindow">1</otp_window>
24+
<leeway backend_model="Magento\TwoFactorAuth\Model\Config\Backend\Leeway">29</leeway>
2525
</google>
2626
</twofactorauth>
2727
</default>

0 commit comments

Comments
 (0)