|
12 | 12 | namespace Symfony\Component\HttpFoundation\Tests;
|
13 | 13 |
|
14 | 14 | use PHPUnit\Framework\TestCase;
|
| 15 | +use Symfony\Component\Clock\MockClock; |
15 | 16 | use Symfony\Component\HttpFoundation\Exception\LogicException;
|
16 | 17 | use Symfony\Component\HttpFoundation\Request;
|
17 | 18 | use Symfony\Component\HttpFoundation\UriSigner;
|
@@ -199,6 +200,29 @@ public function testCheckWithUriExpiration()
|
199 | 200 | $this->assertFalse($signer->check($relativeUriFromNow3));
|
200 | 201 | }
|
201 | 202 |
|
| 203 | + public function testCheckWithUriExpirationWithClock() |
| 204 | + { |
| 205 | + $clock = new MockClock(); |
| 206 | + $signer = new UriSigner('foobar', clock: $clock); |
| 207 | + |
| 208 | + $this->assertFalse($signer->check($signer->sign('http://example.com/foo', new \DateTimeImmutable('2000-01-01 00:00:00')))); |
| 209 | + $this->assertFalse($signer->check($signer->sign('http://example.com/foo?foo=bar', new \DateTimeImmutable('2000-01-01 00:00:00')))); |
| 210 | + $this->assertFalse($signer->check($signer->sign('http://example.com/foo?foo=bar&0=integer', new \DateTimeImmutable('2000-01-01 00:00:00')))); |
| 211 | + |
| 212 | + $this->assertFalse($signer->check($signer->sign('http://example.com/foo', 1577836800))); // 2000-01-01 |
| 213 | + $this->assertFalse($signer->check($signer->sign('http://example.com/foo?foo=bar', 1577836800))); // 2000-01-01 |
| 214 | + $this->assertFalse($signer->check($signer->sign('http://example.com/foo?foo=bar&0=integer', 1577836800))); // 2000-01-01 |
| 215 | + |
| 216 | + $relativeUriFromNow1 = $signer->sign('http://example.com/foo', new \DateInterval('PT3S')); |
| 217 | + $relativeUriFromNow2 = $signer->sign('http://example.com/foo?foo=bar', new \DateInterval('PT3S')); |
| 218 | + $relativeUriFromNow3 = $signer->sign('http://example.com/foo?foo=bar&0=integer', new \DateInterval('PT3S')); |
| 219 | + $clock->sleep(10); |
| 220 | + |
| 221 | + $this->assertFalse($signer->check($relativeUriFromNow1)); |
| 222 | + $this->assertFalse($signer->check($relativeUriFromNow2)); |
| 223 | + $this->assertFalse($signer->check($relativeUriFromNow3)); |
| 224 | + } |
| 225 | + |
202 | 226 | public function testNonUrlSafeBase64()
|
203 | 227 | {
|
204 | 228 | $signer = new UriSigner('foobar');
|
|
0 commit comments