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
@@ -129,7 +130,7 @@ public function testHandleNonStringUsernameWithToString($postOnly)
129
130
/**
130
131
* @dataProvider postOnlyDataProvider
131
132
*/
132
- public function testHandleNonStringPasswordWithArray ($ postOnly )
133
+ public function testHandleNonStringPasswordWithArray (bool $ postOnly )
133
134
{
134
135
$ this ->expectException (BadRequestHttpException::class);
135
136
$ this ->expectExceptionMessage ('The key "_password" must be a string, "array" given. ' );
@@ -144,16 +145,24 @@ public function testHandleNonStringPasswordWithArray($postOnly)
144
145
/**
145
146
* @dataProvider postOnlyDataProvider
146
147
*/
147
- public function testHandleNonStringPasswordWithInt ( $ postOnly )
148
+ public function testHandleNonStringPasswordWithToString ( bool $ postOnly )
148
149
{
149
- $ this ->expectException (BadRequestHttpException::class);
150
- $ this ->expectExceptionMessage ('The key "_password" must be a string, "integer" given. ' );
150
+ $ passwordObject = new class () {
151
+ public function __toString ()
152
+ {
153
+ return 's$cr$t ' ;
154
+ }
155
+ };
151
156
152
- $ request = Request::create ('/login_check ' , 'POST ' , ['_username ' => 'foo ' , '_password ' => 42 ]);
157
+ $ request = Request::create ('/login_check ' , 'POST ' , ['_username ' => 'foo ' , '_password ' => $ passwordObject ]);
153
158
$ request ->setSession ($ this ->createSession ());
154
159
155
160
$ this ->setUpAuthenticator (['post_only ' => $ postOnly ]);
156
- $ this ->authenticator ->authenticate ($ request );
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 ());
157
166
}
158
167
159
168
public static function postOnlyDataProvider ()
0 commit comments