Skip to content

Commit 3b90224

Browse files
committed
OXDEV-9078 Set challenge as verified if there are no verification errors
1 parent 7b5d760 commit 3b90224

2 files changed

Lines changed: 34 additions & 0 deletions

File tree

src/Authentication/TwoFactorAuth/OTP/OtpFacade.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ public function invalidateChallenge(string $userId): void
6060
public function verify(string $userId, #[\SensitiveParameter] string $code): void
6161
{
6262
$this->codeValidator->validateCode($userId, $code);
63+
$this->stateService->markVerified($userId);
6364
}
6465

6566
public function resend(string $userId): void

tests/Unit/Authentication/TwoFactorAuth/OTP/OtpFacadeTest.php

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,39 @@ public function verifyTriggersCodeValidator(): void
118118
$sut->verify(userId: $userId, code: $code);
119119
}
120120

121+
#[Test]
122+
public function verifyMarksChallengAsVerifiedIfValidationOk(): void
123+
{
124+
$stateServiceSpy = $this->createMock(OtpChallengeStateServiceInterface::class);
125+
$stateServiceSpy->expects($this->once())
126+
->method('markVerified')
127+
->with($userId = uniqid());
128+
129+
$sut = $this->getSut(stateService: $stateServiceSpy);
130+
131+
$sut->verify(userId: $userId, code: uniqid());
132+
}
133+
134+
#[Test]
135+
public function verifyDoesNotMarkVerifiedWhenValidationFails(): void
136+
{
137+
$codeValidatorStub = $this->createStub(OtpCodeValidatorServiceInterface::class);
138+
$codeValidatorStub->method('validateCode')->willThrowException(new InvalidCodeException());
139+
140+
$stateServiceSpy = $this->createMock(OtpChallengeStateServiceInterface::class);
141+
$stateServiceSpy->expects($this->never())
142+
->method('markVerified');
143+
144+
$sut = $this->getSut(
145+
stateService: $stateServiceSpy,
146+
codeValidator: $codeValidatorStub,
147+
);
148+
149+
$this->expectException(InvalidCodeException::class);
150+
151+
$sut->verify(userId: uniqid(), code: uniqid());
152+
}
153+
121154
#[Test]
122155
public function triggerChallengeGeneratesCodeCreatesStateAndNotifies(): void
123156
{

0 commit comments

Comments
 (0)