Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* 2.7: limited the maximum length of a submitted username
- Loading branch information
Showing
5 changed files
with
90 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
78 changes: 78 additions & 0 deletions
78
...Component/Security/Tests/Http/Firewall/UsernamePasswordFormAuthenticationListenerTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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), | ||
); | ||
} | ||
} |