-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Security] Fixed roles serialization on token from user object #19778
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,6 +14,7 @@ | |
use Symfony\Component\Security\Core\Authentication\Token\AbstractToken; | ||
use Symfony\Component\Security\Core\Role\Role; | ||
use Symfony\Component\Security\Core\Role\SwitchUserRole; | ||
use Symfony\Component\Security\Core\User\User; | ||
|
||
class TestUser | ||
{ | ||
|
@@ -87,7 +88,7 @@ public function testEraseCredentials() | |
|
||
public function testSerialize() | ||
{ | ||
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. What about $user = new User('name', 'password', array('ROLE_FOO', new Role('ROLE_BAR')));
$token = $this->getToken(array('ROLE_FOO2', new Role('ROLE_BAR2')));
$token->setUser($user);
// serialize/unserialize
$this->assertEquals($token->getUser(), $uToken->getUser()); Fully covers |
||
$token = $this->getToken(array('ROLE_FOO')); | ||
$token = $this->getToken(array('ROLE_FOO', new Role('ROLE_BAR'))); | ||
$token->setAttributes(array('foo' => 'bar')); | ||
|
||
$uToken = unserialize(serialize($token)); | ||
|
@@ -96,6 +97,19 @@ public function testSerialize() | |
$this->assertEquals($token->getAttributes(), $uToken->getAttributes()); | ||
} | ||
|
||
public function testSerializeWithRoleObjects() | ||
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. Better update 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. @ro0NL I agree with you on this comment, I will remove all of these tests and just let one into 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. This is done, PR is up-to-date with comments. 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. Why not update 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. @ro0NL I've updated the 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. Your change is covered by the test above now.
Im not sure how that relates to your change... what about adding a 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. @ro0NL Roles are passed in the |
||
{ | ||
$user = new User('name', 'password', array(new Role('ROLE_FOO'), new Role('ROLE_BAR'))); | ||
$token = new ConcreteToken($user, $user->getRoles()); | ||
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. Point is; passing roles here is effectively the same as passing in roles via |
||
|
||
$serialized = serialize($token); | ||
$unserialized = unserialize($serialized); | ||
|
||
$roles = $unserialized->getRoles(); | ||
|
||
$this->assertEquals($roles, $user->getRoles()); | ||
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. Same test as above, ie. |
||
} | ||
|
||
public function testSerializeParent() | ||
{ | ||
$user = new TestUser('fabien'); | ||
|
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.
Is this related?
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.
@ro0NL Yes, it is related, test failed without that change because we checked an exact reference. Check has to be changed like the line just before.