Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Throw InvalidTokenException instead of RuntimeException when parsing malformed token (fix #438) #439

Merged
merged 1 commit into from
Aug 6, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Helpers/Tokens/SignatureVerifier.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ final public function verifyAndDecode(string $token) : Token
{
try {
$parsedToken = $this->parser->parse($token);
} catch (InvalidArgumentException $e) {
} catch (InvalidArgumentException | \RuntimeException $e) {
throw new InvalidTokenException( 'ID token could not be decoded' );
}

Expand Down
12 changes: 12 additions & 0 deletions tests/Helpers/Tokens/AsymmetricVerifierTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,18 @@ public function testThatTokenClaimsAreReturned()
$this->assertEquals('__test_sub__', $decodedToken->getClaim('sub'));
}

public function testThatMalformedTokenFails()
{
$rsa_keys = self::getRsaKeys();
$verifier = new AsymmetricVerifier( [ '__test_kid__' => $rsa_keys['public'] ] );
$token = 'a'.(string) self::getToken($rsa_keys['private']);

$this->expectException(InvalidTokenException::class);
$this->expectExceptionMessage('ID token could not be decoded');

$verifier->verifyAndDecode( $token );
}

/*
* Helper methods
*/
Expand Down