summaryrefslogtreecommitdiffstats
path: root/Http/Tests
diff options
context:
space:
mode:
Diffstat (limited to 'Http/Tests')
-rw-r--r--Http/Tests/Authentication/DefaultAuthenticationFailureHandlerTest.php10
-rw-r--r--Http/Tests/Firewall/AbstractPreAuthenticatedListenerTest.php38
-rw-r--r--Http/Tests/Firewall/AccessListenerTest.php28
-rw-r--r--Http/Tests/Firewall/AnonymousAuthenticationListenerTest.php26
-rw-r--r--Http/Tests/Firewall/BasicAuthenticationListenerTest.php38
-rw-r--r--Http/Tests/Firewall/ContextListenerTest.php50
-rw-r--r--Http/Tests/Firewall/ExceptionListenerTest.php12
-rw-r--r--Http/Tests/Firewall/LogoutListenerTest.php28
-rw-r--r--Http/Tests/Firewall/RememberMeListenerTest.php40
-rw-r--r--Http/Tests/Firewall/RemoteUserAuthenticationListenerTest.php12
-rw-r--r--Http/Tests/Firewall/SimplePreAuthenticationListenerTest.php128
-rw-r--r--Http/Tests/Firewall/SwitchUserListenerTest.php40
-rw-r--r--Http/Tests/Firewall/X509AuthenticationListenerTest.php16
13 files changed, 293 insertions, 173 deletions
diff --git a/Http/Tests/Authentication/DefaultAuthenticationFailureHandlerTest.php b/Http/Tests/Authentication/DefaultAuthenticationFailureHandlerTest.php
index f642096..82b5533 100644
--- a/Http/Tests/Authentication/DefaultAuthenticationFailureHandlerTest.php
+++ b/Http/Tests/Authentication/DefaultAuthenticationFailureHandlerTest.php
@@ -105,7 +105,10 @@ class DefaultAuthenticationFailureHandlerTest extends \PHPUnit_Framework_TestCas
public function testRedirectIsLogged()
{
- $this->logger->expects($this->once())->method('debug')->with('Redirecting to /login');
+ $this->logger
+ ->expects($this->once())
+ ->method('debug')
+ ->with('Authentication failure, redirect triggered.', array('failure_path' => '/login'));
$handler = new DefaultAuthenticationFailureHandler($this->httpKernel, $this->httpUtils, array(), $this->logger);
$handler->onAuthenticationFailure($this->request, $this->exception);
@@ -119,7 +122,10 @@ class DefaultAuthenticationFailureHandlerTest extends \PHPUnit_Framework_TestCas
->method('createRequest')->with($this->request, '/login')
->will($this->returnValue($this->getRequest()));
- $this->logger->expects($this->once())->method('debug')->with('Forwarding to /login');
+ $this->logger
+ ->expects($this->once())
+ ->method('debug')
+ ->with('Authentication failure, forward triggered.', array('failure_path' => '/login'));
$handler = new DefaultAuthenticationFailureHandler($this->httpKernel, $this->httpUtils, $options, $this->logger);
$handler->onAuthenticationFailure($this->request, $this->exception);
diff --git a/Http/Tests/Firewall/AbstractPreAuthenticatedListenerTest.php b/Http/Tests/Firewall/AbstractPreAuthenticatedListenerTest.php
index 6e34532..61f086a 100644
--- a/Http/Tests/Firewall/AbstractPreAuthenticatedListenerTest.php
+++ b/Http/Tests/Firewall/AbstractPreAuthenticatedListenerTest.php
@@ -26,13 +26,13 @@ class AbstractPreAuthenticatedListenerTest extends \PHPUnit_Framework_TestCase
$token = $this->getMock('Symfony\Component\Security\Core\Authentication\Token\TokenInterface');
- $context = $this->getMock('Symfony\Component\Security\Core\SecurityContextInterface');
- $context
+ $tokenStorage = $this->getMock('Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface');
+ $tokenStorage
->expects($this->any())
->method('getToken')
->will($this->returnValue(null))
;
- $context
+ $tokenStorage
->expects($this->once())
->method('setToken')
->with($this->equalTo($token))
@@ -47,7 +47,7 @@ class AbstractPreAuthenticatedListenerTest extends \PHPUnit_Framework_TestCase
;
$listener = $this->getMockForAbstractClass('Symfony\Component\Security\Http\Firewall\AbstractPreAuthenticatedListener', array(
- $context,
+ $tokenStorage,
$authenticationManager,
'TheProviderKey',
));
@@ -72,13 +72,13 @@ class AbstractPreAuthenticatedListenerTest extends \PHPUnit_Framework_TestCase
$request = new Request(array(), array(), array(), array(), array(), array());
- $context = $this->getMock('Symfony\Component\Security\Core\SecurityContextInterface');
- $context
+ $tokenStorage = $this->getMock('Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface');
+ $tokenStorage
->expects($this->any())
->method('getToken')
->will($this->returnValue(null))
;
- $context
+ $tokenStorage
->expects($this->never())
->method('setToken')
;
@@ -93,7 +93,7 @@ class AbstractPreAuthenticatedListenerTest extends \PHPUnit_Framework_TestCase
;
$listener = $this->getMockForAbstractClass('Symfony\Component\Security\Http\Firewall\AbstractPreAuthenticatedListener', array(
- $context,
+ $tokenStorage,
$authenticationManager,
'TheProviderKey',
));
@@ -120,13 +120,13 @@ class AbstractPreAuthenticatedListenerTest extends \PHPUnit_Framework_TestCase
$request = new Request(array(), array(), array(), array(), array(), array());
- $context = $this->getMock('Symfony\Component\Security\Core\SecurityContextInterface');
- $context
+ $tokenStorage = $this->getMock('Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface');
+ $tokenStorage
->expects($this->any())
->method('getToken')
->will($this->returnValue($token))
;
- $context
+ $tokenStorage
->expects($this->never())
->method('setToken')
;
@@ -141,7 +141,7 @@ class AbstractPreAuthenticatedListenerTest extends \PHPUnit_Framework_TestCase
;
$listener = $this->getMockForAbstractClass('Symfony\Component\Security\Http\Firewall\AbstractPreAuthenticatedListener', array(
- $context,
+ $tokenStorage,
$authenticationManager,
'TheProviderKey',
));
@@ -168,8 +168,8 @@ class AbstractPreAuthenticatedListenerTest extends \PHPUnit_Framework_TestCase
$token = new PreAuthenticatedToken('TheUser', 'TheCredentials', 'TheProviderKey', array('ROLE_FOO'));
- $context = $this->getMock('Symfony\Component\Security\Core\SecurityContextInterface');
- $context
+ $tokenStorage = $this->getMock('Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface');
+ $tokenStorage
->expects($this->any())
->method('getToken')
->will($this->returnValue($token))
@@ -182,7 +182,7 @@ class AbstractPreAuthenticatedListenerTest extends \PHPUnit_Framework_TestCase
;
$listener = $this->getMockForAbstractClass('Symfony\Component\Security\Http\Firewall\AbstractPreAuthenticatedListener', array(
- $context,
+ $tokenStorage,
$authenticationManager,
'TheProviderKey',
));
@@ -209,13 +209,13 @@ class AbstractPreAuthenticatedListenerTest extends \PHPUnit_Framework_TestCase
$token = new PreAuthenticatedToken('AnotherUser', 'TheCredentials', 'TheProviderKey', array('ROLE_FOO'));
- $context = $this->getMock('Symfony\Component\Security\Core\SecurityContextInterface');
- $context
+ $tokenStorage = $this->getMock('Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface');
+ $tokenStorage
->expects($this->any())
->method('getToken')
->will($this->returnValue($token))
;
- $context
+ $tokenStorage
->expects($this->once())
->method('setToken')
->with($this->equalTo(null))
@@ -231,7 +231,7 @@ class AbstractPreAuthenticatedListenerTest extends \PHPUnit_Framework_TestCase
;
$listener = $this->getMockForAbstractClass('Symfony\Component\Security\Http\Firewall\AbstractPreAuthenticatedListener', array(
- $context,
+ $tokenStorage,
$authenticationManager,
'TheProviderKey',
));
diff --git a/Http/Tests/Firewall/AccessListenerTest.php b/Http/Tests/Firewall/AccessListenerTest.php
index f9b0f3c..af9d565 100644
--- a/Http/Tests/Firewall/AccessListenerTest.php
+++ b/Http/Tests/Firewall/AccessListenerTest.php
@@ -37,8 +37,8 @@ class AccessListenerTest extends \PHPUnit_Framework_TestCase
->will($this->returnValue(true))
;
- $context = $this->getMock('Symfony\Component\Security\Core\SecurityContextInterface');
- $context
+ $tokenStorage = $this->getMock('Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface');
+ $tokenStorage
->expects($this->any())
->method('getToken')
->will($this->returnValue($token))
@@ -53,7 +53,7 @@ class AccessListenerTest extends \PHPUnit_Framework_TestCase
;
$listener = new AccessListener(
- $context,
+ $tokenStorage,
$accessDecisionManager,
$accessMap,
$this->getMock('Symfony\Component\Security\Core\Authentication\AuthenticationManagerInterface')
@@ -103,13 +103,13 @@ class AccessListenerTest extends \PHPUnit_Framework_TestCase
->will($this->returnValue($authenticatedToken))
;
- $context = $this->getMock('Symfony\Component\Security\Core\SecurityContextInterface');
- $context
+ $tokenStorage = $this->getMock('Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface');
+ $tokenStorage
->expects($this->any())
->method('getToken')
->will($this->returnValue($notAuthenticatedToken))
;
- $context
+ $tokenStorage
->expects($this->once())
->method('setToken')
->with($this->equalTo($authenticatedToken))
@@ -124,7 +124,7 @@ class AccessListenerTest extends \PHPUnit_Framework_TestCase
;
$listener = new AccessListener(
- $context,
+ $tokenStorage,
$accessDecisionManager,
$accessMap,
$authManager
@@ -158,15 +158,15 @@ class AccessListenerTest extends \PHPUnit_Framework_TestCase
->method('isAuthenticated')
;
- $context = $this->getMock('Symfony\Component\Security\Core\SecurityContextInterface');
- $context
+ $tokenStorage = $this->getMock('Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface');
+ $tokenStorage
->expects($this->any())
->method('getToken')
->will($this->returnValue($token))
;
$listener = new AccessListener(
- $context,
+ $tokenStorage,
$this->getMock('Symfony\Component\Security\Core\Authorization\AccessDecisionManagerInterface'),
$accessMap,
$this->getMock('Symfony\Component\Security\Core\Authentication\AuthenticationManagerInterface')
@@ -185,17 +185,17 @@ class AccessListenerTest extends \PHPUnit_Framework_TestCase
/**
* @expectedException \Symfony\Component\Security\Core\Exception\AuthenticationCredentialsNotFoundException
*/
- public function testHandleWhenTheSecurityContextHasNoToken()
+ public function testHandleWhenTheSecurityTokenStorageHasNoToken()
{
- $context = $this->getMock('Symfony\Component\Security\Core\SecurityContextInterface');
- $context
+ $tokenStorage = $this->getMock('Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface');
+ $tokenStorage
->expects($this->any())
->method('getToken')
->will($this->returnValue(null))
;
$listener = new AccessListener(
- $context,
+ $tokenStorage,
$this->getMock('Symfony\Component\Security\Core\Authorization\AccessDecisionManagerInterface'),
$this->getMock('Symfony\Component\Security\Http\AccessMapInterface'),
$this->getMock('Symfony\Component\Security\Core\Authentication\AuthenticationManagerInterface')
diff --git a/Http/Tests/Firewall/AnonymousAuthenticationListenerTest.php b/Http/Tests/Firewall/AnonymousAuthenticationListenerTest.php
index 9af4791..3450c1e 100644
--- a/Http/Tests/Firewall/AnonymousAuthenticationListenerTest.php
+++ b/Http/Tests/Firewall/AnonymousAuthenticationListenerTest.php
@@ -16,15 +16,15 @@ use Symfony\Component\Security\Http\Firewall\AnonymousAuthenticationListener;
class AnonymousAuthenticationListenerTest extends \PHPUnit_Framework_TestCase
{
- public function testHandleWithContextHavingAToken()
+ public function testHandleWithTokenStorageHavingAToken()
{
- $context = $this->getMock('Symfony\Component\Security\Core\SecurityContextInterface');
- $context
+ $tokenStorage = $this->getMock('Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface');
+ $tokenStorage
->expects($this->any())
->method('getToken')
->will($this->returnValue($this->getMock('Symfony\Component\Security\Core\Authentication\Token\TokenInterface')))
;
- $context
+ $tokenStorage
->expects($this->never())
->method('setToken')
;
@@ -35,14 +35,14 @@ class AnonymousAuthenticationListenerTest extends \PHPUnit_Framework_TestCase
->method('authenticate')
;
- $listener = new AnonymousAuthenticationListener($context, 'TheKey', null, $authenticationManager);
+ $listener = new AnonymousAuthenticationListener($tokenStorage, 'TheKey', null, $authenticationManager);
$listener->handle($this->getMock('Symfony\Component\HttpKernel\Event\GetResponseEvent', array(), array(), '', false));
}
- public function testHandleWithContextHavingNoToken()
+ public function testHandleWithTokenStorageHavingNoToken()
{
- $context = $this->getMock('Symfony\Component\Security\Core\SecurityContextInterface');
- $context
+ $tokenStorage = $this->getMock('Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface');
+ $tokenStorage
->expects($this->any())
->method('getToken')
->will($this->returnValue(null))
@@ -60,28 +60,28 @@ class AnonymousAuthenticationListenerTest extends \PHPUnit_Framework_TestCase
->will($this->returnValue($anonymousToken))
;
- $context
+ $tokenStorage
->expects($this->once())
->method('setToken')
->with($anonymousToken)
;
- $listener = new AnonymousAuthenticationListener($context, 'TheKey', null, $authenticationManager);
+ $listener = new AnonymousAuthenticationListener($tokenStorage, 'TheKey', null, $authenticationManager);
$listener->handle($this->getMock('Symfony\Component\HttpKernel\Event\GetResponseEvent', array(), array(), '', false));
}
public function testHandledEventIsLogged()
{
- $context = $this->getMock('Symfony\Component\Security\Core\SecurityContextInterface');
+ $tokenStorage = $this->getMock('Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface');
$logger = $this->getMock('Psr\Log\LoggerInterface');
$logger->expects($this->once())
->method('info')
- ->with('Populated SecurityContext with an anonymous Token')
+ ->with('Populated the TokenStorage with an anonymous Token.')
;
$authenticationManager = $this->getMock('Symfony\Component\Security\Core\Authentication\AuthenticationManagerInterface');
- $listener = new AnonymousAuthenticationListener($context, 'TheKey', $logger, $authenticationManager);
+ $listener = new AnonymousAuthenticationListener($tokenStorage, 'TheKey', $logger, $authenticationManager);
$listener->handle($this->getMock('Symfony\Component\HttpKernel\Event\GetResponseEvent', array(), array(), '', false));
}
}
diff --git a/Http/Tests/Firewall/BasicAuthenticationListenerTest.php b/Http/Tests/Firewall/BasicAuthenticationListenerTest.php
index 0ef993f..8901cb2 100644
--- a/Http/Tests/Firewall/BasicAuthenticationListenerTest.php
+++ b/Http/Tests/Firewall/BasicAuthenticationListenerTest.php
@@ -29,13 +29,13 @@ class BasicAuthenticationListenerTest extends \PHPUnit_Framework_TestCase
$token = $this->getMock('Symfony\Component\Security\Core\Authentication\Token\TokenInterface');
- $context = $this->getMock('Symfony\Component\Security\Core\SecurityContextInterface');
- $context
+ $tokenStorage = $this->getMock('Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface');
+ $tokenStorage
->expects($this->any())
->method('getToken')
->will($this->returnValue(null))
;
- $context
+ $tokenStorage
->expects($this->once())
->method('setToken')
->with($this->equalTo($token))
@@ -50,7 +50,7 @@ class BasicAuthenticationListenerTest extends \PHPUnit_Framework_TestCase
;
$listener = new BasicAuthenticationListener(
- $context,
+ $tokenStorage,
$authenticationManager,
'TheProviderKey',
$this->getMock('Symfony\Component\Security\Http\EntryPoint\AuthenticationEntryPointInterface')
@@ -75,13 +75,13 @@ class BasicAuthenticationListenerTest extends \PHPUnit_Framework_TestCase
$token = $this->getMock('Symfony\Component\Security\Core\Authentication\Token\TokenInterface');
- $context = $this->getMock('Symfony\Component\Security\Core\SecurityContextInterface');
- $context
+ $tokenStorage = $this->getMock('Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface');
+ $tokenStorage
->expects($this->any())
->method('getToken')
->will($this->returnValue(null))
;
- $context
+ $tokenStorage
->expects($this->never())
->method('setToken')
;
@@ -97,7 +97,7 @@ class BasicAuthenticationListenerTest extends \PHPUnit_Framework_TestCase
;
$listener = new BasicAuthenticationListener(
- $context,
+ $tokenStorage,
new AuthenticationProviderManager(array($this->getMock('Symfony\Component\Security\Core\Authentication\Provider\AuthenticationProviderInterface'))),
'TheProviderKey',
$authenticationEntryPoint
@@ -122,14 +122,14 @@ class BasicAuthenticationListenerTest extends \PHPUnit_Framework_TestCase
{
$request = new Request();
- $context = $this->getMock('Symfony\Component\Security\Core\SecurityContextInterface');
- $context
+ $tokenStorage = $this->getMock('Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface');
+ $tokenStorage
->expects($this->never())
->method('getToken')
;
$listener = new BasicAuthenticationListener(
- $context,
+ $tokenStorage,
$this->getMock('Symfony\Component\Security\Core\Authentication\AuthenticationManagerInterface'),
'TheProviderKey',
$this->getMock('Symfony\Component\Security\Http\EntryPoint\AuthenticationEntryPointInterface')
@@ -151,8 +151,8 @@ class BasicAuthenticationListenerTest extends \PHPUnit_Framework_TestCase
$token = new UsernamePasswordToken('TheUsername', 'ThePassword', 'TheProviderKey', array('ROLE_FOO'));
- $context = $this->getMock('Symfony\Component\Security\Core\SecurityContextInterface');
- $context
+ $tokenStorage = $this->getMock('Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface');
+ $tokenStorage
->expects($this->any())
->method('getToken')
->will($this->returnValue($token))
@@ -165,7 +165,7 @@ class BasicAuthenticationListenerTest extends \PHPUnit_Framework_TestCase
;
$listener = new BasicAuthenticationListener(
- $context,
+ $tokenStorage,
$authenticationManager,
'TheProviderKey',
$this->getMock('Symfony\Component\Security\Http\EntryPoint\AuthenticationEntryPointInterface')
@@ -188,7 +188,7 @@ class BasicAuthenticationListenerTest extends \PHPUnit_Framework_TestCase
public function testItRequiresProviderKey()
{
new BasicAuthenticationListener(
- $this->getMock('Symfony\Component\Security\Core\SecurityContextInterface'),
+ $this->getMock('Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface'),
$this->getMock('Symfony\Component\Security\Core\Authentication\AuthenticationManagerInterface'),
'',
$this->getMock('Symfony\Component\Security\Http\EntryPoint\AuthenticationEntryPointInterface')
@@ -204,13 +204,13 @@ class BasicAuthenticationListenerTest extends \PHPUnit_Framework_TestCase
$token = new PreAuthenticatedToken('TheUser', 'TheCredentials', 'TheProviderKey', array('ROLE_FOO'));
- $context = $this->getMock('Symfony\Component\Security\Core\SecurityContextInterface');
- $context
+ $tokenStorage = $this->getMock('Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface');
+ $tokenStorage
->expects($this->any())
->method('getToken')
->will($this->returnValue($token))
;
- $context
+ $tokenStorage
->expects($this->never())
->method('setToken')
;
@@ -226,7 +226,7 @@ class BasicAuthenticationListenerTest extends \PHPUnit_Framework_TestCase
;
$listener = new BasicAuthenticationListener(
- $context,
+ $tokenStorage,
new AuthenticationProviderManager(array($this->getMock('Symfony\Component\Security\Core\Authentication\Provider\AuthenticationProviderInterface'))),
'TheProviderKey',
$authenticationEntryPoint
diff --git a/Http/Tests/Firewall/ContextListenerTest.php b/Http/Tests/Firewall/ContextListenerTest.php
index 00ec418..ae1199a 100644
--- a/Http/Tests/Firewall/ContextListenerTest.php
+++ b/Http/Tests/Firewall/ContextListenerTest.php
@@ -20,25 +20,11 @@ use Symfony\Component\HttpKernel\HttpKernelInterface;
use Symfony\Component\HttpKernel\KernelEvents;
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorage;
use Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken;
-use Symfony\Component\Security\Core\SecurityContext;
use Symfony\Component\Security\Http\Firewall\ContextListener;
use Symfony\Component\EventDispatcher\EventDispatcher;
class ContextListenerTest extends \PHPUnit_Framework_TestCase
{
- protected function setUp()
- {
- $this->securityContext = new SecurityContext(
- new TokenStorage(),
- $this->getMock('Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface')
- );
- }
-
- protected function tearDown()
- {
- unset($this->securityContext);
- }
-
/**
* @expectedException \InvalidArgumentException
* @expectedExceptionMessage $contextKey must not be empty
@@ -46,7 +32,7 @@ class ContextListenerTest extends \PHPUnit_Framework_TestCase
public function testItRequiresContextKey()
{
new ContextListener(
- $this->getMock('Symfony\Component\Security\Core\SecurityContextInterface'),
+ $this->getMock('Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface'),
array(),
''
);
@@ -59,7 +45,7 @@ class ContextListenerTest extends \PHPUnit_Framework_TestCase
public function testUserProvidersNeedToImplementAnInterface()
{
new ContextListener(
- $this->getMock('Symfony\Component\Security\Core\SecurityContextInterface'),
+ $this->getMock('Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface'),
array(new \stdClass()),
'key123'
);
@@ -101,7 +87,8 @@ class ContextListenerTest extends \PHPUnit_Framework_TestCase
public function testOnKernelResponseWithoutSession()
{
- $this->securityContext->setToken(new UsernamePasswordToken('test1', 'pass1', 'phpunit'));
+ $tokenStorage = new TokenStorage();
+ $tokenStorage->setToken(new UsernamePasswordToken('test1', 'pass1', 'phpunit'));
$request = new Request();
$session = new Session(new MockArraySessionStorage());
$request->setSession($session);
@@ -113,7 +100,7 @@ class ContextListenerTest extends \PHPUnit_Framework_TestCase
new Response()
);
- $listener = new ContextListener($this->securityContext, array(), 'session', null, new EventDispatcher());
+ $listener = new ContextListener($tokenStorage, array(), 'session', null, new EventDispatcher());
$listener->onKernelResponse($event);
$this->assertTrue($session->isStarted());
@@ -132,7 +119,7 @@ class ContextListenerTest extends \PHPUnit_Framework_TestCase
new Response()
);
- $listener = new ContextListener($this->securityContext, array(), 'session', null, new EventDispatcher());
+ $listener = new ContextListener(new TokenStorage(), array(), 'session', null, new EventDispatcher());
$listener->onKernelResponse($event);
$this->assertFalse($session->isStarted());
@@ -143,7 +130,7 @@ class ContextListenerTest extends \PHPUnit_Framework_TestCase
*/
public function testInvalidTokenInSession($token)
{
- $context = $this->getMock('Symfony\Component\Security\Core\SecurityContextInterface');
+ $tokenStorage = $this->getMock('Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface');
$event = $this->getMockBuilder('Symfony\Component\HttpKernel\Event\GetResponseEvent')
->disableOriginalConstructor()
->getMock();
@@ -163,11 +150,11 @@ class ContextListenerTest extends \PHPUnit_Framework_TestCase
->method('get')
->with('_security_key123')
->will($this->returnValue($token));
- $context->expects($this->once())
+ $tokenStorage->expects($this->once())
->method('setToken')
->with(null);
- $listener = new ContextListener($context, array(), 'key123');
+ $listener = new ContextListener($tokenStorage, array(), 'key123');
$listener->handle($event);
}
@@ -182,13 +169,13 @@ class ContextListenerTest extends \PHPUnit_Framework_TestCase
public function testHandleAddsKernelResponseListener()
{
- $context = $this->getMock('Symfony\Component\Security\Core\SecurityContextInterface');
+ $tokenStorage = $this->getMock('Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface');
$dispatcher = $this->getMock('Symfony\Component\EventDispatcher\EventDispatcherInterface');
$event = $this->getMockBuilder('Symfony\Component\HttpKernel\Event\GetResponseEvent')
->disableOriginalConstructor()
->getMock();
- $listener = new ContextListener($context, array(), 'key123', null, $dispatcher);
+ $listener = new ContextListener($tokenStorage, array(), 'key123', null, $dispatcher);
$event->expects($this->any())
->method('isMasterRequest')
@@ -206,13 +193,13 @@ class ContextListenerTest extends \PHPUnit_Framework_TestCase
public function testOnKernelResponseListenerRemovesItself()
{
- $context = $this->getMock('Symfony\Component\Security\Core\SecurityContextInterface');
+ $tokenStorage = $this->getMock('Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface');
$dispatcher = $this->getMock('Symfony\Component\EventDispatcher\EventDispatcherInterface');
$event = $this->getMockBuilder('Symfony\Component\HttpKernel\Event\FilterResponseEvent')
->disableOriginalConstructor()
->getMock();
- $listener = new ContextListener($context, array(), 'key123', null, $dispatcher);
+ $listener = new ContextListener($tokenStorage, array(), 'key123', null, $dispatcher);
$request = $this->getMock('Symfony\Component\HttpFoundation\Request');
$request->expects($this->any())
@@ -243,10 +230,10 @@ class ContextListenerTest extends \PHPUnit_Framework_TestCase
->getMock();
$event->expects($this->any())->method('getRequest')->will($this->returnValue($request));
- $context = $this->getMock('Symfony\Component\Security\Core\SecurityContextInterface');
- $context->expects($this->once())->method('setToken')->with(null);
+ $tokenStorage = $this->getMock('Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface');
+ $tokenStorage->expects($this->once())->method('setToken')->with(null);
- $listener = new ContextListener($context, array(), 'key123');
+ $listener = new ContextListener($tokenStorage, array(), 'key123');
$listener->handle($event);
}
@@ -258,7 +245,8 @@ class ContextListenerTest extends \PHPUnit_Framework_TestCase
$session->set('_security_session', $original);
}
- $this->securityContext->setToken($newToken);
+ $tokenStorage = new TokenStorage();
+ $tokenStorage->setToken($newToken);
$request = new Request();
$request->setSession($session);
@@ -271,7 +259,7 @@ class ContextListenerTest extends \PHPUnit_Framework_TestCase
new Response()
);
- $listener = new ContextListener($this->securityContext, array(), 'session', null, new EventDispatcher());
+ $listener = new ContextListener($tokenStorage, array(), 'session', null, new EventDispatcher());
$listener->onKernelResponse($event);
return $session;
diff --git a/Http/Tests/Firewall/ExceptionListenerTest.php b/Http/Tests/Firewall/ExceptionListenerTest.php
index 6b99471..3d409e5 100644
--- a/Http/Tests/Firewall/ExceptionListenerTest.php
+++ b/Http/Tests/Firewall/ExceptionListenerTest.php
@@ -16,9 +16,9 @@ use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent;
use Symfony\Component\HttpKernel\HttpKernelInterface;
use Symfony\Component\Security\Core\Authentication\AuthenticationTrustResolverInterface;
+use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
use Symfony\Component\Security\Core\Exception\AccessDeniedException;
use Symfony\Component\Security\Core\Exception\AuthenticationException;
-use Symfony\Component\Security\Core\SecurityContextInterface;
use Symfony\Component\Security\Http\Authorization\AccessDeniedHandlerInterface;
use Symfony\Component\Security\Http\EntryPoint\AuthenticationEntryPointInterface;
use Symfony\Component\Security\Http\Firewall\ExceptionListener;
@@ -123,10 +123,10 @@ class ExceptionListenerTest extends \PHPUnit_Framework_TestCase
{
$event = $this->createEvent($exception);
- $context = $this->getMock('Symfony\Component\Security\Core\SecurityContextInterface');
- $context->expects($this->once())->method('getToken')->will($this->returnValue($this->getMock('Symfony\Component\Security\Core\Authentication\Token\TokenInterface')));
+ $tokenStorage = $this->getMock('Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface');
+ $tokenStorage->expects($this->once())->method('getToken')->will($this->returnValue($this->getMock('Symfony\Component\Security\Core\Authentication\Token\TokenInterface')));
- $listener = $this->createExceptionListener($context, $this->createTrustResolver(false), null, $this->createEntryPoint());
+ $listener = $this->createExceptionListener($tokenStorage, $this->createTrustResolver(false), null, $this->createEntryPoint());
$listener->onKernelException($event);
$this->assertEquals('OK', $event->getResponse()->getContent());
@@ -169,10 +169,10 @@ class ExceptionListenerTest extends \PHPUnit_Framework_TestCase
return new GetResponseForExceptionEvent($kernel, Request::create('/'), HttpKernelInterface::MASTER_REQUEST, $exception);
}
- private function createExceptionListener(SecurityContextInterface $context = null, AuthenticationTrustResolverInterface $trustResolver = null, HttpUtils $httpUtils = null, AuthenticationEntryPointInterface $authenticationEntryPoint = null, $errorPage = null, AccessDeniedHandlerInterface $accessDeniedHandler = null)
+ private function createExceptionListener(TokenStorageInterface $tokenStorage = null, AuthenticationTrustResolverInterface $trustResolver = null, HttpUtils $httpUtils = null, AuthenticationEntryPointInterface $authenticationEntryPoint = null, $errorPage = null, AccessDeniedHandlerInterface $accessDeniedHandler = null)
{
return new ExceptionListener(
- $context ?: $this->getMock('Symfony\Component\Security\Core\SecurityContextInterface'),
+ $tokenStorage ?: $this->getMock('Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface'),
$trustResolver ?: $this->getMock('Symfony\Component\Security\Core\Authentication\AuthenticationTrustResolverInterface'),
$httpUtils ?: $this->getMock('Symfony\Component\Security\Http\HttpUtils'),
'key',
diff --git a/Http/Tests/Firewall/LogoutListenerTest.php b/Http/Tests/Firewall/LogoutListenerTest.php
index 041febc..15c996e 100644
--- a/Http/Tests/Firewall/LogoutListenerTest.php
+++ b/Http/Tests/Firewall/LogoutListenerTest.php
@@ -19,7 +19,7 @@ class LogoutListenerTest extends \PHPUnit_Framework_TestCase
{
public function testHandleUnmatchedPath()
{
- list($listener, $context, $httpUtils, $options) = $this->getListener();
+ list($listener, $tokenStorage, $httpUtils, $options) = $this->getListener();
list($event, $request) = $this->getGetResponseEvent();
@@ -39,7 +39,7 @@ class LogoutListenerTest extends \PHPUnit_Framework_TestCase
$successHandler = $this->getSuccessHandler();
$tokenManager = $this->getTokenManager();
- list($listener, $context, $httpUtils, $options) = $this->getListener($successHandler, $tokenManager);
+ list($listener, $tokenStorage, $httpUtils, $options) = $this->getListener($successHandler, $tokenManager);
list($event, $request) = $this->getGetResponseEvent();
@@ -59,7 +59,7 @@ class LogoutListenerTest extends \PHPUnit_Framework_TestCase
->with($request)
->will($this->returnValue($response = new Response()));
- $context->expects($this->once())
+ $tokenStorage->expects($this->once())
->method('getToken')
->will($this->returnValue($token = $this->getToken()));
@@ -68,7 +68,7 @@ class LogoutListenerTest extends \PHPUnit_Framework_TestCase
->method('logout')
->with($request, $response, $token);
- $context->expects($this->once())
+ $tokenStorage->expects($this->once())
->method('setToken')
->with(null);
@@ -85,7 +85,7 @@ class LogoutListenerTest extends \PHPUnit_Framework_TestCase
{
$successHandler = $this->getSuccessHandler();
- list($listener, $context, $httpUtils, $options) = $this->getListener($successHandler);
+ list($listener, $tokenStorage, $httpUtils, $options) = $this->getListener($successHandler);
list($event, $request) = $this->getGetResponseEvent();
@@ -99,7 +99,7 @@ class LogoutListenerTest extends \PHPUnit_Framework_TestCase
->with($request)
->will($this->returnValue($response = new Response()));
- $context->expects($this->once())
+ $tokenStorage->expects($this->once())
->method('getToken')
->will($this->returnValue($token = $this->getToken()));
@@ -108,7 +108,7 @@ class LogoutListenerTest extends \PHPUnit_Framework_TestCase
->method('logout')
->with($request, $response, $token);
- $context->expects($this->once())
+ $tokenStorage->expects($this->once())
->method('setToken')
->with(null);
@@ -128,7 +128,7 @@ class LogoutListenerTest extends \PHPUnit_Framework_TestCase
{
$successHandler = $this->getSuccessHandler();
- list($listener, $context, $httpUtils, $options) = $this->getListener($successHandler);
+ list($listener, $tokenStorage, $httpUtils, $options) = $this->getListener($successHandler);
list($event, $request) = $this->getGetResponseEvent();
@@ -152,7 +152,7 @@ class LogoutListenerTest extends \PHPUnit_Framework_TestCase
{
$tokenManager = $this->getTokenManager();
- list($listener, $context, $httpUtils, $options) = $this->getListener(null, $tokenManager);
+ list($listener, $tokenStorage, $httpUtils, $options) = $this->getListener(null, $tokenManager);
list($event, $request) = $this->getGetResponseEvent();
@@ -175,11 +175,9 @@ class LogoutListenerTest extends \PHPUnit_Framework_TestCase
return $this->getMock('Symfony\Component\Security\Csrf\CsrfTokenManagerInterface');
}
- private function getContext()
+ private function getTokenStorage()
{
- return $this->getMockBuilder('Symfony\Component\Security\Core\SecurityContext')
- ->disableOriginalConstructor()
- ->getMock();
+ return $this->getMock('Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface');
}
private function getGetResponseEvent()
@@ -210,7 +208,7 @@ class LogoutListenerTest extends \PHPUnit_Framework_TestCase
private function getListener($successHandler = null, $tokenManager = null)
{
$listener = new LogoutListener(
- $context = $this->getContext(),
+ $tokenStorage = $this->getTokenStorage(),
$httpUtils = $this->getHttpUtils(),
$successHandler ?: $this->getSuccessHandler(),
$options = array(
@@ -222,7 +220,7 @@ class LogoutListenerTest extends \PHPUnit_Framework_TestCase
$tokenManager
);
- return array($listener, $context, $httpUtils, $options);
+ return array($listener, $tokenStorage, $httpUtils, $options);
}
private function getSuccessHandler()
diff --git a/Http/Tests/Firewall/RememberMeListenerTest.php b/Http/Tests/Firewall/RememberMeListenerTest.php
index 3f43fb2..e348355 100644
--- a/Http/Tests/Firewall/RememberMeListenerTest.php
+++ b/Http/Tests/Firewall/RememberMeListenerTest.php
@@ -18,17 +18,17 @@ use Symfony\Component\Security\Http\SecurityEvents;
class RememberMeListenerTest extends \PHPUnit_Framework_TestCase
{
- public function testOnCoreSecurityDoesNotTryToPopulateNonEmptySecurityContext()
+ public function testOnCoreSecurityDoesNotTryToPopulateNonEmptyTokenStorage()
{
- list($listener, $context) = $this->getListener();
+ list($listener, $tokenStorage) = $this->getListener();
- $context
+ $tokenStorage
->expects($this->once())
->method('getToken')
->will($this->returnValue($this->getMock('Symfony\Component\Security\Core\Authentication\Token\TokenInterface')))
;
- $context
+ $tokenStorage
->expects($this->never())
->method('setToken')
;
@@ -38,9 +38,9 @@ class RememberMeListenerTest extends \PHPUnit_Framework_TestCase
public function testOnCoreSecurityDoesNothingWhenNoCookieIsSet()
{
- list($listener, $context, $service) = $this->getListener();
+ list($listener, $tokenStorage, $service) = $this->getListener();
- $context
+ $tokenStorage
->expects($this->once())
->method('getToken')
->will($this->returnValue(null))
@@ -64,9 +64,9 @@ class RememberMeListenerTest extends \PHPUnit_Framework_TestCase
public function testOnCoreSecurityIgnoresAuthenticationExceptionThrownByAuthenticationManagerImplementation()
{
- list($listener, $context, $service, $manager) = $this->getListener();
+ list($listener, $tokenStorage, $service, $manager) = $this->getListener();
- $context
+ $tokenStorage
->expects($this->once())
->method('getToken')
->will($this->returnValue(null))
@@ -106,9 +106,9 @@ class RememberMeListenerTest extends \PHPUnit_Framework_TestCase
*/
public function testOnCoreSecurityIgnoresAuthenticationOptionallyRethrowsExceptionThrownAuthenticationManagerImplementation()
{
- list($listener, $context, $service, $manager) = $this->getListener(false, false);
+ list($listener, $tokenStorage, $service, $manager) = $this->getListener(false, false);
- $context
+ $tokenStorage
->expects($this->once())
->method('getToken')
->will($this->returnValue(null))
@@ -144,9 +144,9 @@ class RememberMeListenerTest extends \PHPUnit_Framework_TestCase
public function testOnCoreSecurity()
{
- list($listener, $context, $service, $manager) = $this->getListener();
+ list($listener, $tokenStorage, $service, $manager) = $this->getListener();
- $context
+ $tokenStorage
->expects($this->once())
->method('getToken')
->will($this->returnValue(null))
@@ -159,7 +159,7 @@ class RememberMeListenerTest extends \PHPUnit_Framework_TestCase
->will($this->returnValue($token))
;
- $context
+ $tokenStorage
->expects($this->once())
->method('setToken')
->with($this->equalTo($token))
@@ -183,9 +183,9 @@ class RememberMeListenerTest extends \PHPUnit_Framework_TestCase
public function testOnCoreSecurityInteractiveLoginEventIsDispatchedIfDispatcherIsPresent()
{
- list($listener, $context, $service, $manager, , $dispatcher) = $this->getListener(true);
+ list($listener, $tokenStorage, $service, $manager, , $dispatcher) = $this->getListener(true);
- $context
+ $tokenStorage
->expects($this->once())
->method('getToken')
->will($this->returnValue(null))
@@ -198,7 +198,7 @@ class RememberMeListenerTest extends \PHPUnit_Framework_TestCase
->will($this->returnValue($token))
;
- $context
+ $tokenStorage
->expects($this->once())
->method('setToken')
->with($this->equalTo($token))
@@ -243,7 +243,7 @@ class RememberMeListenerTest extends \PHPUnit_Framework_TestCase
protected function getListener($withDispatcher = false, $catchExceptions = true)
{
$listener = new RememberMeListener(
- $context = $this->getContext(),
+ $tokenStorage = $this->getTokenStorage(),
$service = $this->getService(),
$manager = $this->getManager(),
$logger = $this->getLogger(),
@@ -251,7 +251,7 @@ class RememberMeListenerTest extends \PHPUnit_Framework_TestCase
$catchExceptions
);
- return array($listener, $context, $service, $manager, $logger, $dispatcher);
+ return array($listener, $tokenStorage, $service, $manager, $logger, $dispatcher);
}
protected function getLogger()
@@ -269,9 +269,9 @@ class RememberMeListenerTest extends \PHPUnit_Framework_TestCase
return $this->getMock('Symfony\Component\Security\Http\RememberMe\RememberMeServicesInterface');
}
- protected function getContext()
+ protected function getTokenStorage()
{
- return $this->getMock('Symfony\Component\Security\Core\SecurityContextInterface');
+ return $this->getMock('Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface');
}
protected function getDispatcher()
diff --git a/Http/Tests/Firewall/RemoteUserAuthenticationListenerTest.php b/Http/Tests/Firewall/RemoteUserAuthenticationListenerTest.php
index 6e6b979..dad7aad 100644
--- a/Http/Tests/Firewall/RemoteUserAuthenticationListenerTest.php
+++ b/Http/Tests/Firewall/RemoteUserAuthenticationListenerTest.php
@@ -24,12 +24,12 @@ class RemoteUserAuthenticationListenerTest extends \PHPUnit_Framework_TestCase
$request = new Request(array(), array(), array(), array(), array(), $serverVars);
- $context = $this->getMock('Symfony\Component\Security\Core\SecurityContextInterface');
+ $tokenStorage = $this->getMock('Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface');
$authenticationManager = $this->getMock('Symfony\Component\Security\Core\Authentication\AuthenticationManagerInterface');
$listener = new RemoteUserAuthenticationListener(
- $context,
+ $tokenStorage,
$authenticationManager,
'TheProviderKey'
);
@@ -48,12 +48,12 @@ class RemoteUserAuthenticationListenerTest extends \PHPUnit_Framework_TestCase
{
$request = new Request(array(), array(), array(), array(), array(), array());
- $context = $this->getMock('Symfony\Component\Security\Core\SecurityContextInterface');
+ $tokenStorage = $this->getMock('Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface');
$authenticationManager = $this->getMock('Symfony\Component\Security\Core\Authentication\AuthenticationManagerInterface');
$listener = new RemoteUserAuthenticationListener(
- $context,
+ $tokenStorage,
$authenticationManager,
'TheProviderKey'
);
@@ -71,12 +71,12 @@ class RemoteUserAuthenticationListenerTest extends \PHPUnit_Framework_TestCase
$request = new Request(array(), array(), array(), array(), array(), array(
'TheUserKey' => 'TheUser',
));
- $context = $this->getMock('Symfony\Component\Security\Core\SecurityContextInterface');
+ $tokenStorage = $this->getMock('Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface');
$authenticationManager = $this->getMock('Symfony\Component\Security\Core\Authentication\AuthenticationManagerInterface');
$listener = new RemoteUserAuthenticationListener(
- $context,
+ $tokenStorage,
$authenticationManager,
'TheProviderKey',
'TheUserKey'
diff --git a/Http/Tests/Firewall/SimplePreAuthenticationListenerTest.php b/Http/Tests/Firewall/SimplePreAuthenticationListenerTest.php
new file mode 100644
index 0000000..0a1286c
--- /dev/null
+++ b/Http/Tests/Firewall/SimplePreAuthenticationListenerTest.php
@@ -0,0 +1,128 @@
+<?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\Http\Tests\Firewall;
+
+use Symfony\Component\HttpFoundation\Request;
+use Symfony\Component\Security\Core\Exception\AuthenticationException;
+use Symfony\Component\Security\Http\Event\InteractiveLoginEvent;
+use Symfony\Component\Security\Http\Firewall\SimplePreAuthenticationListener;
+use Symfony\Component\Security\Http\SecurityEvents;
+
+class SimplePreAuthenticationListenerTest extends \PHPUnit_Framework_TestCase
+{
+ private $authenticationManager;
+ private $dispatcher;
+ private $event;
+ private $logger;
+ private $request;
+ private $tokenStorage;
+ private $token;
+
+ public function testHandle()
+ {
+ $this->tokenStorage
+ ->expects($this->once())
+ ->method('setToken')
+ ->with($this->equalTo($this->token))
+ ;
+
+ $this->authenticationManager
+ ->expects($this->once())
+ ->method('authenticate')
+ ->with($this->equalTo($this->token))
+ ->will($this->returnValue($this->token))
+ ;
+
+ $simpleAuthenticator = $this->getMock('Symfony\Component\Security\Core\Authentication\SimplePreAuthenticatorInterface');
+ $simpleAuthenticator
+ ->expects($this->once())
+ ->method('createToken')
+ ->with($this->equalTo($this->request), $this->equalTo('secured_area'))
+ ->will($this->returnValue($this->token))
+ ;
+
+ $loginEvent = new InteractiveLoginEvent($this->request, $this->token);
+
+ $this->dispatcher
+ ->expects($this->once())
+ ->method('dispatch')
+ ->with($this->equalTo(SecurityEvents::INTERACTIVE_LOGIN), $this->equalTo($loginEvent))
+ ;
+
+ $listener = new SimplePreAuthenticationListener($this->tokenStorage, $this->authenticationManager, 'secured_area', $simpleAuthenticator, $this->logger, $this->dispatcher);
+
+ $listener->handle($this->event);
+ }
+
+ public function testHandlecatchAuthenticationException()
+ {
+ $exception = new AuthenticationException('Authentication failed.');
+
+ $this->authenticationManager
+ ->expects($this->once())
+ ->method('authenticate')
+ ->with($this->equalTo($this->token))
+ ->will($this->throwException($exception))
+ ;
+
+ $this->tokenStorage->expects($this->once())
+ ->method('setToken')
+ ->with($this->equalTo(null))
+ ;
+
+ $simpleAuthenticator = $this->getMock('Symfony\Component\Security\Core\Authentication\SimplePreAuthenticatorInterface');
+ $simpleAuthenticator
+ ->expects($this->once())
+ ->method('createToken')
+ ->with($this->equalTo($this->request), $this->equalTo('secured_area'))
+ ->will($this->returnValue($this->token))
+ ;
+
+ $listener = new SimplePreAuthenticationListener($this->tokenStorage, $this->authenticationManager, 'secured_area', $simpleAuthenticator, $this->logger, $this->dispatcher);
+
+ $listener->handle($this->event);
+ }
+
+ protected function setUp()
+ {
+ $this->authenticationManager = $this->getMockBuilder('Symfony\Component\Security\Core\Authentication\AuthenticationProviderManager')
+ ->disableOriginalConstructor()
+ ->getMock()
+ ;
+
+ $this->dispatcher = $this->getMock('Symfony\Component\EventDispatcher\EventDispatcherInterface');
+
+ $this->request = new Request(array(), array(), array(), array(), array(), array());
+
+ $this->event = $this->getMock('Symfony\Component\HttpKernel\Event\GetResponseEvent', array(), array(), '', false);
+ $this->event
+ ->expects($this->any())
+ ->method('getRequest')
+ ->will($this->returnValue($this->request))
+ ;
+
+ $this->logger = $this->getMock('Psr\Log\LoggerInterface');
+ $this->tokenStorage = $this->getMock('Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface');
+ $this->token = $this->getMock('Symfony\Component\Security\Core\Authentication\Token\TokenInterface');
+ }
+
+ protected function tearDown()
+ {
+ $this->authenticationManager = null;
+ $this->dispatcher = null;
+ $this->event = null;
+ $this->logger = null;
+ $this->request = null;
+ $this->tokenStorage = null;
+ $this->token = null;
+ }
+}
diff --git a/Http/Tests/Firewall/SwitchUserListenerTest.php b/Http/Tests/Firewall/SwitchUserListenerTest.php
index a3c96f2..f43b564 100644
--- a/Http/Tests/Firewall/SwitchUserListenerTest.php
+++ b/Http/Tests/Firewall/SwitchUserListenerTest.php
@@ -17,7 +17,7 @@ use Symfony\Component\Security\Http\SecurityEvents;
class SwitchUserListenerTest extends \PHPUnit_Framework_TestCase
{
- private $securityContext;
+ private $tokenStorage;
private $userProvider;
@@ -31,7 +31,7 @@ class SwitchUserListenerTest extends \PHPUnit_Framework_TestCase
protected function setUp()
{
- $this->securityContext = $this->getMock('Symfony\Component\Security\Core\SecurityContextInterface');
+ $this->tokenStorage = $this->getMock('Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface');
$this->userProvider = $this->getMock('Symfony\Component\Security\Core\User\UserProviderInterface');
$this->userChecker = $this->getMock('Symfony\Component\Security\Core\User\UserCheckerInterface');
$this->accessDecisionManager = $this->getMock('Symfony\Component\Security\Core\Authorization\AccessDecisionManagerInterface');
@@ -47,7 +47,7 @@ class SwitchUserListenerTest extends \PHPUnit_Framework_TestCase
*/
public function testProviderKeyIsRequired()
{
- new SwitchUserListener($this->securityContext, $this->userProvider, $this->userChecker, '', $this->accessDecisionManager);
+ new SwitchUserListener($this->tokenStorage, $this->userProvider, $this->userChecker, '', $this->accessDecisionManager);
}
public function testEventIsIgnoredIfUsernameIsNotPassedWithTheRequest()
@@ -55,9 +55,9 @@ class SwitchUserListenerTest extends \PHPUnit_Framework_TestCase
$this->request->expects($this->any())->method('get')->with('_switch_user')->will($this->returnValue(null));
$this->event->expects($this->never())->method('setResponse');
- $this->securityContext->expects($this->never())->method('setToken');
+ $this->tokenStorage->expects($this->never())->method('setToken');
- $listener = new SwitchUserListener($this->securityContext, $this->userProvider, $this->userChecker, 'provider123', $this->accessDecisionManager);
+ $listener = new SwitchUserListener($this->tokenStorage, $this->userProvider, $this->userChecker, 'provider123', $this->accessDecisionManager);
$listener->handle($this->event);
}
@@ -68,10 +68,10 @@ class SwitchUserListenerTest extends \PHPUnit_Framework_TestCase
{
$token = $this->getToken(array($this->getMock('Symfony\Component\Security\Core\Role\RoleInterface')));
- $this->securityContext->expects($this->any())->method('getToken')->will($this->returnValue($token));
+ $this->tokenStorage->expects($this->any())->method('getToken')->will($this->returnValue($token));
$this->request->expects($this->any())->method('get')->with('_switch_user')->will($this->returnValue('_exit'));
- $listener = new SwitchUserListener($this->securityContext, $this->userProvider, $this->userChecker, 'provider123', $this->accessDecisionManager);
+ $listener = new SwitchUserListener($this->tokenStorage, $this->userProvider, $this->userChecker, 'provider123', $this->accessDecisionManager);
$listener->handle($this->event);
}
@@ -83,7 +83,7 @@ class SwitchUserListenerTest extends \PHPUnit_Framework_TestCase
->getMock();
$role->expects($this->any())->method('getSource')->will($this->returnValue($originalToken));
- $this->securityContext->expects($this->any())
+ $this->tokenStorage->expects($this->any())
->method('getToken')
->will($this->returnValue($this->getToken(array($role))));
@@ -93,12 +93,12 @@ class SwitchUserListenerTest extends \PHPUnit_Framework_TestCase
$this->request->query->expects($this->any())->method('all')->will($this->returnValue(array()));
$this->request->server->expects($this->once())->method('set')->with('QUERY_STRING', '');
- $this->securityContext->expects($this->once())
+ $this->tokenStorage->expects($this->once())
->method('setToken')->with($originalToken);
$this->event->expects($this->once())
->method('setResponse')->with($this->isInstanceOf('Symfony\Component\HttpFoundation\RedirectResponse'));
- $listener = new SwitchUserListener($this->securityContext, $this->userProvider, $this->userChecker, 'provider123', $this->accessDecisionManager);
+ $listener = new SwitchUserListener($this->tokenStorage, $this->userProvider, $this->userChecker, 'provider123', $this->accessDecisionManager);
$listener->handle($this->event);
}
@@ -123,7 +123,7 @@ class SwitchUserListenerTest extends \PHPUnit_Framework_TestCase
->getMock();
$role->expects($this->any())->method('getSource')->willReturn($originalToken);
$this
- ->securityContext
+ ->tokenStorage
->expects($this->any())
->method('getToken')
->willReturn($this->getToken(array($role)));
@@ -154,7 +154,7 @@ class SwitchUserListenerTest extends \PHPUnit_Framework_TestCase
}))
;
- $listener = new SwitchUserListener($this->securityContext, $this->userProvider, $this->userChecker, 'provider123', $this->accessDecisionManager, null, '_switch_user', 'ROLE_ALLOWED_TO_SWITCH', $dispatcher);
+ $listener = new SwitchUserListener($this->tokenStorage, $this->userProvider, $this->userChecker, 'provider123', $this->accessDecisionManager, null, '_switch_user', 'ROLE_ALLOWED_TO_SWITCH', $dispatcher);
$listener->handle($this->event);
}
@@ -165,14 +165,14 @@ class SwitchUserListenerTest extends \PHPUnit_Framework_TestCase
{
$token = $this->getToken(array($this->getMock('Symfony\Component\Security\Core\Role\RoleInterface')));
- $this->securityContext->expects($this->any())->method('getToken')->will($this->returnValue($token));
+ $this->tokenStorage->expects($this->any())->method('getToken')->will($this->returnValue($token));
$this->request->expects($this->any())->method('get')->with('_switch_user')->will($this->returnValue('kuba'));
$this->accessDecisionManager->expects($this->once())
->method('decide')->with($token, array('ROLE_ALLOWED_TO_SWITCH'))
->will($this->returnValue(false));
- $listener = new SwitchUserListener($this->securityContext, $this->userProvider, $this->userChecker, 'provider123', $this->accessDecisionManager);
+ $listener = new SwitchUserListener($this->tokenStorage, $this->userProvider, $this->userChecker, 'provider123', $this->accessDecisionManager);
$listener->handle($this->event);
}
@@ -182,7 +182,7 @@ class SwitchUserListenerTest extends \PHPUnit_Framework_TestCase
$user = $this->getMock('Symfony\Component\Security\Core\User\UserInterface');
$user->expects($this->any())->method('getRoles')->will($this->returnValue(array()));
- $this->securityContext->expects($this->any())->method('getToken')->will($this->returnValue($token));
+ $this->tokenStorage->expects($this->any())->method('getToken')->will($this->returnValue($token));
$this->request->expects($this->any())->method('get')->with('_switch_user')->will($this->returnValue('kuba'));
$this->request->query->expects($this->once())->method('remove', '_switch_user');
$this->request->query->expects($this->any())->method('all')->will($this->returnValue(array()));
@@ -199,10 +199,10 @@ class SwitchUserListenerTest extends \PHPUnit_Framework_TestCase
->will($this->returnValue($user));
$this->userChecker->expects($this->once())
->method('checkPostAuth')->with($user);
- $this->securityContext->expects($this->once())
+ $this->tokenStorage->expects($this->once())
->method('setToken')->with($this->isInstanceOf('Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken'));
- $listener = new SwitchUserListener($this->securityContext, $this->userProvider, $this->userChecker, 'provider123', $this->accessDecisionManager);
+ $listener = new SwitchUserListener($this->tokenStorage, $this->userProvider, $this->userChecker, 'provider123', $this->accessDecisionManager);
$listener->handle($this->event);
}
@@ -212,7 +212,7 @@ class SwitchUserListenerTest extends \PHPUnit_Framework_TestCase
$user = $this->getMock('Symfony\Component\Security\Core\User\UserInterface');
$user->expects($this->any())->method('getRoles')->will($this->returnValue(array()));
- $this->securityContext->expects($this->any())->method('getToken')->will($this->returnValue($token));
+ $this->tokenStorage->expects($this->any())->method('getToken')->will($this->returnValue($token));
$this->request->expects($this->any())->method('get')->with('_switch_user')->will($this->returnValue('kuba'));
$this->request->query->expects($this->once())->method('remove', '_switch_user');
$this->request->query->expects($this->any())->method('all')->will($this->returnValue(array('page' => 3, 'section' => 2)));
@@ -228,10 +228,10 @@ class SwitchUserListenerTest extends \PHPUnit_Framework_TestCase
->will($this->returnValue($user));
$this->userChecker->expects($this->once())
->method('checkPostAuth')->with($user);
- $this->securityContext->expects($this->once())
+ $this->tokenStorage->expects($this->once())
->method('setToken')->with($this->isInstanceOf('Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken'));
- $listener = new SwitchUserListener($this->securityContext, $this->userProvider, $this->userChecker, 'provider123', $this->accessDecisionManager);
+ $listener = new SwitchUserListener($this->tokenStorage, $this->userProvider, $this->userChecker, 'provider123', $this->accessDecisionManager);
$listener->handle($this->event);
}
diff --git a/Http/Tests/Firewall/X509AuthenticationListenerTest.php b/Http/Tests/Firewall/X509AuthenticationListenerTest.php
index 7f2da3e..66690d9 100644
--- a/Http/Tests/Firewall/X509AuthenticationListenerTest.php
+++ b/Http/Tests/Firewall/X509AuthenticationListenerTest.php
@@ -31,11 +31,11 @@ class X509AuthenticationListenerTest extends \PHPUnit_Framework_TestCase
$request = new Request(array(), array(), array(), array(), array(), $serverVars);
- $context = $this->getMock('Symfony\Component\Security\Core\SecurityContextInterface');
+ $tokenStorage = $this->getMock('Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface');
$authenticationManager = $this->getMock('Symfony\Component\Security\Core\Authentication\AuthenticationManagerInterface');
- $listener = new X509AuthenticationListener($context, $authenticationManager, 'TheProviderKey');
+ $listener = new X509AuthenticationListener($tokenStorage, $authenticationManager, 'TheProviderKey');
$method = new \ReflectionMethod($listener, 'getPreAuthenticatedData');
$method->setAccessible(true);
@@ -60,11 +60,11 @@ class X509AuthenticationListenerTest extends \PHPUnit_Framework_TestCase
$credentials = 'CN=Sample certificate DN/emailAddress='.$emailAddress;
$request = new Request(array(), array(), array(), array(), array(), array('SSL_CLIENT_S_DN' => $credentials));
- $context = $this->getMock('Symfony\Component\Security\Core\SecurityContextInterface');
+ $tokenStorage = $this->getMock('Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface');
$authenticationManager = $this->getMock('Symfony\Component\Security\Core\Authentication\AuthenticationManagerInterface');
- $listener = new X509AuthenticationListener($context, $authenticationManager, 'TheProviderKey');
+ $listener = new X509AuthenticationListener($tokenStorage, $authenticationManager, 'TheProviderKey');
$method = new \ReflectionMethod($listener, 'getPreAuthenticatedData');
$method->setAccessible(true);
@@ -88,11 +88,11 @@ class X509AuthenticationListenerTest extends \PHPUnit_Framework_TestCase
{
$request = new Request(array(), array(), array(), array(), array(), array());
- $context = $this->getMock('Symfony\Component\Security\Core\SecurityContextInterface');
+ $tokenStorage = $this->getMock('Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface');
$authenticationManager = $this->getMock('Symfony\Component\Security\Core\Authentication\AuthenticationManagerInterface');
- $listener = new X509AuthenticationListener($context, $authenticationManager, 'TheProviderKey');
+ $listener = new X509AuthenticationListener($tokenStorage, $authenticationManager, 'TheProviderKey');
$method = new \ReflectionMethod($listener, 'getPreAuthenticatedData');
$method->setAccessible(true);
@@ -108,11 +108,11 @@ class X509AuthenticationListenerTest extends \PHPUnit_Framework_TestCase
'TheUserKey' => 'TheUser',
'TheCredentialsKey' => 'TheCredentials',
));
- $context = $this->getMock('Symfony\Component\Security\Core\SecurityContextInterface');
+ $tokenStorage = $this->getMock('Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface');
$authenticationManager = $this->getMock('Symfony\Component\Security\Core\Authentication\AuthenticationManagerInterface');
- $listener = new X509AuthenticationListener($context, $authenticationManager, 'TheProviderKey', 'TheUserKey', 'TheCredentialsKey');
+ $listener = new X509AuthenticationListener($tokenStorage, $authenticationManager, 'TheProviderKey', 'TheUserKey', 'TheCredentialsKey');
$method = new \ReflectionMethod($listener, 'getPreAuthenticatedData');
$method->setAccessible(true);