Skip to content

Commit a5e574b

Browse files
committed
Merge branch '2.7' into 2.8
* 2.7: removed test that does not test anything fixed tests #21809 [SecurityBundle] bugfix: if security provider's name contains upper cases then container didn't compile [Validator] fix URL validator to detect non supported chars according to RFC 3986 [Security] Fixed roles serialization on token from user object
2 parents bf9c7d6 + 5d4460c commit a5e574b

File tree

3 files changed

+17
-3
lines changed

3 files changed

+17
-3
lines changed

Authentication/Token/AbstractToken.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ public function serialize()
150150
array(
151151
is_object($this->user) ? clone $this->user : $this->user,
152152
$this->authenticated,
153-
$this->roles,
153+
array_map(function ($role) { return clone $role; }, $this->roles),
154154
$this->attributes,
155155
)
156156
);

Tests/Authentication/Provider/UserAuthenticationProviderTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ public function testAuthenticateWithPreservingRoleSwitchUserRole()
221221
$this->assertInstanceOf('Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken', $authToken);
222222
$this->assertSame($user, $authToken->getUser());
223223
$this->assertContains(new Role('ROLE_FOO'), $authToken->getRoles(), '', false, false);
224-
$this->assertContains($switchUserRole, $authToken->getRoles());
224+
$this->assertContains($switchUserRole, $authToken->getRoles(), '', false, false);
225225
$this->assertEquals('foo', $authToken->getCredentials());
226226
$this->assertEquals(array('foo' => 'bar'), $authToken->getAttributes(), '->authenticate() copies token attributes');
227227
}

Tests/Authentication/Token/AbstractTokenTest.php

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use Symfony\Component\Security\Core\Authentication\Token\AbstractToken;
1616
use Symfony\Component\Security\Core\Role\Role;
1717
use Symfony\Component\Security\Core\Role\SwitchUserRole;
18+
use Symfony\Component\Security\Core\User\User;
1819

1920
class TestUser
2021
{
@@ -89,7 +90,7 @@ public function testEraseCredentials()
8990

9091
public function testSerialize()
9192
{
92-
$token = $this->getToken(array('ROLE_FOO'));
93+
$token = $this->getToken(array('ROLE_FOO', new Role('ROLE_BAR')));
9394
$token->setAttributes(array('foo' => 'bar'));
9495

9596
$uToken = unserialize(serialize($token));
@@ -98,6 +99,19 @@ public function testSerialize()
9899
$this->assertEquals($token->getAttributes(), $uToken->getAttributes());
99100
}
100101

102+
public function testSerializeWithRoleObjects()
103+
{
104+
$user = new User('name', 'password', array(new Role('ROLE_FOO'), new Role('ROLE_BAR')));
105+
$token = new ConcreteToken($user, $user->getRoles());
106+
107+
$serialized = serialize($token);
108+
$unserialized = unserialize($serialized);
109+
110+
$roles = $unserialized->getRoles();
111+
112+
$this->assertEquals($roles, $user->getRoles());
113+
}
114+
101115
public function testSerializeParent()
102116
{
103117
$user = new TestUser('fabien');

0 commit comments

Comments
 (0)