|
| 1 | +<?php |
| 2 | + |
| 3 | +/* |
| 4 | + * This file is part of the Symfony framework. |
| 5 | + * |
| 6 | + * (c) Fabien Potencier <fabien@symfony.com> |
| 7 | + * |
| 8 | + * This source file is subject to the MIT license that is bundled |
| 9 | + * with this source code in the file LICENSE. |
| 10 | + */ |
| 11 | + |
| 12 | +namespace Symfony\Tests\Component\Security\Http\Firewall; |
| 13 | + |
| 14 | +use Symfony\Component\HttpFoundation\Request; |
| 15 | +use Symfony\Component\Security\Http\Firewall\ContextListener; |
| 16 | + |
| 17 | +class ContextListenerTest extends \PHPUnit_Framework_TestCase |
| 18 | +{ |
| 19 | + /** |
| 20 | + * @dataProvider provideInvalidToken |
| 21 | + */ |
| 22 | + public function testInvalidTokenInSession($token) |
| 23 | + { |
| 24 | + $context = $this->getMock('Symfony\Component\Security\Core\SecurityContextInterface'); |
| 25 | + $event = $this->getMockBuilder('Symfony\Component\HttpKernel\Event\GetResponseEvent') |
| 26 | + ->disableOriginalConstructor() |
| 27 | + ->getMock(); |
| 28 | + $request = $this->getMock('Symfony\Component\HttpFoundation\Request'); |
| 29 | + $session = $this->getMockBuilder('Symfony\Component\HttpFoundation\Session') |
| 30 | + ->disableOriginalConstructor() |
| 31 | + ->getMock(); |
| 32 | + |
| 33 | + $event->expects($this->any()) |
| 34 | + ->method('getRequest') |
| 35 | + ->will($this->returnValue($request)); |
| 36 | + $request->expects($this->any()) |
| 37 | + ->method('hasPreviousSession') |
| 38 | + ->will($this->returnValue(true)); |
| 39 | + $request->expects($this->any()) |
| 40 | + ->method('getSession') |
| 41 | + ->will($this->returnValue($session)); |
| 42 | + $session->expects($this->any()) |
| 43 | + ->method('get') |
| 44 | + ->with('_security_key123') |
| 45 | + ->will($this->returnValue(serialize($token))); |
| 46 | + $context->expects($this->once()) |
| 47 | + ->method('setToken') |
| 48 | + ->with(null); |
| 49 | + |
| 50 | + $listener = new ContextListener($context, array(), 'key123'); |
| 51 | + $listener->handle($event); |
| 52 | + } |
| 53 | + |
| 54 | + public function provideInvalidToken() |
| 55 | + { |
| 56 | + return array( |
| 57 | + array(new \__PHP_Incomplete_Class()), |
| 58 | + array(null), |
| 59 | + ); |
| 60 | + } |
| 61 | +} |
0 commit comments