Skip to content

Commit 0b8b145

Browse files
Merge branch '6.4' into 7.0
* 6.4: Update FileProfilerStorage.php [Security] Allow custom scheme to be used as redirection URIs [Validator] Do not mock metadata factory on debug command tests [HttpKernel][WebProfilerBundle] Fix search feature [ErrorHandler] Avoid compile crash while trying to find candidate when a class is not found [Security] Make `PersistentToken` immutable and tell `TokenProviderInterface::updateToken()` implementations should accept `DateTimeInterface` do not listen to signals if the pcntl extension is missing [DependencyInjection] Improve reporting named autowiring aliases [DependencyInjection] Make better use of memory and CPU during auto-discovery update Intl component to take into account B-variant when converting Alpha3 to Alpha2. fixing issue with Darwin. [VarDumper] Fix dumping `ArrayObject` with `DumpDataCollector` [VarDumper] Add tests to demonstrate a bug when dumping ArrayObject with full stack fmk [DebugBundle][FrameworkBundle] Fix using the framework without the Console component [FrameworkBundle] Add missing monolog channel tag to the `messenger:failed:retry` command fetch all known ChoiceType values at once [RateLimiter] fix incorrect retryAfter of FixedWindow Fix Finder phpdoc [TwigBundle] Allow omitting the `autoescape_service_method` option when `autoescape_service` is set to an invokable service id [PropertyAccess] Auto-cast from/to DateTime/Immutable when appropriate
2 parents ade1448 + 9eb649d commit 0b8b145

File tree

8 files changed

+36
-17
lines changed

8 files changed

+36
-17
lines changed

Authentication/RememberMe/InMemoryTokenProvider.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
*
1919
* @author Johannes M. Schmitt <[email protected]>
2020
*/
21-
class InMemoryTokenProvider implements TokenProviderInterface
21+
final class InMemoryTokenProvider implements TokenProviderInterface
2222
{
2323
private array $tokens = [];
2424

@@ -31,7 +31,7 @@ public function loadTokenBySeries(string $series): PersistentTokenInterface
3131
return $this->tokens[$series];
3232
}
3333

