Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 4db12a3

Browse files
Merge branch '5.4' into 6.0
* 5.4: Remove deprecated User from serialized test fixture
2 parents 5c73e8d + 14540c1 commit 4db12a3

File tree

4 files changed

+69
-0
lines changed

4 files changed

+69
-0
lines changed
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
<?php
2+
3+
namespace Symfony\Component\Security\Core\Tests\Authentication\Token\Fixtures;
4+
5+
use Symfony\Component\Security\Core\User\UserInterface;
6+
7+
final class CustomUser implements UserInterface
8+
{
9+
/** @var string */
10+
private $username;
11+
/** @var array */
12+
private $roles;
13+
14+
public function __construct(string $username, array $roles)
15+
{
16+
$this->username = $username;
17+
$this->roles = $roles;
18+
}
19+
20+
public function getUsername(): string
21+
{
22+
return $this->username;
23+
}
24+
25+
public function getUserIdentifier(): string
26+
{
27+
return $this->username;
28+
}
29+
30+
public function getRoles(): array
31+
{
32+
return $this->roles;
33+
}
34+
35+
public function getPassword(): ?string
36+
{
37+
return null;
38+
}
39+
40+
public function getSalt(): ?string
41+
{
42+
return null;
43+
}
44+
45+
public function eraseCredentials(): void
46+
{
47+
}
48+
}

src/Symfony/Component/Security/Core/Tests/Authentication/Token/SwitchUserTokenTest.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use PHPUnit\Framework\TestCase;
1515
use Symfony\Component\Security\Core\Authentication\Token\SwitchUserToken;
1616
use Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken;
17+
use Symfony\Component\Security\Core\Tests\Authentication\Token\Fixtures\CustomUser;
1718
use Symfony\Component\Security\Core\User\UserInterface;
1819

1920
class SwitchUserTokenTest extends TestCase
@@ -90,13 +91,33 @@ public function testSerializeNullImpersonateUrl()
9091
$this->assertNull($unserializedToken->getOriginatedFromUri());
9192
}
9293

94+
/**
95+
* Tests if an old version of SwitchUserToken can still be unserialized.
96+
*
97+
* The fixture was generated by running the following code with Symfony 4.4 and PHP 7.2.
98+
*
99+
* serialize(
100+
* new SwitchUserToken(
101+
* new CustomUser('john', ['ROLE_USER']),
102+
* ['foo' => 'bar'],
103+
* 'main', ['ROLE_USER'],
104+
* new UsernamePasswordToken(
105+
* new CustomUser('jane', ['ROLE_USER']),
106+
* ['foo' => 'bar'],
107+
* 'main',
108+
* ['ROLE_USER']
109+
* )
110+
* )
111+
* )
112+
*/
93113
public function testUnserializeOldToken()
94114
{
95115
/** @var SwitchUserToken $token */
96116
$token = unserialize(file_get_contents(__DIR__.'/Fixtures/switch-user-token-4.4.txt'));
97117

98118
self::assertInstanceOf(SwitchUserToken::class, $token);
99119
self::assertInstanceOf(UsernamePasswordToken::class, $token->getOriginalToken());
120+
self::assertInstanceOf(CustomUser::class, $token->getUser());
100121
self::assertSame('john', $token->getUserIdentifier());
101122
self::assertSame(['foo' => 'bar'], $token->getCredentials());
102123
self::assertSame('main', $token->getFirewallName());

0 commit comments

Comments
 (0)