-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Security] Allow exception bubbling in RememberMeListener #10793
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
fabpot
merged 1 commit into
symfony:master
from
InterNations:features/rememberme-exception-bubble
Jul 25, 2014
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
...fony/Bundle/SecurityBundle/Tests/DependencyInjection/Fixtures/php/remember_me_options.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<?php | ||
$container->loadFromExtension('security', array( | ||
'providers' => array( | ||
'default' => array('id' => 'foo'), | ||
), | ||
|
||
'firewalls' => array( | ||
'main' => array( | ||
'form_login' => true, | ||
'remember_me' => array( | ||
'key' => 'TheyKey', | ||
'catch_exceptions' => false, | ||
'token_provider' => 'token_provider_id', | ||
) | ||
) | ||
), | ||
)); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
...fony/Bundle/SecurityBundle/Tests/DependencyInjection/Fixtures/xml/remember_me_options.xml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
|
||
<container xmlns="http://symfony.com/schema/dic/services" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xmlns:sec="http://symfony.com/schema/dic/security" | ||
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd"> | ||
|
||
<sec:config> | ||
<sec:providers> | ||
<sec:default id="foo"/> | ||
</sec:providers> | ||
<sec:firewall name="main"> | ||
<sec:form-login/> | ||
<sec:remember-me key="TheKey" catch-exceptions="false" token-provider="token_provider_id" /> | ||
</sec:firewall> | ||
</sec:config> | ||
|
||
</container> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
...fony/Bundle/SecurityBundle/Tests/DependencyInjection/Fixtures/yml/remember_me_options.yml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
security: | ||
providers: | ||
default: | ||
id: foo | ||
|
||
firewalls: | ||
main: | ||
form_login: true | ||
remember_me: | ||
key: TheKey | ||
catch_exceptions: false | ||
token_provider: token_provider_id |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,12 +14,13 @@ | |
use Symfony\Component\Security\Core\Exception\AuthenticationException; | ||
use Symfony\Component\Security\Http\Firewall\RememberMeListener; | ||
use Symfony\Component\HttpFoundation\Request; | ||
use Symfony\Component\Security\Http\SecurityEvents; | ||
|
||
class RememberMeListenerTest extends \PHPUnit_Framework_TestCase | ||
{ | ||
public function testOnCoreSecurityDoesNotTryToPopulateNonEmptySecurityContext() | ||
{ | ||
list($listener, $context, $service,,) = $this->getListener(); | ||
list($listener, $context,,,,) = $this->getListener(); | ||
|
||
$context | ||
->expects($this->once()) | ||
|
@@ -99,6 +100,48 @@ public function testOnCoreSecurityIgnoresAuthenticationExceptionThrownByAuthenti | |
$listener->handle($event); | ||
} | ||
|
||
/** | ||
* @expectedException Symfony\Component\Security\Core\Exception\AuthenticationException | ||
* @expectedExceptionMessage Authentication failed. | ||
*/ | ||
public function testOnCoreSecurityIgnoresAuthenticationOptionallyRethrowsExceptionThrownAuthenticationManagerImplementation() | ||
{ | ||
list($listener, $context, $service, $manager,) = $this->getListener(false, false); | ||
|
||
$context | ||
->expects($this->once()) | ||
->method('getToken') | ||
->will($this->returnValue(null)) | ||
; | ||
|
||
$service | ||
->expects($this->once()) | ||
->method('autoLogin') | ||
->will($this->returnValue($this->getMock('Symfony\Component\Security\Core\Authentication\Token\TokenInterface'))) | ||
; | ||
|
||
$service | ||
->expects($this->once()) | ||
->method('loginFail') | ||
; | ||
|
||
$exception = new AuthenticationException('Authentication failed.'); | ||
$manager | ||
->expects($this->once()) | ||
->method('authenticate') | ||
->will($this->throwException($exception)) | ||
; | ||
|
||
$event = $this->getGetResponseEvent(); | ||
$event | ||
->expects($this->once()) | ||
->method('getRequest') | ||
->will($this->returnValue(new Request())) | ||
; | ||
|
||
$listener->handle($event); | ||
} | ||
|
||
public function testOnCoreSecurity() | ||
{ | ||
list($listener, $context, $service, $manager,) = $this->getListener(); | ||
|
@@ -138,6 +181,55 @@ public function testOnCoreSecurity() | |
$listener->handle($event); | ||
} | ||
|
||
public function testOnCoreSecurityInteractiveLoginEventIsDispatchedIfDispatcherIsPresent() | ||
{ | ||
list($listener, $context, $service, $manager,, $dispatcher) = $this->getListener(true); | ||
|
||
$context | ||
->expects($this->once()) | ||
->method('getToken') | ||
->will($this->returnValue(null)) | ||
; | ||
|
||
$token = $this->getMock('Symfony\Component\Security\Core\Authentication\Token\TokenInterface'); | ||
$service | ||
->expects($this->once()) | ||
->method('autoLogin') | ||
->will($this->returnValue($token)) | ||
; | ||
|
||
$context | ||
->expects($this->once()) | ||
->method('setToken') | ||
->with($this->equalTo($token)) | ||
; | ||
|
||
$manager | ||
->expects($this->once()) | ||
->method('authenticate') | ||
->will($this->returnValue($token)) | ||
; | ||
|
||
$event = $this->getGetResponseEvent(); | ||
$request = new Request(); | ||
$event | ||
->expects($this->once()) | ||
->method('getRequest') | ||
->will($this->returnValue($request)) | ||
; | ||
|
||
$dispatcher | ||
->expects($this->once()) | ||
->method('dispatch') | ||
->with( | ||
SecurityEvents::INTERACTIVE_LOGIN, | ||
$this->isInstanceOf('Symfony\Component\Security\Http\Event\InteractiveLoginEvent') | ||
) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed, thank you! |
||
; | ||
|
||
$listener->handle($event); | ||
} | ||
|
||
protected function getGetResponseEvent() | ||
{ | ||
return $this->getMock('Symfony\Component\HttpKernel\Event\GetResponseEvent', array(), array(), '', false); | ||
|
@@ -148,16 +240,18 @@ protected function getFilterResponseEvent() | |
return $this->getMock('Symfony\Component\HttpKernel\Event\FilterResponseEvent', array(), array(), '', false); | ||
} | ||
|
||
protected function getListener() | ||
protected function getListener($withDispatcher = false, $catchExceptions = true) | ||
{ | ||
$listener = new RememberMeListener( | ||
$context = $this->getContext(), | ||
$service = $this->getService(), | ||
$manager = $this->getManager(), | ||
$logger = $this->getLogger() | ||
$logger = $this->getLogger(), | ||
$dispatcher = ($withDispatcher ? $this->getDispatcher() : null), | ||
$catchExceptions | ||
); | ||
|
||
return array($listener, $context, $service, $manager, $logger); | ||
return array($listener, $context, $service, $manager, $logger, $dispatcher); | ||
} | ||
|
||
protected function getLogger() | ||
|
@@ -177,8 +271,11 @@ protected function getService() | |
|
||
protected function getContext() | ||
{ | ||
return $this->getMockBuilder('Symfony\Component\Security\Core\SecurityContext') | ||
->disableOriginalConstructor() | ||
->getMock(); | ||
return $this->getMock('Symfony\Component\Security\Core\SecurityContextInterface'); | ||
} | ||
|
||
protected function getDispatcher() | ||
{ | ||
return $this->getMock('Symfony\Component\EventDispatcher\EventDispatcherInterface'); | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You need to add a comment in the XML definition (like for the other argument.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added.