1717use CodeIgniter \Shield \Authentication \Authentication ;
1818use CodeIgniter \Shield \Authentication \AuthenticationException ;
1919use CodeIgniter \Shield \Authentication \Authenticators \Session ;
20+ use CodeIgniter \Shield \Authentication \Passwords ;
2021use CodeIgniter \Shield \Config \Auth ;
2122use CodeIgniter \Shield \Entities \User ;
2223use CodeIgniter \Shield \Exceptions \LogicException ;
@@ -272,6 +273,29 @@ public function testCheckCannotFindUser(): void
272273 $ this ->assertSame (lang ('Auth.badAttempt ' ), $ result ->reason ());
273274 }
274275
276+ public function testCheckUnknownUserStillVerifiesPassword (): void
277+ {
278+ $ passwords = new class (new Auth ()) extends Passwords {
279+ public array $ checks = [];
280+
281+ public function verify (string $ password , string $ hash ): bool
282+ {
283+ $ this ->checks [] = [$ password , $ hash ];
284+
285+ return false ;
286+ }
287+ };
288+ Services::injectMock ('passwords ' , $ passwords );
289+
290+ $ result = $ this ->auth ->check ([
291+ 'email ' => 'unknown@example.com ' ,
292+ 'password ' => 'secret ' ,
293+ ]);
294+
295+ $ this ->assertFalse ($ result ->isOK ());
296+ $ this ->assertSame ([['secret ' , config ('Auth ' )->dummyPasswordHash ]], $ passwords ->checks );
297+ }
298+
275299 public function testCheckBadPassword (): void
276300 {
277301 $ this ->user ->createEmailIdentity ([
@@ -286,7 +310,7 @@ public function testCheckBadPassword(): void
286310
287311 $ this ->assertInstanceOf (Result::class, $ result );
288312 $ this ->assertFalse ($ result ->isOK ());
289- $ this ->assertSame (lang ('Auth.invalidPassword ' ), $ result ->reason ());
313+ $ this ->assertSame (lang ('Auth.badAttempt ' ), $ result ->reason ());
290314 }
291315
292316 public function testCheckSuccess (): void
0 commit comments