Skip to content

Commit e937649

Browse files
committed
Don't populate IdentifierCollection errors with empty nested arrays
1 parent ad4c3c9 commit e937649

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

src/Identifier/IdentifierCollection.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,11 @@ public function identify(array $credentials): ArrayAccess|array|null
5656

5757
return $result;
5858
}
59-
$this->_errors[$name] = $identifier->getErrors();
59+
60+
$errors = $identifier->getErrors();
61+
if ($errors) {
62+
$this->_errors[$name] = $identifier->getErrors();
63+
}
6064
}
6165

6266
$this->_successfulIdentifier = null;

tests/TestCase/Authenticator/FormAuthenticatorTest.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,27 @@ public function testCredentialsEmpty()
112112
$this->assertEquals([0 => 'Login credentials not found'], $result->getErrors());
113113
}
114114

115+
public function testIdentityNotFound()
116+
{
117+
$identifiers = new IdentifierCollection([
118+
'Authentication.Password',
119+
]);
120+
121+
$request = ServerRequestFactory::fromGlobals(
122+
['REQUEST_URI' => '/users/does-not-match'],
123+
[],
124+
['username' => 'non-existent', 'password' => 'password'],
125+
);
126+
127+
$form = new FormAuthenticator($identifiers);
128+
129+
$result = $form->authenticate($request);
130+
131+
$this->assertInstanceOf(Result::class, $result);
132+
$this->assertSame(Result::FAILURE_IDENTITY_NOT_FOUND, $result->getStatus());
133+
$this->assertSame([], $result->getErrors());
134+
}
135+
115136
/**
116137
* testSingleLoginUrlMismatch
117138
*

0 commit comments

Comments
 (0)