summaryrefslogtreecommitdiffstats
path: root/Tests/Http
diff options
context:
space:
mode:
authorFabien Potencier <fabien.potencier@gmail.com>2016-05-09 14:24:00 -0500
committerFabien Potencier <fabien.potencier@gmail.com>2016-05-09 14:24:00 -0500
commit231aafdaf4c9abbc812139bd6f909008fec91cd7 (patch)
treefcb9f7445dd5d955fae4b6bee33884344997be5d /Tests/Http
parent9e447f3c6d7cd5ac712a967840edcd504f488ca2 (diff)
parent1eebd2bd10b38c068aa05aa123201c53def1bc6d (diff)
downloadsymfony-security-231aafdaf4c9abbc812139bd6f909008fec91cd7.zip
symfony-security-231aafdaf4c9abbc812139bd6f909008fec91cd7.tar.gz
symfony-security-231aafdaf4c9abbc812139bd6f909008fec91cd7.tar.bz2
Merge branch '2.7' into 2.8
* 2.7: limited the maximum length of a submitted username
Diffstat (limited to 'Tests/Http')
-rw-r--r--Tests/Http/Firewall/UsernamePasswordFormAuthenticationListenerTest.php78
1 files changed, 78 insertions, 0 deletions
diff --git a/Tests/Http/Firewall/UsernamePasswordFormAuthenticationListenerTest.php b/Tests/Http/Firewall/UsernamePasswordFormAuthenticationListenerTest.php
new file mode 100644
index 0000000..b7c6ab9
--- /dev/null
+++ b/Tests/Http/Firewall/UsernamePasswordFormAuthenticationListenerTest.php
@@ -0,0 +1,78 @@
+<?php
+
+/*
+ * This file is part of the Symfony package.
+ *
+ * (c) Fabien Potencier <fabien@symfony.com>
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+namespace Symfony\Component\Security\Tests\Http\Firewall;
+
+use Symfony\Component\HttpFoundation\Request;
+use Symfony\Component\HttpFoundation\Response;
+use Symfony\Component\Security\Http\Firewall\UsernamePasswordFormAuthenticationListener;
+use Symfony\Component\Security\Core\SecurityContextInterface;
+
+class UsernamePasswordFormAuthenticationListenerTest extends \PHPUnit_Framework_TestCase
+{
+ /**
+ * @dataProvider getUsernameForLength
+ */
+ public function testHandleWhenUsernameLength($username, $ok)
+ {
+ $request = Request::create('/login_check', 'POST', array('_username' => $username));
+ $request->setSession($this->getMock('Symfony\Component\HttpFoundation\Session\SessionInterface'));
+
+ $httpUtils = $this->getMock('Symfony\Component\Security\Http\HttpUtils');
+ $httpUtils
+ ->expects($this->any())
+ ->method('checkRequestPath')
+ ->will($this->returnValue(true))
+ ;
+
+ $failureHandler = $this->getMock('Symfony\Component\Security\Http\Authentication\AuthenticationFailureHandlerInterface');
+ $failureHandler
+ ->expects($ok ? $this->never() : $this->once())
+ ->method('onAuthenticationFailure')
+ ->will($this->returnValue(new Response()))
+ ;
+
+ $authenticationManager = $this->getMockBuilder('Symfony\Component\Security\Core\Authentication\AuthenticationProviderManager')->disableOriginalConstructor()->getMock();
+ $authenticationManager
+ ->expects($ok ? $this->once() : $this->never())
+ ->method('authenticate')
+ ->will($this->returnValue(new Response()))
+ ;
+
+ $listener = new UsernamePasswordFormAuthenticationListener(
+ $this->getMock('Symfony\Component\Security\Core\SecurityContextInterface'),
+ $authenticationManager,
+ $this->getMock('Symfony\Component\Security\Http\Session\SessionAuthenticationStrategyInterface'),
+ $httpUtils,
+ 'TheProviderKey',
+ $this->getMock('Symfony\Component\Security\Http\Authentication\AuthenticationSuccessHandlerInterface'),
+ $failureHandler,
+ array('require_previous_session' => false)
+ );
+
+ $event = $this->getMock('Symfony\Component\HttpKernel\Event\GetResponseEvent', array(), array(), '', false);
+ $event
+ ->expects($this->any())
+ ->method('getRequest')
+ ->will($this->returnValue($request))
+ ;
+
+ $listener->handle($event);
+ }
+
+ public function getUsernameForLength()
+ {
+ return array(
+ array(str_repeat('x', SecurityContextInterface::MAX_USERNAME_LENGTH + 1), false),
+ array(str_repeat('x', SecurityContextInterface::MAX_USERNAME_LENGTH - 1), true),
+ );
+ }
+}