Skip to content

Commit af92066

Browse files
committed
Add tests
1 parent ab5303a commit af92066

File tree

3 files changed

+47
-0
lines changed

3 files changed

+47
-0
lines changed

src/Symfony/Bridge/Doctrine/Tests/Security/RememberMe/DoctrineTokenProviderTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ public function testVerifyOutdatedTokenAfterParallelRequest()
6969

7070
// new request comes in requiring remember-me auth, which updates the token
7171
$provider->updateExistingToken($token, $newValue, new \DateTime('-5 seconds'));
72+
$provider->updateToken($token, $newValue, new \DateTime('-5 seconds'));
7273

7374
// parallel request comes in with the old remember-me cookie and session, which also requires reauth
7475
$token = $provider->loadTokenBySeries($series);
@@ -93,6 +94,7 @@ public function testVerifyOutdatedTokenAfterParallelRequestFailsAfter60Seconds()
9394

9495
// new request comes in requiring remember-me auth, which updates the token
9596
$provider->updateExistingToken($token, $newValue, new \DateTime('-61 seconds'));
97+
$provider->updateToken($token, $newValue, new \DateTime('-5 seconds'));
9698

9799
// parallel request comes in with the old remember-me cookie and session, which also requires reauth
98100
$token = $provider->loadTokenBySeries($series);
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\Security\Core\Tests\Authentication\RememberMe;
13+
14+
use PHPUnit\Framework\TestCase;
15+
use Symfony\Component\Cache\Adapter\ArrayAdapter;
16+
use Symfony\Component\Security\Core\Authentication\RememberMe\CacheTokenVerifier;
17+
use Symfony\Component\Security\Core\Authentication\RememberMe\PersistentToken;
18+
19+
class CacheTokenVerifierTest extends TestCase
20+
{
21+
public function testVerifyCurrentToken()
22+
{
23+
$verifier = new CacheTokenVerifier(new ArrayAdapter());
24+
$token = new PersistentToken('class', 'user', 'series1', 'value', new \DateTime());
25+
$this->assertTrue($verifier->verifyToken($token, 'value'));
26+
}
27+
28+
public function testVerifyFailsInvalidToken()
29+
{
30+
$verifier = new CacheTokenVerifier(new ArrayAdapter());
31+
$token = new PersistentToken('class', 'user', 'series1', 'value', new \DateTime());
32+
$this->assertFalse($verifier->verifyToken($token, 'wrong-value'));
33+
}
34+
35+
public function testVerifyOutdatedToken()
36+
{
37+
$verifier = new CacheTokenVerifier(new ArrayAdapter());
38+
$outdatedToken = new PersistentToken('class', 'user', 'series1', 'value', new \DateTime());
39+
$newToken = new PersistentToken('class', 'user', 'series1', 'newvalue', new \DateTime());
40+
$verifier->updateExistingToken($outdatedToken, 'newvalue', new \DateTime());
41+
$this->assertTrue($verifier->verifyToken($newToken, 'value'));
42+
}
43+
}

src/Symfony/Component/Security/Core/composer.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525
},
2626
"require-dev": {
2727
"psr/container": "^1.0|^2.0",
28+
"psr/cache": "^1.0|^2.0|^3.0",
29+
"symfony/cache": "^4.4|^5.0",
2830
"symfony/event-dispatcher": "^4.4|^5.0",
2931
"symfony/expression-language": "^4.4|^5.0",
3032
"symfony/http-foundation": "^5.3",

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy