File tree Expand file tree Collapse file tree
src/Authentication/TwoFactorAuth/OTP
tests/Unit/Authentication/TwoFactorAuth/OTP Expand file tree Collapse file tree Original file line number Diff line number Diff 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
Original file line number Diff line number Diff 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 {
You can’t perform that action at this time.
0 commit comments