|
17 | 17 | use OxidEsales\Eshop\Core\Utils; |
18 | 18 | use OxidEsales\EshopCommunity\Core\Di\ContainerFacade; |
19 | 19 | use OxidEsales\EshopCommunity\Internal\Framework\Module\Facade\ModuleSettingServiceInterface; |
| 20 | +use DateTimeImmutable; |
| 21 | +use OxidEsales\SecurityModule\Authentication\TwoFactorAuth\OTP\Infrastructure\Repository\OtpChallengeStateRepositoryInterface; |
20 | 22 | use OxidEsales\SecurityModule\Authentication\TwoFactorAuth\Service\AuthorizeService; |
21 | 23 | use OxidEsales\SecurityModule\Authentication\TwoFactorAuth\Service\ModuleSettingsService; |
22 | 24 | use OxidEsales\SecurityModule\Captcha\Service\ModuleSettingsServiceInterface as CaptchaSettingsServiceInterface; |
23 | 25 | use OxidEsales\SecurityModule\Core\Module; |
24 | 26 | use OxidEsales\SecurityModule\Tests\Integration\IntegrationTestCase; |
25 | 27 |
|
| 28 | +// todo-critical: rework the 2FA part of the test. it changes the real configs on the fly and causing side effects |
26 | 29 | class UserTest extends IntegrationTestCase |
27 | 30 | { |
28 | 31 | private const OTP_USER_NAME = 'user@oxid-esales.com'; |
@@ -207,31 +210,24 @@ public function testLoginWithOTPEnabledStoresUserIdInSession(): void |
207 | 210 | $this->assertEquals($subject->getId(), $sessionUserId); |
208 | 211 | } |
209 | 212 |
|
210 | | - public function testLoginWithOTPPassSessionVariableSkipsOTPRedirect(): void |
| 213 | + public function testLoginWithVerifiedChallengeStateSkipsOTPRedirect(): void |
211 | 214 | { |
212 | 215 | $this->disableCaptcha(); |
213 | 216 | $this->enableTwoFactorAuth(); |
214 | 217 |
|
215 | | - $subject = oxNew(User::class); |
216 | | - $subject->load($this->getOTPUserId()); |
| 218 | + $userId = $this->getOTPUserId(); |
217 | 219 |
|
218 | | - Registry::getSession()->setVariable('OTP_PASS', $subject->getId()); |
| 220 | + $stateRepo = $this->get(OtpChallengeStateRepositoryInterface::class); |
| 221 | + $stateRepo->createChallengeState($userId, 'hash', new DateTimeImmutable('+5 minutes')); |
| 222 | + $stateRepo->markVerified($userId); |
219 | 223 |
|
220 | 224 | $utilsMock = $this->createMock(Utils::class); |
221 | 225 | $utilsMock->expects($this->never())->method('redirect'); |
222 | 226 | Registry::set(Utils::class, $utilsMock); |
223 | 227 |
|
224 | | - $result = $subject->login(self::OTP_USER_NAME, self::OTP_USER_PASSWORD); |
| 228 | + $result = oxNew(User::class)->login(self::OTP_USER_NAME, self::OTP_USER_PASSWORD); |
225 | 229 |
|
226 | 230 | $this->assertTrue($result); |
227 | | - $this->assertNull( |
228 | | - Registry::getSession()->getVariable('OTP_PASS'), |
229 | | - 'OTP_PASS session variable should be cleared after successful login' |
230 | | - ); |
231 | | - $this->assertNull( |
232 | | - Registry::getSession()->getVariable(AuthorizeService::USER_SESSION_KEY), |
233 | | - 'USER_SESSION_KEY should not be set when OTP was already validated' |
234 | | - ); |
235 | 231 | } |
236 | 232 |
|
237 | 233 | public function testLoginWithOTPPassSessionVariableMismatchTriggersOTPFlow(): void |
|
0 commit comments