|
23 | 23 | use Symfony\Component\Security\Http\Authenticator\FormLoginAuthenticator;
|
24 | 24 | use Symfony\Component\Security\Http\Authenticator\Passport\Badge\CsrfTokenBadge;
|
25 | 25 | use Symfony\Component\Security\Http\Authenticator\Passport\Badge\PasswordUpgradeBadge;
|
| 26 | +use Symfony\Component\Security\Http\Authenticator\Passport\Credentials\PasswordCredentials; |
26 | 27 | use Symfony\Component\Security\Http\HttpUtils;
|
27 | 28 | use Symfony\Component\Security\Http\Tests\Authenticator\Fixtures\PasswordUpgraderProvider;
|
28 | 29 |
|
@@ -126,6 +127,44 @@ public function testHandleNonStringUsernameWithToString($postOnly)
|
126 | 127 | $this->authenticator->authenticate($request);
|
127 | 128 | }
|
128 | 129 |
|
| 130 | + /** |
| 131 | + * @dataProvider postOnlyDataProvider |
| 132 | + */ |
| 133 | + public function testHandleNonStringPasswordWithArray(bool $postOnly) |
| 134 | + { |
| 135 | + $this->expectException(BadRequestHttpException::class); |
| 136 | + $this->expectExceptionMessage('The key "_password" must be a string, "array" given.'); |
| 137 | + |
| 138 | + $request = Request::create('/login_check', 'POST', ['_username' => 'foo', '_password' => []]); |
| 139 | + $request->setSession($this->createSession()); |
| 140 | + |
| 141 | + $this->setUpAuthenticator(['post_only' => $postOnly]); |
| 142 | + $this->authenticator->authenticate($request); |
| 143 | + } |
| 144 | + |
| 145 | + /** |
| 146 | + * @dataProvider postOnlyDataProvider |
| 147 | + */ |
| 148 | + public function testHandleNonStringPasswordWithToString(bool $postOnly) |
| 149 | + { |
| 150 | + $passwordObject = new class() { |
| 151 | + public function __toString() |
| 152 | + { |
| 153 | + return 's$cr$t'; |
| 154 | + } |
| 155 | + }; |
| 156 | + |
| 157 | + $request = Request::create('/login_check', 'POST', ['_username' => 'foo', '_password' => $passwordObject]); |
| 158 | + $request->setSession($this->createSession()); |
| 159 | + |
| 160 | + $this->setUpAuthenticator(['post_only' => $postOnly]); |
| 161 | + $passport = $this->authenticator->authenticate($request); |
| 162 | + |
| 163 | + /** @var PasswordCredentials $credentialsBadge */ |
| 164 | + $credentialsBadge = $passport->getBadge(PasswordCredentials::class); |
| 165 | + $this->assertSame('s$cr$t', $credentialsBadge->getPassword()); |
| 166 | + } |
| 167 | + |
129 | 168 | public static function postOnlyDataProvider()
|
130 | 169 | {
|
131 | 170 | yield [true];
|
|
0 commit comments