Skip to content

Commit 38524f6

Browse files
committed
#AC-11762::Update 2FA OTP window field with correct description and default value after BiC change-fixes for static tests failures
1 parent 35f0e82 commit 38524f6

File tree

2 files changed

+19
-6
lines changed

2 files changed

+19
-6
lines changed

TwoFactorAuth/Model/Config/Backend/OtpWindow.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
class OtpWindow extends Value implements ProcessorInterface
1616
{
1717
/**
18+
* Fetch Totp default period value
19+
*
1820
* @return int
1921
*/
2022
private function getDefaultPeriod(): int
@@ -48,7 +50,13 @@ public function beforeSave()
4850
$value = $this->getValue();
4951
$period = $this->getDefaultPeriod();
5052
if (!is_numeric($value) || $value < 1 || $value >= $period) {
51-
throw new ValidatorException(__('Invalid OTP window value. It must be less than the OTP period value '.$period));
53+
throw new ValidatorException(
54+
__(
55+
'Invalid OTP window value. It must be between 1 and %1 as default period is %2',
56+
$period-1,
57+
$period
58+
)
59+
);
5260
}
5361

5462
return parent::beforeSave();

TwoFactorAuth/Setup/Patch/Data/UpdateOtpWindow.php

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,19 @@ class UpdateOtpWindow implements DataPatchInterface
1818
*/
1919
private $moduleDataSetup;
2020

21+
/**
22+
* @param ModuleDataSetupInterface $moduleDataSetup
23+
*/
2124
public function __construct(ModuleDataSetupInterface $moduleDataSetup)
2225
{
2326
$this->moduleDataSetup = $moduleDataSetup;
2427
}
2528

29+
/**
30+
* Fetch Totp default period
31+
*
32+
* @return int
33+
*/
2634
public function getDefaultPeriod()
2735
{
2836
return TOTPInterface::DEFAULT_PERIOD;
@@ -43,17 +51,15 @@ public function apply()
4351
$period = $this->getDefaultPeriod();
4452
if ($existingValue && $existingValue >= $period) {
4553
$newWindowValue = $period - 1;
46-
}
47-
48-
if ($existingValue) {
4954
$setup->update(
5055
'core_config_data',
5156
['value' => $newWindowValue],
5257
'path = "twofactorauth/google/otp_window"'
5358
);
5459
}
55-
5660
$setup->endSetup();
61+
62+
return $this;
5763
}
5864

5965
/**
@@ -71,5 +77,4 @@ public function getAliases()
7177
{
7278
return [];
7379
}
74-
7580
}

0 commit comments

Comments
 (0)