[Security] fixed some tests

This commit is contained in:
Johannes Schmitt 2011-03-11 01:53:47 +01:00 committed by Johannes M. Schmitt
parent c73d1c3406
commit 97125269d2
10 changed files with 18 additions and 32 deletions

View File

@ -156,8 +156,7 @@ class SecurityExtension extends Extension
$access['path'], $access['path'],
$access['host'], $access['host'],
count($access['methods']) === 0 ? null : $access['methods'], count($access['methods']) === 0 ? null : $access['methods'],
$access['ip'], $access['ip']
$access['attributes']
); );
$container->getDefinition('security.access_map') $container->getDefinition('security.access_map')

View File

@ -2,6 +2,7 @@
namespace Symfony\Bundle\SecurityBundle; namespace Symfony\Bundle\SecurityBundle;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\EventDispatcher\EventInterface; use Symfony\Component\EventDispatcher\EventInterface;
use Symfony\Component\Security\Http\RememberMe\RememberMeServicesInterface; use Symfony\Component\Security\Http\RememberMe\RememberMeServicesInterface;
@ -12,13 +13,15 @@ use Symfony\Component\Security\Http\RememberMe\RememberMeServicesInterface;
*/ */
class ResponseListener class ResponseListener
{ {
public function handle(EventInterface $event) public function handle(EventInterface $event, Response $response)
{ {
$request = $event->get('request'); $request = $event->get('request');
if (!$request->attributes->has(RememberMeServicesInterface::COOKIE_ATTR_NAME)) { 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;
} }
} }

View File

@ -58,7 +58,7 @@ $container->loadFromExtension('security', array(
'access_control' => array( 'access_control' => array(
array('path' => '/blog/524', 'role' => 'ROLE_USER', 'requires_channel' => 'https'), 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( 'role_hierarchy' => array(

View File

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

View File

@ -50,5 +50,4 @@ security:
- { path: /blog/524, role: ROLE_USER, requires_channel: https } - { path: /blog/524, role: ROLE_USER, requires_channel: https }
- -
path: /blog/.* path: /blog/.*
attributes: { _controller: .*\\BlogBundle\\.* }
role: IS_AUTHENTICATED_ANONYMOUSLY role: IS_AUTHENTICATED_ANONYMOUSLY

View File

@ -38,7 +38,7 @@ class Firewall
* *
* @param FirewallMap $map A FirewallMap instance * @param FirewallMap $map A FirewallMap instance
*/ */
public function __construct(FirewallMapInterface $map) public function __construct(FirewallMapInterface $map, EventDispatcherInterface $dispatcher)
{ {
$this->map = $map; $this->map = $map;
$this->dispatcher = $dispatcher; $this->dispatcher = $dispatcher;

View File

@ -46,8 +46,8 @@ class ContextListener implements ListenerInterface
$this->userProviders = $userProviders; $this->userProviders = $userProviders;
$this->contextKey = $contextKey; $this->contextKey = $contextKey;
if (null !== $this->eventDispatcher) { if (null !== $eventDispatcher) {
$this->eventDispatcher->connect('core.response', array($this, 'write'), 0); $eventDispatcher->connect('core.response', array($this, 'write'), 0);
} }
} }

View File

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

View File

@ -160,6 +160,7 @@ abstract class AbstractRememberMeServices implements RememberMeServicesInterface
public final function loginFail(Request $request) public final function loginFail(Request $request)
{ {
$this->cancelCookie($request); $this->cancelCookie($request);
$this->onLoginFail($request);
} }
/** /**

View File

@ -11,20 +11,6 @@ use Symfony\Component\HttpFoundation\Request;
class RememberMeListenerTest extends \PHPUnit_Framework_TestCase 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() public function testCheckCookiesDoesNotTryToPopulateNonEmptySecurityContext()
{ {
list($listener, $context, $service,,) = $this->getListener(); list($listener, $context, $service,,) = $this->getListener();
@ -40,7 +26,7 @@ class RememberMeListenerTest extends \PHPUnit_Framework_TestCase
->method('setToken') ->method('setToken')
; ;
$this->assertNull($listener->checkCookies($this->getEvent())); $this->assertNull($listener->handle($this->getEvent()));
} }
public function testCheckCookiesDoesNothingWhenNoCookieIsSet() public function testCheckCookiesDoesNothingWhenNoCookieIsSet()
@ -67,7 +53,7 @@ class RememberMeListenerTest extends \PHPUnit_Framework_TestCase
->will($this->returnValue(new Request())) ->will($this->returnValue(new Request()))
; ;
$this->assertNull($listener->checkCookies($event)); $this->assertNull($listener->handle($event));
} }
public function testCheckCookiesIgnoresAuthenticationExceptionThrownByAuthenticationManagerImplementation() public function testCheckCookiesIgnoresAuthenticationExceptionThrownByAuthenticationManagerImplementation()
@ -106,7 +92,7 @@ class RememberMeListenerTest extends \PHPUnit_Framework_TestCase
->will($this->returnValue(new Request())) ->will($this->returnValue(new Request()))
; ;
$listener->checkCookies($event); $listener->handle($event);
} }
public function testCheckCookies() public function testCheckCookies()
@ -146,7 +132,7 @@ class RememberMeListenerTest extends \PHPUnit_Framework_TestCase
->will($this->returnValue(new Request())) ->will($this->returnValue(new Request()))
; ;
$listener->checkCookies($event); $listener->handle($event);
} }
protected function getEvent() protected function getEvent()