summaryrefslogtreecommitdiffstats
path: root/Tests/Http
diff options
context:
space:
mode:
Diffstat (limited to 'Tests/Http')
-rw-r--r--Tests/Http/AccessMapTest.php58
-rw-r--r--Tests/Http/Authentication/DefaultAuthenticationFailureHandlerTest.php186
-rw-r--r--Tests/Http/Authentication/DefaultAuthenticationSuccessHandlerTest.php173
-rw-r--r--Tests/Http/EntryPoint/FormAuthenticationEntryPointTest.php7
-rw-r--r--Tests/Http/Firewall/DigestDataTest.php12
-rw-r--r--Tests/Http/Logout/DefaultLogoutSuccessHandlerTest.php42
-rw-r--r--Tests/Http/RememberMe/ResponseListenerTest.php92
-rw-r--r--Tests/Http/Session/SessionAuthenticationStrategyTest.php80
8 files changed, 642 insertions, 8 deletions
diff --git a/Tests/Http/AccessMapTest.php b/Tests/Http/AccessMapTest.php
new file mode 100644
index 0000000..653152a
--- /dev/null
+++ b/Tests/Http/AccessMapTest.php
@@ -0,0 +1,58 @@
+<?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;
+
+use Symfony\Component\Security\Http\AccessMap;
+
+class AccessMapTest extends \PHPUnit_Framework_TestCase
+{
+ protected function setUp()
+ {
+ if (!class_exists('Symfony\Component\HttpFoundation\Request')) {
+ $this->markTestSkipped('The "HttpFoundation" component is not available');
+ }
+ }
+
+ public function testReturnsFirstMatchedPattern()
+ {
+ $request = $this->getMock('Symfony\Component\HttpFoundation\Request');
+ $requestMatcher1 = $this->getRequestMatcher($request, false);
+ $requestMatcher2 = $this->getRequestMatcher($request, true);
+
+ $map = new AccessMap();
+ $map->add($requestMatcher1, array('ROLE_ADMIN'), 'http');
+ $map->add($requestMatcher2, array('ROLE_USER'), 'https');
+
+ $this->assertSame(array(array('ROLE_USER'), 'https'), $map->getPatterns($request));
+ }
+
+ public function testReturnsEmptyPatternIfNoneMatched()
+ {
+ $request = $this->getMock('Symfony\Component\HttpFoundation\Request');
+ $requestMatcher = $this->getRequestMatcher($request, false);
+
+ $map = new AccessMap();
+ $map->add($requestMatcher, array('ROLE_USER'), 'https');
+
+ $this->assertSame(array(null, null), $map->getPatterns($request));
+ }
+
+ private function getRequestMatcher($request, $matches)
+ {
+ $requestMatcher = $this->getMock('Symfony\Component\HttpFoundation\RequestMatcherInterface');
+ $requestMatcher->expects($this->once())
+ ->method('matches')->with($request)
+ ->will($this->returnValue($matches));
+
+ return $requestMatcher;
+ }
+}
diff --git a/Tests/Http/Authentication/DefaultAuthenticationFailureHandlerTest.php b/Tests/Http/Authentication/DefaultAuthenticationFailureHandlerTest.php
new file mode 100644
index 0000000..c51893f
--- /dev/null
+++ b/Tests/Http/Authentication/DefaultAuthenticationFailureHandlerTest.php
@@ -0,0 +1,186 @@
+<?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;
+
+use Symfony\Component\Security\Http\Authentication\DefaultAuthenticationFailureHandler;
+use Symfony\Component\Security\Core\SecurityContextInterface;
+use Symfony\Component\HttpKernel\HttpKernelInterface;
+
+class DefaultAuthenticationFailureHandlerTest extends \PHPUnit_Framework_TestCase
+{
+ private $httpKernel = null;
+
+ private $httpUtils = null;
+
+ private $logger = null;
+
+ private $request = null;
+
+ private $session = null;
+
+ private $exception = null;
+
+ protected function setUp()
+ {
+ if (!class_exists('Symfony\Component\HttpKernel\HttpKernel')) {
+ $this->markTestSkipped('The "HttpKernel" component is not available');
+ }
+
+ if (!class_exists('Symfony\Component\HttpFoundation\Request')) {
+ $this->markTestSkipped('The "HttpFoundation" component is not available');
+ }
+
+ if (!interface_exists('Psr\Log\LoggerInterface')) {
+ $this->markTestSkipped('The "LoggerInterface" is not available');
+ }
+
+ $this->httpKernel = $this->getMock('Symfony\Component\HttpKernel\HttpKernelInterface');
+ $this->httpUtils = $this->getMock('Symfony\Component\Security\Http\HttpUtils');
+ $this->logger = $this->getMock('Psr\Log\LoggerInterface');
+
+ $this->session = $this->getMock('Symfony\Component\HttpFoundation\Session\SessionInterface');
+ $this->request = $this->getMock('Symfony\Component\HttpFoundation\Request');
+ $this->request->expects($this->any())->method('getSession')->will($this->returnValue($this->session));
+ $this->exception = $this->getMock('Symfony\Component\Security\Core\Exception\AuthenticationException');
+ }
+
+ public function testForward()
+ {
+ $options = array('failure_forward' => true);
+
+ $subRequest = $this->getRequest();
+ $subRequest->attributes->expects($this->once())
+ ->method('set')->with(SecurityContextInterface::AUTHENTICATION_ERROR, $this->exception);
+ $this->httpUtils->expects($this->once())
+ ->method('createRequest')->with($this->request, '/login')
+ ->will($this->returnValue($subRequest));
+
+ $response = $this->getMock('Symfony\Component\HttpFoundation\Response');
+ $this->httpKernel->expects($this->once())
+ ->method('handle')->with($subRequest, HttpKernelInterface::SUB_REQUEST)
+ ->will($this->returnValue($response));
+
+ $handler = new DefaultAuthenticationFailureHandler($this->httpKernel, $this->httpUtils, $options, $this->logger);
+ $result = $handler->onAuthenticationFailure($this->request, $this->exception);
+
+ $this->assertSame($response, $result);
+ }
+
+ public function testRedirect()
+ {
+ $response = $this->getMock('Symfony\Component\HttpFoundation\Response');
+ $this->httpUtils->expects($this->once())
+ ->method('createRedirectResponse')->with($this->request, '/login')
+ ->will($this->returnValue($response));
+
+ $handler = new DefaultAuthenticationFailureHandler($this->httpKernel, $this->httpUtils, array(), $this->logger);
+ $result = $handler->onAuthenticationFailure($this->request, $this->exception);
+
+ $this->assertSame($response, $result);
+ }
+
+ public function testExceptionIsPersistedInSession()
+ {
+ $this->session->expects($this->once())
+ ->method('set')->with(SecurityContextInterface::AUTHENTICATION_ERROR, $this->exception);
+
+ $handler = new DefaultAuthenticationFailureHandler($this->httpKernel, $this->httpUtils, array(), $this->logger);
+ $handler->onAuthenticationFailure($this->request, $this->exception);
+ }
+
+ public function testExceptionIsPassedInRequestOnForward()
+ {
+ $options = array('failure_forward' => true);
+
+ $subRequest = $this->getRequest();
+ $subRequest->attributes->expects($this->once())
+ ->method('set')->with(SecurityContextInterface::AUTHENTICATION_ERROR, $this->exception);
+
+ $this->httpUtils->expects($this->once())
+ ->method('createRequest')->with($this->request, '/login')
+ ->will($this->returnValue($subRequest));
+
+ $this->session->expects($this->never())->method('set');
+
+ $handler = new DefaultAuthenticationFailureHandler($this->httpKernel, $this->httpUtils, $options, $this->logger);
+ $handler->onAuthenticationFailure($this->request, $this->exception);
+ }
+
+ public function testRedirectIsLogged()
+ {
+ $this->logger->expects($this->once())->method('debug')->with('Redirecting to /login');
+
+ $handler = new DefaultAuthenticationFailureHandler($this->httpKernel, $this->httpUtils, array(), $this->logger);
+ $handler->onAuthenticationFailure($this->request, $this->exception);
+ }
+
+ public function testForwardIsLogged()
+ {
+ $options = array('failure_forward' => true);
+
+ $this->httpUtils->expects($this->once())
+ ->method('createRequest')->with($this->request, '/login')
+ ->will($this->returnValue($this->getRequest()));
+
+ $this->logger->expects($this->once())->method('debug')->with('Forwarding to /login');
+
+ $handler = new DefaultAuthenticationFailureHandler($this->httpKernel, $this->httpUtils, $options, $this->logger);
+ $handler->onAuthenticationFailure($this->request, $this->exception);
+ }
+
+ public function testFailurePathCanBeOverwritten()
+ {
+ $options = array('failure_path' => '/auth/login');
+
+ $this->httpUtils->expects($this->once())
+ ->method('createRedirectResponse')->with($this->request, '/auth/login');
+
+ $handler = new DefaultAuthenticationFailureHandler($this->httpKernel, $this->httpUtils, $options, $this->logger);
+ $handler->onAuthenticationFailure($this->request, $this->exception);
+ }
+
+ public function testFailurePathCanBeOverwrittenWithRequest()
+ {
+ $this->request->expects($this->once())
+ ->method('get')->with('_failure_path', null, true)
+ ->will($this->returnValue('/auth/login'));
+
+ $this->httpUtils->expects($this->once())
+ ->method('createRedirectResponse')->with($this->request, '/auth/login');
+
+ $handler = new DefaultAuthenticationFailureHandler($this->httpKernel, $this->httpUtils, array(), $this->logger);
+ $handler->onAuthenticationFailure($this->request, $this->exception);
+ }
+
+ public function testFailurePathParameterCanBeOverwritten()
+ {
+ $options = array('failure_path_parameter' => '_my_failure_path');
+
+ $this->request->expects($this->once())
+ ->method('get')->with('_my_failure_path', null, true)
+ ->will($this->returnValue('/auth/login'));
+
+ $this->httpUtils->expects($this->once())
+ ->method('createRedirectResponse')->with($this->request, '/auth/login');
+
+ $handler = new DefaultAuthenticationFailureHandler($this->httpKernel, $this->httpUtils, $options, $this->logger);
+ $handler->onAuthenticationFailure($this->request, $this->exception);
+ }
+
+ private function getRequest()
+ {
+ $request = $this->getMock('Symfony\Component\HttpFoundation\Request');
+ $request->attributes = $this->getMock('Symfony\Component\HttpFoundation\ParameterBag');
+
+ return $request;
+ }
+}
diff --git a/Tests/Http/Authentication/DefaultAuthenticationSuccessHandlerTest.php b/Tests/Http/Authentication/DefaultAuthenticationSuccessHandlerTest.php
new file mode 100644
index 0000000..71d6ad4
--- /dev/null
+++ b/Tests/Http/Authentication/DefaultAuthenticationSuccessHandlerTest.php
@@ -0,0 +1,173 @@
+<?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;
+
+use Symfony\Component\Security\Http\Authentication\DefaultAuthenticationSuccessHandler;
+
+class DefaultAuthenticationSuccessHandlerTest extends \PHPUnit_Framework_TestCase
+{
+ private $httpUtils = null;
+
+ private $request = null;
+
+ private $token = null;
+
+ protected function setUp()
+ {
+ if (!class_exists('Symfony\Component\HttpFoundation\Request')) {
+ $this->markTestSkipped('The "HttpFoundation" component is not available');
+ }
+
+ $this->httpUtils = $this->getMock('Symfony\Component\Security\Http\HttpUtils');
+ $this->request = $this->getMock('Symfony\Component\HttpFoundation\Request');
+ $this->request->headers = $this->getMock('Symfony\Component\HttpFoundation\HeaderBag');
+ $this->token = $this->getMock('Symfony\Component\Security\Core\Authentication\Token\TokenInterface');
+ }
+
+ public function testRequestIsRedirected()
+ {
+ $response = $this->expectRedirectResponse('/');
+
+ $handler = new DefaultAuthenticationSuccessHandler($this->httpUtils, array());
+ $result = $handler->onAuthenticationSuccess($this->request, $this->token);
+
+ $this->assertSame($response, $result);
+ }
+
+ public function testDefaultTargetPathCanBeForced()
+ {
+ $options = array(
+ 'always_use_default_target_path' => true,
+ 'default_target_path' => '/dashboard'
+ );
+
+ $response = $this->expectRedirectResponse('/dashboard');
+
+ $handler = new DefaultAuthenticationSuccessHandler($this->httpUtils, $options);
+ $result = $handler->onAuthenticationSuccess($this->request, $this->token);
+
+ $this->assertSame($response, $result);
+ }
+
+ public function testTargetPathIsPassedWithRequest()
+ {
+ $this->request->expects($this->once())
+ ->method('get')->with('_target_path')
+ ->will($this->returnValue('/dashboard'));
+
+ $response = $this->expectRedirectResponse('/dashboard');
+
+ $handler = new DefaultAuthenticationSuccessHandler($this->httpUtils, array());
+ $result = $handler->onAuthenticationSuccess($this->request, $this->token);
+
+ $this->assertSame($response, $result);
+ }
+
+ public function testTargetPathParameterIsCustomised()
+ {
+ $options = array('target_path_parameter' => '_my_target_path');
+
+ $this->request->expects($this->once())
+ ->method('get')->with('_my_target_path')
+ ->will($this->returnValue('/dashboard'));
+
+ $response = $this->expectRedirectResponse('/dashboard');
+
+ $handler = new DefaultAuthenticationSuccessHandler($this->httpUtils, $options);
+ $result = $handler->onAuthenticationSuccess($this->request, $this->token);
+
+ $this->assertSame($response, $result);
+ }
+
+ public function testTargetPathIsTakenFromTheSession()
+ {
+ $session = $this->getMock('Symfony\Component\HttpFoundation\Session\SessionInterface');
+ $session->expects($this->once())
+ ->method('get')->with('_security.admin.target_path')
+ ->will($this->returnValue('/admin/dashboard'));
+ $session->expects($this->once())
+ ->method('remove')->with('_security.admin.target_path');
+
+ $this->request->expects($this->any())
+ ->method('getSession')
+ ->will($this->returnValue($session));
+
+ $response = $this->expectRedirectResponse('/admin/dashboard');
+
+ $handler = new DefaultAuthenticationSuccessHandler($this->httpUtils, array());
+ $handler->setProviderKey('admin');
+
+ $result = $handler->onAuthenticationSuccess($this->request, $this->token);
+
+ $this->assertSame($response, $result);
+ }
+
+ public function testTargetPathIsPassedAsReferer()
+ {
+ $options = array('use_referer' => true);
+
+ $this->request->headers->expects($this->once())
+ ->method('get')->with('Referer')
+ ->will($this->returnValue('/dashboard'));
+
+ $response = $this->expectRedirectResponse('/dashboard');
+
+ $handler = new DefaultAuthenticationSuccessHandler($this->httpUtils, $options);
+ $result = $handler->onAuthenticationSuccess($this->request, $this->token);
+
+ $this->assertSame($response, $result);
+ }
+
+ public function testRefererHasToBeDifferentThatLoginUrl()
+ {
+ $options = array('use_referer' => true);
+
+ $this->request->headers->expects($this->any())
+ ->method('get')->with('Referer')
+ ->will($this->returnValue('/login'));
+
+ $this->httpUtils->expects($this->once())
+ ->method('generateUri')->with($this->request, '/login')
+ ->will($this->returnValue('/login'));
+
+ $response = $this->expectRedirectResponse('/');
+
+ $handler = new DefaultAuthenticationSuccessHandler($this->httpUtils, $options);
+ $result = $handler->onAuthenticationSuccess($this->request, $this->token);
+
+ $this->assertSame($response, $result);
+ }
+
+ public function testRefererTargetPathIsIgnoredByDefault()
+ {
+ $this->request->headers->expects($this->never())->method('get');
+
+ $response = $this->expectRedirectResponse('/');
+
+ $handler = new DefaultAuthenticationSuccessHandler($this->httpUtils, array());
+ $result = $handler->onAuthenticationSuccess($this->request, $this->token);
+
+ $this->assertSame($response, $result);
+ }
+
+ private function expectRedirectResponse($path)
+ {
+ $response = $this->getMock('Symfony\Component\HttpFoundation\Response');
+
+ $this->httpUtils->expects($this->once())
+ ->method('createRedirectResponse')
+ ->with($this->request, $path)
+ ->will($this->returnValue($response));
+
+ return $response;
+ }
+}
diff --git a/Tests/Http/EntryPoint/FormAuthenticationEntryPointTest.php b/Tests/Http/EntryPoint/FormAuthenticationEntryPointTest.php
index 1cf2c2d..cbec1bd 100644
--- a/Tests/Http/EntryPoint/FormAuthenticationEntryPointTest.php
+++ b/Tests/Http/EntryPoint/FormAuthenticationEntryPointTest.php
@@ -50,7 +50,7 @@ class FormAuthenticationEntryPointTest extends \PHPUnit_Framework_TestCase
{
$request = $this->getMock('Symfony\Component\HttpFoundation\Request', array(), array(), '', false, false);
$subRequest = $this->getMock('Symfony\Component\HttpFoundation\Request', array(), array(), '', false, false);
- $response = $this->getMock('Symfony\Component\HttpFoundation\Response');
+ $response = new \Symfony\Component\HttpFoundation\Response('', 200);
$httpUtils = $this->getMock('Symfony\Component\Security\Http\HttpUtils');
$httpUtils
@@ -70,6 +70,9 @@ class FormAuthenticationEntryPointTest extends \PHPUnit_Framework_TestCase
$entryPoint = new FormAuthenticationEntryPoint($httpKernel, $httpUtils, '/the/login/path', true);
- $this->assertEquals($response, $entryPoint->start($request));
+ $entryPointResponse = $entryPoint->start($request);
+
+ $this->assertEquals($response, $entryPointResponse);
+ $this->assertEquals(401, $entryPointResponse->headers->get('X-Status-Code'));
}
}
diff --git a/Tests/Http/Firewall/DigestDataTest.php b/Tests/Http/Firewall/DigestDataTest.php
index cfb929c..8b63d9c 100644
--- a/Tests/Http/Firewall/DigestDataTest.php
+++ b/Tests/Http/Firewall/DigestDataTest.php
@@ -103,10 +103,10 @@ class DigestDataTest extends \PHPUnit_Framework_TestCase
{
$time = microtime(true);
$key = 'ThisIsAKey';
- $nonce = base64_encode($time . ':' . md5($time . ':' . $key));
+ $nonce = base64_encode($time.':'.md5($time.':'.$key));
$digestAuth = new DigestData(
- 'username="user", realm="Welcome, robot!", nonce="' . $nonce . '", ' .
+ 'username="user", realm="Welcome, robot!", nonce="'.$nonce.'", ' .
'uri="/path/info?p1=5&p2=5", cnonce="MDIwODkz", nc=00000001, qop="auth", ' .
'response="b52938fc9e6d7c01be7702ece9031b42"'
);
@@ -143,10 +143,10 @@ class DigestDataTest extends \PHPUnit_Framework_TestCase
{
$time = microtime(true) + 10;
$key = 'ThisIsAKey';
- $nonce = base64_encode($time . ':' . md5($time . ':' . $key));
+ $nonce = base64_encode($time.':'.md5($time.':'.$key));
$digestAuth = new DigestData(
- 'username="user", realm="Welcome, robot!", nonce="' . $nonce . '", ' .
+ 'username="user", realm="Welcome, robot!", nonce="'.$nonce.'", ' .
'uri="/path/info?p1=5&p2=5", cnonce="MDIwODkz", nc=00000001, qop="auth", ' .
'response="b52938fc9e6d7c01be7702ece9031b42"'
);
@@ -164,10 +164,10 @@ class DigestDataTest extends \PHPUnit_Framework_TestCase
private function calculateServerDigest($username, $realm, $password, $key, $nc, $cnonce, $qop, $method, $uri)
{
$time = microtime(true);
- $nonce = base64_encode($time . ':' . md5($time . ':' . $key));
+ $nonce = base64_encode($time.':'.md5($time.':'.$key));
$response = md5(
- md5($username . ':' . $realm . ':' . $password) . ':' . $nonce . ':' . $nc . ':' . $cnonce . ':' . $qop . ':' . md5($method . ':' . $uri)
+ md5($username.':'.$realm.':'.$password).':'.$nonce.':'.$nc.':'.$cnonce.':'.$qop.':'.md5($method.':'.$uri)
);
$digest = sprintf('username="%s", realm="%s", nonce="%s", uri="%s", cnonce="%s", nc=%s, qop="%s", response="%s"',
diff --git a/Tests/Http/Logout/DefaultLogoutSuccessHandlerTest.php b/Tests/Http/Logout/DefaultLogoutSuccessHandlerTest.php
new file mode 100644
index 0000000..e1b1227
--- /dev/null
+++ b/Tests/Http/Logout/DefaultLogoutSuccessHandlerTest.php
@@ -0,0 +1,42 @@
+<?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\Logout;
+
+use Symfony\Component\HttpFoundation\Response;
+use Symfony\Component\Security\Http\Logout\DefaultLogoutSuccessHandler;
+
+class DefaultLogoutSuccessHandlerTest extends \PHPUnit_Framework_TestCase
+{
+ protected function setUp()
+ {
+ if (!class_exists('Symfony\Component\HttpFoundation\Request')) {
+ $this->markTestSkipped('The "HttpFoundation" component is not available');
+ }
+ }
+
+ public function testLogout()
+ {
+ $request = $this->getMock('Symfony\Component\HttpFoundation\Request');
+ $response = $this->getMock('Symfony\Component\HttpFoundation\Response');
+
+ $httpUtils = $this->getMock('Symfony\Component\Security\Http\HttpUtils');
+ $httpUtils->expects($this->once())
+ ->method('createRedirectResponse')
+ ->with($request, '/dashboard')
+ ->will($this->returnValue($response));
+
+ $handler = new DefaultLogoutSuccessHandler($httpUtils, '/dashboard');
+ $result = $handler->onLogoutSuccess($request);
+
+ $this->assertSame($response, $result);
+ }
+}
diff --git a/Tests/Http/RememberMe/ResponseListenerTest.php b/Tests/Http/RememberMe/ResponseListenerTest.php
new file mode 100644
index 0000000..cbd3f1f
--- /dev/null
+++ b/Tests/Http/RememberMe/ResponseListenerTest.php
@@ -0,0 +1,92 @@
+<?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\RememberMe;
+
+use Symfony\Component\Security\Http\RememberMe\ResponseListener;
+use Symfony\Component\Security\Http\RememberMe\RememberMeServicesInterface;
+use Symfony\Component\HttpFoundation\Request;
+use Symfony\Component\HttpFoundation\Cookie;
+use Symfony\Component\HttpKernel\KernelEvents;
+
+class ResponseListenerTest extends \PHPUnit_Framework_TestCase
+{
+ protected function setUp()
+ {
+ if (!class_exists('Symfony\Component\HttpFoundation\Request')) {
+ $this->markTestSkipped('The "HttpFoundation" component is not available');
+ }
+ }
+
+ public function testRememberMeCookieIsSentWithResponse()
+ {
+ $cookie = new Cookie('rememberme');
+
+ $request = $this->getRequest(array(
+ RememberMeServicesInterface::COOKIE_ATTR_NAME => $cookie
+ ));
+
+ $response = $this->getResponse();
+ $response->headers->expects($this->once())->method('setCookie')->with($cookie);
+
+ $listener = new ResponseListener();
+ $listener->onKernelResponse($this->getEvent($request, $response));
+ }
+
+ public function testRemmeberMeCookieIsNotSendWithResponse()
+ {
+ $request = $this->getRequest();
+
+ $response = $this->getResponse();
+ $response->headers->expects($this->never())->method('setCookie');
+
+ $listener = new ResponseListener();
+ $listener->onKernelResponse($this->getEvent($request, $response));
+ }
+
+ public function testItSubscribesToTheOnKernelResponseEvent()
+ {
+ $listener = new ResponseListener();
+
+ $this->assertSame(array(KernelEvents::RESPONSE => 'onKernelResponse'), $listener->getSubscribedEvents());
+ }
+
+ private function getRequest(array $attributes = array())
+ {
+ $request = new Request();
+
+ foreach ($attributes as $name => $value) {
+ $request->attributes->set($name, $value);
+ }
+
+ return $request;
+ }
+
+ private function getResponse()
+ {
+ $response = $this->getMock('Symfony\Component\HttpFoundation\Response');
+ $response->headers = $this->getMock('Symfony\Component\HttpFoundation\ResponseHeaderBag');
+
+ return $response;
+ }
+
+ private function getEvent($request, $response)
+ {
+ $event = $this->getMockBuilder('Symfony\Component\HttpKernel\Event\FilterResponseEvent')
+ ->disableOriginalConstructor()
+ ->getMock();
+
+ $event->expects($this->any())->method('getRequest')->will($this->returnValue($request));
+ $event->expects($this->any())->method('getResponse')->will($this->returnValue($response));
+
+ return $event;
+ }
+}
diff --git a/Tests/Http/Session/SessionAuthenticationStrategyTest.php b/Tests/Http/Session/SessionAuthenticationStrategyTest.php
new file mode 100644
index 0000000..43c52b5
--- /dev/null
+++ b/Tests/Http/Session/SessionAuthenticationStrategyTest.php
@@ -0,0 +1,80 @@
+<?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\Session;
+
+use Symfony\Component\Security\Http\Session\SessionAuthenticationStrategy;
+
+class SessionAuthenticationStrategyTest extends \PHPUnit_Framework_TestCase
+{
+ protected function setUp()
+ {
+ if (!class_exists('Symfony\Component\HttpFoundation\Request')) {
+ $this->markTestSkipped('The "HttpFoundation" component is not available');
+ }
+ }
+
+ public function testSessionIsNotChanged()
+ {
+ $request = $this->getRequest();
+ $request->expects($this->never())->method('getSession');
+
+ $strategy = new SessionAuthenticationStrategy(SessionAuthenticationStrategy::NONE);
+ $strategy->onAuthentication($request, $this->getToken());
+ }
+
+ /**
+ * @expectedException \RuntimeException
+ * @expectedExceptionMessage Invalid session authentication strategy "foo"
+ */
+ public function testUnsupportedStrategy()
+ {
+ $request = $this->getRequest();
+ $request->expects($this->never())->method('getSession');
+
+ $strategy = new SessionAuthenticationStrategy('foo');
+ $strategy->onAuthentication($request, $this->getToken());
+ }
+
+ public function testSessionIsMigrated()
+ {
+ $session = $this->getMock('Symfony\Component\HttpFoundation\Session\SessionInterface');
+ $session->expects($this->once())->method('migrate');
+
+ $strategy = new SessionAuthenticationStrategy(SessionAuthenticationStrategy::MIGRATE);
+ $strategy->onAuthentication($this->getRequest($session), $this->getToken());
+ }
+
+ public function testSessionIsInvalidated()
+ {
+ $session = $this->getMock('Symfony\Component\HttpFoundation\Session\SessionInterface');
+ $session->expects($this->once())->method('invalidate');
+
+ $strategy = new SessionAuthenticationStrategy(SessionAuthenticationStrategy::INVALIDATE);
+ $strategy->onAuthentication($this->getRequest($session), $this->getToken());
+ }
+
+ private function getRequest($session = null)
+ {
+ $request = $this->getMock('Symfony\Component\HttpFoundation\Request');
+
+ if (null !== $session) {
+ $request->expects($this->any())->method('getSession')->will($this->returnValue($session));
+ }
+
+ return $request;
+ }
+
+ private function getToken()
+ {
+ return $this->getMock('Symfony\Component\Security\Core\Authentication\Token\TokenInterface');
+ }
+}