[SecurityBundle] Backport test

This commit is contained in:
Robin Chalas 2018-02-09 13:55:03 +01:00
parent f7d9701cdf
commit d195a6f060

View File

@ -77,14 +77,14 @@ class UsernamePasswordFormAuthenticationListenerTest extends TestCase
} }
/** /**
* @dataProvider postOnlyDataProvider
* @expectedException \Symfony\Component\HttpKernel\Exception\BadRequestHttpException * @expectedException \Symfony\Component\HttpKernel\Exception\BadRequestHttpException
* @expectedExceptionMessage The key "_username" must be a string, "array" given. * @expectedExceptionMessage The key "_username" must be a string, "array" given.
*/ */
public function testHandleNonStringUsername() public function testHandleNonStringUsername($postOnly)
{ {
$request = Request::create('/login_check', 'POST', array('_username' => array())); $request = Request::create('/login_check', 'POST', array('_username' => array()));
$request->setSession($this->getMockBuilder('Symfony\Component\HttpFoundation\Session\SessionInterface')->getMock()); $request->setSession($this->getMockBuilder('Symfony\Component\HttpFoundation\Session\SessionInterface')->getMock());
$listener = new UsernamePasswordFormAuthenticationListener( $listener = new UsernamePasswordFormAuthenticationListener(
new TokenStorage(), new TokenStorage(),
$this->getMockBuilder('Symfony\Component\Security\Core\Authentication\AuthenticationManagerInterface')->getMock(), $this->getMockBuilder('Symfony\Component\Security\Core\Authentication\AuthenticationManagerInterface')->getMock(),
@ -93,14 +93,20 @@ class UsernamePasswordFormAuthenticationListenerTest extends TestCase
'foo', 'foo',
new DefaultAuthenticationSuccessHandler($httpUtils), new DefaultAuthenticationSuccessHandler($httpUtils),
new DefaultAuthenticationFailureHandler($this->getMockBuilder('Symfony\Component\HttpKernel\HttpKernelInterface')->getMock(), $httpUtils), new DefaultAuthenticationFailureHandler($this->getMockBuilder('Symfony\Component\HttpKernel\HttpKernelInterface')->getMock(), $httpUtils),
array('require_previous_session' => false) array('require_previous_session' => false, 'post_only' => $postOnly)
); );
$event = new GetResponseEvent($this->getMockBuilder('Symfony\Component\HttpKernel\HttpKernelInterface')->getMock(), $request, HttpKernelInterface::MASTER_REQUEST); $event = new GetResponseEvent($this->getMockBuilder('Symfony\Component\HttpKernel\HttpKernelInterface')->getMock(), $request, HttpKernelInterface::MASTER_REQUEST);
$listener->handle($event); $listener->handle($event);
} }
public function postOnlyDataProvider()
{
return array(
array(true),
array(false),
);
}
public function getUsernameForLength() public function getUsernameForLength()
{ {
return array( return array(