From 97125269d2fda0f8d7f84631479d47c0a0f1808f Mon Sep 17 00:00:00 2001 From: Johannes Schmitt Date: Fri, 11 Mar 2011 01:53:47 +0100 Subject: [PATCH] [Security] fixed some tests --- .../DependencyInjection/SecurityExtension.php | 3 +-- .../SecurityBundle/ResponseListener.php | 9 +++++--- .../Fixtures/php/container1.php | 2 +- .../Fixtures/xml/container1.xml | 4 +--- .../Fixtures/yml/container1.yml | 1 - .../Component/Security/Http/Firewall.php | 2 +- .../Http/Firewall/ContextListener.php | 4 ++-- .../Http/Firewall/ExceptionListener.php | 2 +- .../RememberMe/AbstractRememberMeServices.php | 1 + .../Http/Firewall/RememberMeListenerTest.php | 22 ++++--------------- 10 files changed, 18 insertions(+), 32 deletions(-) diff --git a/src/Symfony/Bundle/SecurityBundle/DependencyInjection/SecurityExtension.php b/src/Symfony/Bundle/SecurityBundle/DependencyInjection/SecurityExtension.php index 05996c6cdb..759e777f1a 100644 --- a/src/Symfony/Bundle/SecurityBundle/DependencyInjection/SecurityExtension.php +++ b/src/Symfony/Bundle/SecurityBundle/DependencyInjection/SecurityExtension.php @@ -156,8 +156,7 @@ class SecurityExtension extends Extension $access['path'], $access['host'], count($access['methods']) === 0 ? null : $access['methods'], - $access['ip'], - $access['attributes'] + $access['ip'] ); $container->getDefinition('security.access_map') diff --git a/src/Symfony/Bundle/SecurityBundle/ResponseListener.php b/src/Symfony/Bundle/SecurityBundle/ResponseListener.php index dfebf6b425..93b1c8af6d 100644 --- a/src/Symfony/Bundle/SecurityBundle/ResponseListener.php +++ b/src/Symfony/Bundle/SecurityBundle/ResponseListener.php @@ -2,6 +2,7 @@ namespace Symfony\Bundle\SecurityBundle; +use Symfony\Component\HttpFoundation\Response; use Symfony\Component\EventDispatcher\EventInterface; use Symfony\Component\Security\Http\RememberMe\RememberMeServicesInterface; @@ -12,13 +13,15 @@ use Symfony\Component\Security\Http\RememberMe\RememberMeServicesInterface; */ class ResponseListener { - public function handle(EventInterface $event) + public function handle(EventInterface $event, Response $response) { $request = $event->get('request'); if (!$request->attributes->has(RememberMeServicesInterface::COOKIE_ATTR_NAME)) { - return; + return $response; } - $event->get('response')->headers->setCookie($request->attributes->get(RememberMeServicesInterface::COOKIE_ATTR_NAME)); + $response->headers->setCookie($request->attributes->get(RememberMeServicesInterface::COOKIE_ATTR_NAME)); + + return $response; } } \ No newline at end of file diff --git a/src/Symfony/Bundle/SecurityBundle/Tests/DependencyInjection/Fixtures/php/container1.php b/src/Symfony/Bundle/SecurityBundle/Tests/DependencyInjection/Fixtures/php/container1.php index 4b42a2c83f..66594ae03b 100644 --- a/src/Symfony/Bundle/SecurityBundle/Tests/DependencyInjection/Fixtures/php/container1.php +++ b/src/Symfony/Bundle/SecurityBundle/Tests/DependencyInjection/Fixtures/php/container1.php @@ -58,7 +58,7 @@ $container->loadFromExtension('security', array( 'access_control' => array( array('path' => '/blog/524', 'role' => 'ROLE_USER', 'requires_channel' => 'https'), - array('path' => '/blog/.*', 'attributes' => array('_controller' => '.*\\BlogBundle\\.*'), 'role' => 'IS_AUTHENTICATED_ANONYMOUSLY'), + array('path' => '/blog/.*', 'role' => 'IS_AUTHENTICATED_ANONYMOUSLY'), ), 'role_hierarchy' => array( diff --git a/src/Symfony/Bundle/SecurityBundle/Tests/DependencyInjection/Fixtures/xml/container1.xml b/src/Symfony/Bundle/SecurityBundle/Tests/DependencyInjection/Fixtures/xml/container1.xml index 0d56f89996..efd204ac95 100644 --- a/src/Symfony/Bundle/SecurityBundle/Tests/DependencyInjection/Fixtures/xml/container1.xml +++ b/src/Symfony/Bundle/SecurityBundle/Tests/DependencyInjection/Fixtures/xml/container1.xml @@ -52,8 +52,6 @@ ROLE_USER,ROLE_ADMIN - - - + diff --git a/src/Symfony/Bundle/SecurityBundle/Tests/DependencyInjection/Fixtures/yml/container1.yml b/src/Symfony/Bundle/SecurityBundle/Tests/DependencyInjection/Fixtures/yml/container1.yml index c0d6fb323d..4f1d8a3c2c 100644 --- a/src/Symfony/Bundle/SecurityBundle/Tests/DependencyInjection/Fixtures/yml/container1.yml +++ b/src/Symfony/Bundle/SecurityBundle/Tests/DependencyInjection/Fixtures/yml/container1.yml @@ -50,5 +50,4 @@ security: - { path: /blog/524, role: ROLE_USER, requires_channel: https } - path: /blog/.* - attributes: { _controller: .*\\BlogBundle\\.* } role: IS_AUTHENTICATED_ANONYMOUSLY diff --git a/src/Symfony/Component/Security/Http/Firewall.php b/src/Symfony/Component/Security/Http/Firewall.php index 4935985652..bd77f6d892 100644 --- a/src/Symfony/Component/Security/Http/Firewall.php +++ b/src/Symfony/Component/Security/Http/Firewall.php @@ -38,7 +38,7 @@ class Firewall * * @param FirewallMap $map A FirewallMap instance */ - public function __construct(FirewallMapInterface $map) + public function __construct(FirewallMapInterface $map, EventDispatcherInterface $dispatcher) { $this->map = $map; $this->dispatcher = $dispatcher; diff --git a/src/Symfony/Component/Security/Http/Firewall/ContextListener.php b/src/Symfony/Component/Security/Http/Firewall/ContextListener.php index 4779b70a81..548876a223 100644 --- a/src/Symfony/Component/Security/Http/Firewall/ContextListener.php +++ b/src/Symfony/Component/Security/Http/Firewall/ContextListener.php @@ -46,8 +46,8 @@ class ContextListener implements ListenerInterface $this->userProviders = $userProviders; $this->contextKey = $contextKey; - if (null !== $this->eventDispatcher) { - $this->eventDispatcher->connect('core.response', array($this, 'write'), 0); + if (null !== $eventDispatcher) { + $eventDispatcher->connect('core.response', array($this, 'write'), 0); } } diff --git a/src/Symfony/Component/Security/Http/Firewall/ExceptionListener.php b/src/Symfony/Component/Security/Http/Firewall/ExceptionListener.php index 110290c442..7d1b892bd8 100644 --- a/src/Symfony/Component/Security/Http/Firewall/ExceptionListener.php +++ b/src/Symfony/Component/Security/Http/Firewall/ExceptionListener.php @@ -32,7 +32,7 @@ use Symfony\Component\HttpKernel\HttpKernelInterface; * * @author Fabien Potencier */ -class ExceptionListener implements ListenerInterface +class ExceptionListener { private $context; private $accessDeniedHandler; diff --git a/src/Symfony/Component/Security/Http/RememberMe/AbstractRememberMeServices.php b/src/Symfony/Component/Security/Http/RememberMe/AbstractRememberMeServices.php index daf68f558f..b090e24f6b 100644 --- a/src/Symfony/Component/Security/Http/RememberMe/AbstractRememberMeServices.php +++ b/src/Symfony/Component/Security/Http/RememberMe/AbstractRememberMeServices.php @@ -160,6 +160,7 @@ abstract class AbstractRememberMeServices implements RememberMeServicesInterface public final function loginFail(Request $request) { $this->cancelCookie($request); + $this->onLoginFail($request); } /** diff --git a/tests/Symfony/Tests/Component/Security/Http/Firewall/RememberMeListenerTest.php b/tests/Symfony/Tests/Component/Security/Http/Firewall/RememberMeListenerTest.php index bb8720cae8..2ab8efbb1a 100644 --- a/tests/Symfony/Tests/Component/Security/Http/Firewall/RememberMeListenerTest.php +++ b/tests/Symfony/Tests/Component/Security/Http/Firewall/RememberMeListenerTest.php @@ -11,20 +11,6 @@ use Symfony\Component\HttpFoundation\Request; class RememberMeListenerTest extends \PHPUnit_Framework_TestCase { - public function testRegister() - { - list($listener,,,,) = $this->getListener(); - - $dispatcher = $this->getMock('Symfony\Component\EventDispatcher\EventDispatcher'); - $dispatcher - ->expects($this->at(0)) - ->method('connect') - ->with($this->equalTo('core.security')) - ; - - $listener->register($dispatcher); - } - public function testCheckCookiesDoesNotTryToPopulateNonEmptySecurityContext() { list($listener, $context, $service,,) = $this->getListener(); @@ -40,7 +26,7 @@ class RememberMeListenerTest extends \PHPUnit_Framework_TestCase ->method('setToken') ; - $this->assertNull($listener->checkCookies($this->getEvent())); + $this->assertNull($listener->handle($this->getEvent())); } public function testCheckCookiesDoesNothingWhenNoCookieIsSet() @@ -67,7 +53,7 @@ class RememberMeListenerTest extends \PHPUnit_Framework_TestCase ->will($this->returnValue(new Request())) ; - $this->assertNull($listener->checkCookies($event)); + $this->assertNull($listener->handle($event)); } public function testCheckCookiesIgnoresAuthenticationExceptionThrownByAuthenticationManagerImplementation() @@ -106,7 +92,7 @@ class RememberMeListenerTest extends \PHPUnit_Framework_TestCase ->will($this->returnValue(new Request())) ; - $listener->checkCookies($event); + $listener->handle($event); } public function testCheckCookies() @@ -146,7 +132,7 @@ class RememberMeListenerTest extends \PHPUnit_Framework_TestCase ->will($this->returnValue(new Request())) ; - $listener->checkCookies($event); + $listener->handle($event); } protected function getEvent()