Skip to content

Commit bc14f2a

Browse files
committed
OXDEV-9078 Invalidate the challenge after the login
1 parent 48d48ad commit bc14f2a

2 files changed

Lines changed: 10 additions & 1 deletion

File tree

src/Authentication/TwoFactorAuth/Service/TwoFAUserService.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ public function loginUser(string $userId): void
4949
$this->session->remove(self::USER_SESSION_KEY);
5050

5151
$this->loginAdapter->loginUser($userId);
52+
$this->twoFAService->invalidateChallenge($userId);
5253

5354
$this->utils->redirect($this->redirectService->getRedirectUrl(), false);
5455
}

tests/Unit/Authentication/TwoFactorAuth/Service/TwoFAUserServiceTest.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,10 +83,17 @@ public function isChallengeVerifiedProxiesToTwoFAService(): void
8383
#[Test]
8484
public function loginUserLoadsUserLoginsClearsSessionAndRedirects(): void
8585
{
86+
$userId = uniqid();
87+
8688
$loginAdapterSpy = $this->createMock(UserLoginAdapterInterface::class);
8789
$loginAdapterSpy->expects($this->once())
8890
->method('loginUser')
89-
->with($userId = uniqid());
91+
->with($userId);
92+
93+
$twoFAServiceSpy = $this->createMock(TwoFAServiceInterface::class);
94+
$twoFAServiceSpy->expects($this->once())
95+
->method('invalidateChallenge')
96+
->with($userId);
9097

9198
$sessionSpy = $this->createMock(SessionInterface::class);
9299
$sessionSpy->expects($this->once())
@@ -100,6 +107,7 @@ public function loginUserLoadsUserLoginsClearsSessionAndRedirects(): void
100107
$utilsSpy->expects($this->once())->method('redirect')->with($redirectUrl, false);
101108

102109
$sut = $this->getSut(
110+
twoFAService: $twoFAServiceSpy,
103111
loginAdapter: $loginAdapterSpy,
104112
session: $sessionSpy,
105113
redirectService: $redirectServiceStub,

0 commit comments

Comments
 (0)