summaryrefslogtreecommitdiffstats
path: root/Tests/Core/Authentication/Token/AbstractTokenTest.php
diff options
context:
space:
mode:
authorDavid de Boer <david@ddeboer.nl>2013-12-17 21:46:42 +0100
committerFabien Potencier <fabien.potencier@gmail.com>2013-12-23 16:45:07 +0100
commitb1ad1eb1928ce46962d9c81ffcfa1b11f6dfc476 (patch)
treefe81509cec8a7e338b9c13d38c4719fd7b99e351 /Tests/Core/Authentication/Token/AbstractTokenTest.php
parent5a8f9cd093782a8827fdccd2f2ed1ff790cb35a3 (diff)
downloadsymfony-security-origin/2.2.zip
symfony-security-origin/2.2.tar.gz
symfony-security-origin/2.2.tar.bz2
[Security] Fix parent serialization of user objectorigin/2.2
Diffstat (limited to 'Tests/Core/Authentication/Token/AbstractTokenTest.php')
-rw-r--r--Tests/Core/Authentication/Token/AbstractTokenTest.php41
1 files changed, 41 insertions, 0 deletions
diff --git a/Tests/Core/Authentication/Token/AbstractTokenTest.php b/Tests/Core/Authentication/Token/AbstractTokenTest.php
index 4df6068..13a81db 100644
--- a/Tests/Core/Authentication/Token/AbstractTokenTest.php
+++ b/Tests/Core/Authentication/Token/AbstractTokenTest.php
@@ -11,7 +11,9 @@
namespace Symfony\Component\Security\Tests\Core\Authentication\Token;
+use Symfony\Component\Security\Core\Authentication\Token\AbstractToken;
use Symfony\Component\Security\Core\Role\Role;
+use Symfony\Component\Security\Core\Role\SwitchUserRole;
class TestUser
{
@@ -28,6 +30,31 @@ class TestUser
}
}
+class ConcreteToken extends AbstractToken
+{
+ private $credentials = 'credentials_value';
+
+ public function __construct($user, array $roles = array())
+ {
+ parent::__construct($roles);
+
+ $this->setUser($user);
+ }
+
+ public function serialize()
+ {
+ return serialize(array($this->credentials, parent::serialize()));
+ }
+
+ public function unserialize($serialized)
+ {
+ list($this->credentials, $parentStr) = unserialize($serialized);
+ parent::unserialize($parentStr);
+ }
+
+ public function getCredentials() {}
+}
+
class AbstractTokenTest extends \PHPUnit_Framework_TestCase
{
public function testGetUsername()
@@ -71,6 +98,20 @@ class AbstractTokenTest extends \PHPUnit_Framework_TestCase
$this->assertEquals($token->getAttributes(), $uToken->getAttributes());
}
+ public function testSerializeParent()
+ {
+ $user = new TestUser('fabien');
+ $token = new ConcreteToken($user, array('ROLE_FOO'));
+
+ $parentToken = new ConcreteToken($user, array(new SwitchUserRole('ROLE_PREVIOUS', $token)));
+ $uToken = unserialize(serialize($parentToken));
+
+ $this->assertEquals(
+ current($parentToken->getRoles())->getSource()->getUser(),
+ current($uToken->getRoles())->getSource()->getUser()
+ );
+ }
+
/**
* @covers Symfony\Component\Security\Core\Authentication\Token\AbstractToken::__construct
*/