|
14 | 14 | use PHPUnit\Framework\TestCase;
|
15 | 15 | use Symfony\Component\HttpFoundation\Request;
|
16 | 16 | use Symfony\Component\HttpFoundation\Response;
|
| 17 | +use Symfony\Component\HttpFoundation\Session\Session; |
| 18 | +use Symfony\Component\Security\Core\Authentication\AuthenticationProviderManager; |
| 19 | +use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorage; |
| 20 | +use Symfony\Component\Security\Http\Authentication\DefaultAuthenticationFailureHandler; |
| 21 | +use Symfony\Component\Security\Http\Authentication\DefaultAuthenticationSuccessHandler; |
17 | 22 | use Symfony\Component\Security\Http\Firewall\UsernamePasswordFormAuthenticationListener;
|
18 | 23 | use Symfony\Component\Security\Core\SecurityContextInterface;
|
| 24 | +use Symfony\Component\Security\Http\HttpUtils; |
| 25 | +use Symfony\Component\Security\Http\Session\SessionAuthenticationStrategy; |
19 | 26 |
|
20 | 27 | class UsernamePasswordFormAuthenticationListenerTest extends TestCase
|
21 | 28 | {
|
@@ -69,6 +76,36 @@ public function testHandleWhenUsernameLength($username, $ok)
|
69 | 76 | $listener->handle($event);
|
70 | 77 | }
|
71 | 78 |
|
| 79 | + /** |
| 80 | + * @expectedException \Symfony\Component\HttpKernel\Exception\BadRequestHttpException |
| 81 | + * @expectedExceptionMessage The key "_username" must be a string. |
| 82 | + */ |
| 83 | + public function testHandleNonStringUsername() |
| 84 | + { |
| 85 | + $request = Request::create('/login_check', 'POST', array('_username' => array())); |
| 86 | + $request->setSession(new Session()); |
| 87 | + |
| 88 | + $listener = new UsernamePasswordFormAuthenticationListener( |
| 89 | + new TokenStorage(), |
| 90 | + $this->getMockBuilder('Symfony\Component\Security\Core\Authentication\AuthenticationManagerInterface')->getMock(), |
| 91 | + new SessionAuthenticationStrategy(SessionAuthenticationStrategy::NONE), |
| 92 | + $httpUtils = new HttpUtils(), |
| 93 | + 'foo', |
| 94 | + new DefaultAuthenticationSuccessHandler($httpUtils), |
| 95 | + new DefaultAuthenticationFailureHandler($this->getMockBuilder('Symfony\Component\HttpKernel\HttpKernelInterface')->getMock(), $httpUtils), |
| 96 | + array('require_previous_session' => false) |
| 97 | + ); |
| 98 | + |
| 99 | + $event = $this->getMockBuilder('Symfony\Component\HttpKernel\Event\GetResponseEvent')->disableOriginalConstructor()->getMock(); |
| 100 | + $event |
| 101 | + ->expects($this->any()) |
| 102 | + ->method('getRequest') |
| 103 | + ->will($this->returnValue($request)) |
| 104 | + ; |
| 105 | + |
| 106 | + $listener->handle($event); |
| 107 | + } |
| 108 | + |
72 | 109 | public function getUsernameForLength()
|
73 | 110 | {
|
74 | 111 | return array(
|
|
0 commit comments