@@ -191,6 +191,32 @@ public function testSwitchUser()
191
191
$ this ->assertInstanceOf ('Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken ' , $ this ->tokenStorage ->getToken ());
192
192
}
193
193
194
+ public function testSwitchUserWorksWithFalsyUsernames ()
195
+ {
196
+ $ token = new UsernamePasswordToken ('username ' , '' , 'key ' , ['ROLE_FOO ' ]);
197
+ $ user = new User ('username ' , 'password ' , []);
198
+
199
+ $ this ->tokenStorage ->setToken ($ token );
200
+ $ this ->request ->query ->set ('_switch_user ' , '0 ' );
201
+
202
+ $ this ->accessDecisionManager ->expects ($ this ->once ())
203
+ ->method ('decide ' )->with ($ token , ['ROLE_ALLOWED_TO_SWITCH ' ])
204
+ ->willReturn (true );
205
+
206
+ $ this ->userProvider ->expects ($ this ->once ())
207
+ ->method ('loadUserByUsername ' )->with ('0 ' )
208
+ ->willReturn ($ user );
209
+ $ this ->userChecker ->expects ($ this ->once ())
210
+ ->method ('checkPostAuth ' )->with ($ user );
211
+
212
+ $ listener = new SwitchUserListener ($ this ->tokenStorage , $ this ->userProvider , $ this ->userChecker , 'provider123 ' , $ this ->accessDecisionManager );
213
+ $ listener ->handle ($ this ->event );
214
+
215
+ $ this ->assertSame ([], $ this ->request ->query ->all ());
216
+ $ this ->assertSame ('' , $ this ->request ->server ->get ('QUERY_STRING ' ));
217
+ $ this ->assertInstanceOf ('Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken ' , $ this ->tokenStorage ->getToken ());
218
+ }
219
+
194
220
public function testSwitchUserKeepsOtherQueryStringParameters ()
195
221
{
196
222
$ token = new UsernamePasswordToken ('username ' , '' , 'key ' , ['ROLE_FOO ' ]);
0 commit comments