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