Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
avoid fatal error on invalid session
- Loading branch information
1 parent
3d32a0b
commit c51fc10
Showing
2 changed files
with
76 additions
and
8 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
61 changes: 61 additions & 0 deletions
61
tests/Symfony/Tests/Component/Security/Http/Firewall/ContextListenerTest.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,61 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony framework. | ||
* | ||
* (c) Fabien Potencier <fabien@symfony.com> | ||
* | ||
* This source file is subject to the MIT license that is bundled | ||
* with this source code in the file LICENSE. | ||
*/ | ||
|
||
namespace Symfony\Tests\Component\Security\Http\Firewall; | ||
|
||
use Symfony\Component\HttpFoundation\Request; | ||
use Symfony\Component\Security\Http\Firewall\ContextListener; | ||
|
||
class ContextListenerTest extends \PHPUnit_Framework_TestCase | ||
{ | ||
/** | ||
* @dataProvider provideInvalidToken | ||
*/ | ||
public function testInvalidTokenInSession($token) | ||
{ | ||
$context = $this->getMock('Symfony\Component\Security\Core\SecurityContextInterface'); | ||
$event = $this->getMockBuilder('Symfony\Component\HttpKernel\Event\GetResponseEvent') | ||
->disableOriginalConstructor() | ||
->getMock(); | ||
$request = $this->getMock('Symfony\Component\HttpFoundation\Request'); | ||
$session = $this->getMockBuilder('Symfony\Component\HttpFoundation\Session') | ||
->disableOriginalConstructor() | ||
->getMock(); | ||
|
||
$event->expects($this->any()) | ||
->method('getRequest') | ||
->will($this->returnValue($request)); | ||
$request->expects($this->any()) | ||
->method('hasPreviousSession') | ||
->will($this->returnValue(true)); | ||
$request->expects($this->any()) | ||
->method('getSession') | ||
->will($this->returnValue($session)); | ||
$session->expects($this->any()) | ||
->method('get') | ||
->with('_security_key123') | ||
->will($this->returnValue(serialize($token))); | ||
$context->expects($this->once()) | ||
->method('setToken') | ||
->with(null); | ||
|
||
$listener = new ContextListener($context, array(), 'key123'); | ||
$listener->handle($event); | ||
} | ||
|
||
public function provideInvalidToken() | ||
{ | ||
return array( | ||
array(new \__PHP_Incomplete_Class()), | ||
array(null), | ||
); | ||
} | ||
} |