Skip to content

Commit

Permalink
Add signing and validation tests for special and reserved query param…
Browse files Browse the repository at this point in the history
…eters.
  • Loading branch information
Tibor Rac committed Dec 6, 2023
1 parent fb8d006 commit 730d254
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 0 deletions.
24 changes: 24 additions & 0 deletions tests/Md5UrlSignerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,3 +83,27 @@
expect($this->urlSigner->validate($signedUsingCustomKey, 'custom-key'))->toBeTrue();
expect($this->urlSigner->validate($signedUsingCustomKey, 'wrong-custom-key'))->toBeFalse();
});

it('can sign url which has special characters in the query parameters', function ($url) {
$expiration = 100;

$signedUrl = $this->urlSigner->sign($url, $expiration);

expect($this->urlSigner->validate($signedUrl))->toBeTrue();
})->with([
['https://myapp.com/?foo=bar baz'],
['https://myapp.com/?foo=bar%20baz'],
['https://myapp.com/?foo=bar@baz.com'],
]);

it('can sign url which has reserved query parameters', function ($url) {
$expiration = 100;

$signedUrl = $this->urlSigner->sign($url, $expiration);

expect($this->urlSigner->validate($signedUrl))->toBeTrue();
})->with([
['https://myapp.com/?foo=bar&expires=100&signature=abc123'],
['https://myapp.com/?foo=bar&expires=100'],
['https://myapp.com/?foo=bar&signature=abc123'],
]);
24 changes: 24 additions & 0 deletions tests/Sha256UrlSignerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,3 +92,27 @@
expect($this->urlSigner->validate($signedUsingCustomKey, 'custom-key'))->toBeTrue();
expect($this->urlSigner->validate($signedUsingCustomKey, 'wrong-custom-key'))->toBeFalse();
});

it('can sign url which has special characters in the query parameters', function ($url) {
$expiration = 100;

$signedUrl = $this->urlSigner->sign($url, $expiration);

expect($this->urlSigner->validate($signedUrl))->toBeTrue();
})->with([
['https://myapp.com/?foo=bar baz'],
['https://myapp.com/?foo=bar%20baz'],
['https://myapp.com/?foo=bar@baz.com'],
]);

it('can sign url which has reserved query parameters', function ($url) {
$expiration = 100;

$signedUrl = $this->urlSigner->sign($url, $expiration);

expect($this->urlSigner->validate($signedUrl))->toBeTrue();
})->with([
['https://myapp.com/?foo=bar&expires=100&signature=abc123'],
['https://myapp.com/?foo=bar&expires=100'],
['https://myapp.com/?foo=bar&signature=abc123'],
]);

0 comments on commit 730d254

Please sign in to comment.