summaryrefslogtreecommitdiffstats
path: root/Core/Tests
diff options
context:
space:
mode:
authorFabien Potencier <fabien.potencier@gmail.com>2013-12-29 21:34:05 +0100
committerFabien Potencier <fabien.potencier@gmail.com>2013-12-29 21:34:05 +0100
commit83e46fee1d960010bd09a9dbd82249a15e1602f4 (patch)
tree3c2300828baee3394410d55ee0d0a02f56e45243 /Core/Tests
parentfa9c90990e10a322a55caa8bb1ece92bb0a07ca3 (diff)
parent763b54967bf8bd0798bab530df38ec6b695d2d49 (diff)
downloadsymfony-security-83e46fee1d960010bd09a9dbd82249a15e1602f4.zip
symfony-security-83e46fee1d960010bd09a9dbd82249a15e1602f4.tar.gz
symfony-security-83e46fee1d960010bd09a9dbd82249a15e1602f4.tar.bz2
Merge branch '2.4'
* 2.4: fix some cs use restore_error_handler instead of set_error_handler($previous) fix #9321 Crawler::addHtmlContent add gbk encoding support [Console] fixed column width when using the Table helper with some decoration in cells [Security] Fixed problem with losing ROLE_PREVIOUS_ADMIN role. Fix for cache-key conflict when having a \Traversable as choices [Security] removed obsolete comment
Diffstat (limited to 'Core/Tests')
-rw-r--r--Core/Tests/Authentication/Provider/UserAuthenticationProviderTest.php44
1 files changed, 43 insertions, 1 deletions
diff --git a/Core/Tests/Authentication/Provider/UserAuthenticationProviderTest.php b/Core/Tests/Authentication/Provider/UserAuthenticationProviderTest.php
index c2b5781..db47589 100644
--- a/Core/Tests/Authentication/Provider/UserAuthenticationProviderTest.php
+++ b/Core/Tests/Authentication/Provider/UserAuthenticationProviderTest.php
@@ -13,6 +13,7 @@ namespace Symfony\Component\Security\Core\Tests\Authentication\Provider;
use Symfony\Component\Security\Core\Authentication\Provider\UserAuthenticationProvider;
use Symfony\Component\Security\Core\Role\Role;
+use Symfony\Component\Security\Core\Role\SwitchUserRole;
use Symfony\Component\Security\Core\Exception\BadCredentialsException;
class UserAuthenticationProviderTest extends \PHPUnit_Framework_TestCase
@@ -172,6 +173,11 @@ class UserAuthenticationProviderTest extends \PHPUnit_Framework_TestCase
->will($this->returnValue('foo'))
;
+ $token->expects($this->once())
+ ->method('getRoles')
+ ->will($this->returnValue(array()))
+ ;
+
$authToken = $provider->authenticate($token);
$this->assertInstanceOf('Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken', $authToken);
@@ -181,9 +187,45 @@ class UserAuthenticationProviderTest extends \PHPUnit_Framework_TestCase
$this->assertEquals(array('foo' => 'bar'), $authToken->getAttributes(), '->authenticate() copies token attributes');
}
+ public function testAuthenticateWithPreservingRoleSwitchUserRole()
+ {
+ $user = $this->getMock('Symfony\Component\Security\Core\User\UserInterface');
+ $user->expects($this->once())
+ ->method('getRoles')
+ ->will($this->returnValue(array('ROLE_FOO')))
+ ;
+
+ $provider = $this->getProvider();
+ $provider->expects($this->once())
+ ->method('retrieveUser')
+ ->will($this->returnValue($user))
+ ;
+
+ $token = $this->getSupportedToken();
+ $token->expects($this->once())
+ ->method('getCredentials')
+ ->will($this->returnValue('foo'))
+ ;
+
+ $switchUserRole = new SwitchUserRole('foo', $this->getMock('Symfony\Component\Security\Core\Authentication\Token\TokenInterface'));
+ $token->expects($this->once())
+ ->method('getRoles')
+ ->will($this->returnValue(array($switchUserRole)))
+ ;
+
+ $authToken = $provider->authenticate($token);
+
+ $this->assertInstanceOf('Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken', $authToken);
+ $this->assertSame($user, $authToken->getUser());
+ $this->assertContains(new Role('ROLE_FOO'), $authToken->getRoles(), '', false, false);
+ $this->assertContains($switchUserRole, $authToken->getRoles());
+ $this->assertEquals('foo', $authToken->getCredentials());
+ $this->assertEquals(array('foo' => 'bar'), $authToken->getAttributes(), '->authenticate() copies token attributes');
+ }
+
protected function getSupportedToken()
{
- $mock = $this->getMock('Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken', array('getCredentials', 'getProviderKey'), array(), '', false);
+ $mock = $this->getMock('Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken', array('getCredentials', 'getProviderKey', 'getRoles'), array(), '', false);
$mock
->expects($this->any())
->method('getProviderKey')