Sfoglia il codice sorgente

[Security] fixed some tests

Johannes Schmitt 14 anni fa
parent
commit
97125269d2

+ 1 - 2
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')

+ 6 - 3
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;
     }
 }

+ 1 - 1
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(

+ 1 - 3
src/Symfony/Bundle/SecurityBundle/Tests/DependencyInjection/Fixtures/xml/container1.xml

@@ -52,8 +52,6 @@
         <role id="ROLE_REMOTE">ROLE_USER,ROLE_ADMIN</role>
 
         <rule path="/blog/524" role="ROLE_USER" requires-channel="https" />
-        <rule role='IS_AUTHENTICATED_ANONYMOUSLY' path="/blog/.*">
-            <attribute key="_controller" pattern=".*\\BlogBundle\\.*" />
-        </rule>
+        <rule role='IS_AUTHENTICATED_ANONYMOUSLY' path="/blog/.*" />
     </config>
 </srv:container>

+ 0 - 1
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

+ 1 - 1
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;

+ 2 - 2
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);
         }
     }
 

+ 1 - 1
src/Symfony/Component/Security/Http/Firewall/ExceptionListener.php

@@ -32,7 +32,7 @@ use Symfony\Component\HttpKernel\HttpKernelInterface;
  *
  * @author Fabien Potencier <fabien@symfony.com>
  */
-class ExceptionListener implements ListenerInterface
+class ExceptionListener
 {
     private $context;
     private $accessDeniedHandler;

+ 1 - 0
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);
     }
 
     /**

+ 4 - 18
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()