fix serialization workaround in CustomUserMessageAuthenticationException

This commit is contained in:
renanbr 2019-01-30 16:28:03 +01:00
parent 46edcee92a
commit 542e9e29b9
2 changed files with 30 additions and 1 deletions

View File

@ -60,7 +60,7 @@ class CustomUserMessageAuthenticationException extends AuthenticationException
*/
public function serialize()
{
return serialize([parent::serialize(true), $this->messageKey, $this->messageData]);
$serialized = [parent::serialize(true), $this->messageKey, $this->messageData];
return $this->doSerialize($serialized, \func_num_args() ? \func_get_arg(0) : null);
}

View File

@ -15,6 +15,21 @@ use PHPUnit\Framework\TestCase;
use Symfony\Component\Security\Core\Authentication\Token\AnonymousToken;
use Symfony\Component\Security\Core\Exception\CustomUserMessageAuthenticationException;
class ChildCustomUserMessageAuthenticationException extends CustomUserMessageAuthenticationException
{
public function serialize()
{
return serialize([$this->childMember, parent::serialize()]);
}
public function unserialize($str)
{
list($this->childMember, $parentData) = unserialize($str);
parent::unserialize($parentData);
}
}
class CustomUserMessageAuthenticationExceptionTest extends TestCase
{
public function testConstructWithSAfeMessage()
@ -39,4 +54,18 @@ class CustomUserMessageAuthenticationExceptionTest extends TestCase
$this->assertEquals($token, $processed->getMessageData()['token']);
$this->assertSame($processed->getToken(), $processed->getMessageData()['token']);
}
public function testSharedSerializedDataFromChild()
{
$token = new AnonymousToken('foo', 'bar');
$exception = new ChildCustomUserMessageAuthenticationException();
$exception->childMember = $token;
$exception->setToken($token);
$processed = unserialize(serialize($exception));
$this->assertEquals($token, $processed->childMember);
$this->assertEquals($token, $processed->getToken());
$this->assertSame($processed->getToken(), $processed->childMember);
}
}