diff --git a/src/Identifier/IdentifierCollection.php b/src/Identifier/IdentifierCollection.php index ec49d1dc..257b25d8 100644 --- a/src/Identifier/IdentifierCollection.php +++ b/src/Identifier/IdentifierCollection.php @@ -56,7 +56,11 @@ public function identify(array $credentials): ArrayAccess|array|null return $result; } - $this->_errors[$name] = $identifier->getErrors(); + + $errors = $identifier->getErrors(); + if ($errors) { + $this->_errors[$name] = $identifier->getErrors(); + } } $this->_successfulIdentifier = null; diff --git a/tests/TestCase/Authenticator/FormAuthenticatorTest.php b/tests/TestCase/Authenticator/FormAuthenticatorTest.php index 3287f961..45df94f5 100644 --- a/tests/TestCase/Authenticator/FormAuthenticatorTest.php +++ b/tests/TestCase/Authenticator/FormAuthenticatorTest.php @@ -112,6 +112,27 @@ public function testCredentialsEmpty() $this->assertEquals([0 => 'Login credentials not found'], $result->getErrors()); } + public function testIdentityNotFound() + { + $identifiers = new IdentifierCollection([ + 'Authentication.Password', + ]); + + $request = ServerRequestFactory::fromGlobals( + ['REQUEST_URI' => '/users/does-not-match'], + [], + ['username' => 'non-existent', 'password' => 'password'], + ); + + $form = new FormAuthenticator($identifiers); + + $result = $form->authenticate($request); + + $this->assertInstanceOf(Result::class, $result); + $this->assertSame(Result::FAILURE_IDENTITY_NOT_FOUND, $result->getStatus()); + $this->assertSame([], $result->getErrors()); + } + /** * testSingleLoginUrlMismatch *