34-
public function updateToken(string $series, #[\SensitiveParameter] string $tokenValue, \DateTime $lastUsed): void
34+
public function updateToken(string $series, #[\SensitiveParameter] string $tokenValue, \DateTimeInterface $lastUsed)
3535
{
3636
if (!isset($this->tokens[$series])) {
3737
throw new TokenNotFoundException('No token found.');

Authentication/RememberMe/PersistentToken.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ final class PersistentToken implements PersistentTokenInterface
2222
private string $userIdentifier;
2323
private string $series;
2424
private string $tokenValue;
25-
private \DateTime $lastUsed;
25+
private \DateTimeImmutable $lastUsed;
2626

27-
public function __construct(string $class, string $userIdentifier, string $series, #[\SensitiveParameter] string $tokenValue, \DateTime $lastUsed)
27+
public function __construct(string $class, string $userIdentifier, string $series, #[\SensitiveParameter] string $tokenValue, \DateTimeInterface $lastUsed)
2828
{
2929
if (empty($class)) {
3030
throw new \InvalidArgumentException('$class must not be empty.');
@@ -43,7 +43,7 @@ public function __construct(string $class, string $userIdentifier, string $serie
4343
$this->userIdentifier = $userIdentifier;
4444
$this->series = $series;
4545
$this->tokenValue = $tokenValue;
46-
$this->lastUsed = $lastUsed;
46+
$this->lastUsed = \DateTimeImmutable::createFromInterface($lastUsed);
4747
}
4848

4949
public function getClass(): string
@@ -68,6 +68,6 @@ public function getTokenValue(): string
6868

6969
public function getLastUsed(): \DateTime
7070
{
71-
return $this->lastUsed;
71+
return \DateTime::createFromImmutable($this->lastUsed);
7272
}
7373
}

Authentication/RememberMe/PersistentTokenInterface.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ public function getTokenValue(): string;
3636

3737
/**
3838
* Returns the time the token was last used.
39+
*
40+
* Each call SHOULD return a new distinct DateTime instance.
3941
*/
4042
public function getLastUsed(): \DateTime;
4143

Authentication/RememberMe/TokenProviderInterface.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ public function deleteTokenBySeries(string $series);
3939
/**
4040
* Updates the token according to this data.
4141
*
42+
* @param \DateTimeInterface $lastUsed Accepting only DateTime is deprecated since Symfony 6.4
43+
*
4244
* @return void
4345
*
4446
* @throws TokenNotFoundException if the token is not found

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,19 @@
11
CHANGELOG
22
=========
33

4+
45
7.0
56
---
67

78
* Remove the `Security` class, use `Symfony\Bundle\SecurityBundle\Security` instead
89
* Require explicit argument when calling `TokenStorage::setToken()`
910

11+
6.4
12+
---
13+
14+
* Make `PersistentToken` immutable
15+
* Deprecate accepting only `DateTime` for `TokenProviderInterface::updateToken()`, use `DateTimeInterface` instead
16+
1017
6.3
1118
---
1219

Tests/Authentication/RememberMe/CacheTokenVerifierTest.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,23 +21,23 @@ class CacheTokenVerifierTest extends TestCase
2121
public function testVerifyCurrentToken()
2222
{
2323
$verifier = new CacheTokenVerifier(new ArrayAdapter());
24-
$token = new PersistentToken('class', 'user', 'series1@special:chars=/', 'value', new \DateTime());
24+
$token = new PersistentToken('class', 'user', 'series1@special:chars=/', 'value', new \DateTimeImmutable());
2525
$this->assertTrue($verifier->verifyToken($token, 'value'));
2626
}
2727

2828
public function testVerifyFailsInvalidToken()
2929
{
3030
$verifier = new CacheTokenVerifier(new ArrayAdapter());
31-
$token = new PersistentToken('class', 'user', 'series1@special:chars=/', 'value', new \DateTime());
31+
$token = new PersistentToken('class', 'user', 'series1@special:chars=/', 'value', new \DateTimeImmutable());
3232
$this->assertFalse($verifier->verifyToken($token, 'wrong-value'));
3333
}
3434

3535
public function testVerifyOutdatedToken()
3636
{
3737
$verifier = new CacheTokenVerifier(new ArrayAdapter());
38-
$outdatedToken = new PersistentToken('class', 'user', 'series1@special:chars=/', 'value', new \DateTime());
39-
$newToken = new PersistentToken('class', 'user', 'series1@special:chars=/', 'newvalue', new \DateTime());
40-
$verifier->updateExistingToken($outdatedToken, 'newvalue', new \DateTime());
38+
$outdatedToken = new PersistentToken('class', 'user', 'series1@special:chars=/', 'value', new \DateTimeImmutable());
39+
$newToken = new PersistentToken('class', 'user', 'series1@special:chars=/', 'newvalue', new \DateTimeImmutable());
40+
$verifier->updateExistingToken($outdatedToken, 'newvalue', new \DateTimeImmutable());
4141
$this->assertTrue($verifier->verifyToken($newToken, 'value'));
4242
}
4343
}

Tests/Authentication/RememberMe/InMemoryTokenProviderTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public function testCreateNewToken()
2222
{
2323
$provider = new InMemoryTokenProvider();
2424

25-
$token = new PersistentToken('foo', 'foo', 'foo', 'foo', new \DateTime());
25+
$token = new PersistentToken('foo', 'foo', 'foo', 'foo', new \DateTimeImmutable());
2626
$provider->createNewToken($token);
2727

2828
$this->assertSame($provider->loadTokenBySeries('foo'), $token);
@@ -39,21 +39,21 @@ public function testUpdateToken()
3939
{
4040
$provider = new InMemoryTokenProvider();
4141

42-
$token = new PersistentToken('foo', 'foo', 'foo', 'foo', new \DateTime());
42+
$token = new PersistentToken('foo', 'foo', 'foo', 'foo', new \DateTimeImmutable());
4343
$provider->createNewToken($token);
4444
$provider->updateToken('foo', 'newFoo', $lastUsed = new \DateTime());
4545
$token = $provider->loadTokenBySeries('foo');
4646

4747
$this->assertEquals('newFoo', $token->getTokenValue());
48-
$this->assertSame($token->getLastUsed(), $lastUsed);
48+
$this->assertEquals($token->getLastUsed(), $lastUsed);
4949
}
5050

5151
public function testDeleteToken()
5252
{
5353
$this->expectException(TokenNotFoundException::class);
5454
$provider = new InMemoryTokenProvider();
5555

56-
$token = new PersistentToken('foo', 'foo', 'foo', 'foo', new \DateTime());
56+
$token = new PersistentToken('foo', 'foo', 'foo', 'foo', new \DateTimeImmutable());
5757
$provider->createNewToken($token);
5858
$provider->deleteTokenBySeries('foo');
5959
$provider->loadTokenBySeries('foo');

Tests/Authentication/RememberMe/PersistentTokenTest.php

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,21 @@ class PersistentTokenTest extends TestCase
1818
{
1919
public function testConstructor()
2020
{
21-
$lastUsed = new \DateTime();
21+
$lastUsed = new \DateTimeImmutable();
2222
$token = new PersistentToken('fooclass', 'fooname', 'fooseries', 'footokenvalue', $lastUsed);
2323

2424
$this->assertEquals('fooclass', $token->getClass());
2525
$this->assertEquals('fooname', $token->getUserIdentifier());
2626
$this->assertEquals('fooseries', $token->getSeries());
2727
$this->assertEquals('footokenvalue', $token->getTokenValue());
28-
$this->assertSame($lastUsed, $token->getLastUsed());
28+
$this->assertEquals($lastUsed, $token->getLastUsed());
29+
}
30+
31+
public function testDateTime()
32+
{
33+
$lastUsed = new \DateTime();
34+
$token = new PersistentToken('fooclass', 'fooname', 'fooseries', 'footokenvalue', $lastUsed);
35+
36+
$this->assertEquals($lastUsed, $token->getLastUsed());
2937
}
3038
}

0 commit comments

Comments
 (0)