Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 78d5802

Browse filesBrowse files
committed
add tests
1 parent 9b2e7f3 commit 78d5802
Copy full SHA for 78d5802

File tree

Expand file treeCollapse file tree

1 file changed

+49
-0
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+49
-0
lines changed

‎src/Symfony/Component/HttpFoundation/Tests/UriSignerTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/HttpFoundation/Tests/UriSignerTest.php
+49Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,10 @@
1212
namespace Symfony\Component\HttpFoundation\Tests;
1313

1414
use PHPUnit\Framework\TestCase;
15+
use Symfony\Component\HttpFoundation\Exception\ExpiredSignedUriException;
1516
use Symfony\Component\HttpFoundation\Exception\LogicException;
17+
use Symfony\Component\HttpFoundation\Exception\UnSignedUriException;
18+
use Symfony\Component\HttpFoundation\Exception\UnverifiedSignedUriException;
1619
use Symfony\Component\HttpFoundation\Request;
1720
use Symfony\Component\HttpFoundation\UriSigner;
1821

@@ -204,4 +207,50 @@ public function testNonUrlSafeBase64()
204207
$signer = new UriSigner('foobar');
205208
$this->assertTrue($signer->check('http://example.com/foo?_hash=rIOcC%2FF3DoEGo%2FvnESjSp7uU9zA9S%2F%2BOLhxgMexoPUM%3D&baz=bay&foo=bar'));
206209
}
210+
211+
public function testVerifyUnSignedUri()
212+
{
213+
$signer = new UriSigner('foobar');
214+
$uri = 'http://example.com/foo';
215+
216+
try {
217+
$signer->verify($uri);
218+
219+
$this->fail('Exception not thrown.');
220+
} catch (UnSignedUriException $e) {
221+
$this->assertSame('The URI is not signed.', $e->getMessage());
222+
$this->assertSame($uri, $e->uri);
223+
}
224+
}
225+
226+
public function testVerifyUnverifiedUri()
227+
{
228+
$signer = new UriSigner('foobar');
229+
$uri = 'http://example.com/foo?_hash=invalid';
230+
231+
try {
232+
$signer->verify($uri);
233+
234+
$this->fail('Exception not thrown.');
235+
} catch (UnverifiedSignedUriException $e) {
236+
$this->assertSame('The URI signature is invalid.', $e->getMessage());
237+
$this->assertSame($uri, $e->uri);
238+
}
239+
}
240+
241+
public function testVerifyExpiredUri()
242+
{
243+
$signer = new UriSigner('foobar');
244+
$uri = $signer->sign('http://example.com/foo', 123456);
245+
246+
try {
247+
$signer->verify($uri);
248+
249+
$this->fail('Exception not thrown.');
250+
} catch (ExpiredSignedUriException $e) {
251+
$this->assertSame('The URI has expired.', $e->getMessage());
252+
$this->assertSame($uri, $e->uri);
253+
$this->assertSame(123456, $e->expiredAt->getTimestamp());
254+
}
255+
}
207256
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.