-
Notifications
You must be signed in to change notification settings - Fork 377
Revamp error hierarchy #722
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
Merged
Merged
Changes from 10 commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
deb6d43
Revamp error hierarchy
anakinj de6d3fd
More specific exception assertions and specific error types
anakinj e2dac62
Deprecation comment
anakinj 4a0c991
Changelog entry
anakinj 5743c0e
React on copilot comments
anakinj 07491ef
Make specs test what they claim they are testing
anakinj 0f9aee7
Sharpen examples and changelog
anakinj be10522
Assert the specific error class in HMAC specs
anakinj 7a8a867
Remove EC fixture no longer used by any spec
anakinj a694655
Correct changelog note on what rescue JWT::DecodeError now catches
anakinj 50bb298
Raise EncodeError for every signing failure
anakinj ab0db89
Keep the claim predicates from raising on a malformed payload
anakinj ce59589
Merge branch 'main' into error-hierarchy-revamp
anakinj f33ed78
Keep JWT::DecodeError as a real class and split verification key errors
anakinj 1959028
Keep the error class lookup on one line
anakinj a297d0d
Make every unusable verification key a VerificationKeyError
anakinj 4cd6c03
Cover the verification key guards and document decoding failures
anakinj cd80838
Target the next release at 3.3.0
anakinj 241070f
Reject a public RS*/PS* signing key with a JWT error
anakinj 957dc73
Use the RSA public key fixture in the new sign specs
anakinj 318c649
Move the error hierarchy migration notes to UPGRADING.md
anakinj File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,57 +1,72 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| module JWT | ||
| # The base error class for all JWT errors. | ||
| class Error < StandardError; end | ||
|
|
||
| # The EncodeError class is raised when there is an error encoding a JWT. | ||
| class EncodeError < StandardError; end | ||
| class EncodeError < Error; end | ||
|
|
||
| # The DecodeError class is raised when there is an error decoding a JWT. | ||
| class DecodeError < StandardError; end | ||
| # The TokenError class is the base class for all errors related to token processing. | ||
| class TokenError < Error; end | ||
|
|
||
| # The VerificationError class is raised when there is an error verifying a JWT. | ||
| class VerificationError < DecodeError; end | ||
| # The MalformedTokenError class is raised when the token is structurally invalid. | ||
| class MalformedTokenError < TokenError; end | ||
|
|
||
| # The ExpiredSignature class is raised when the JWT signature has expired. | ||
| class ExpiredSignature < DecodeError; end | ||
| # The Base64DecodeError class is raised when there is an error decoding a Base64-encoded string. | ||
| class Base64DecodeError < MalformedTokenError; end | ||
|
|
||
| # The IncorrectAlgorithm class is raised when the JWT algorithm is incorrect. | ||
| class IncorrectAlgorithm < DecodeError; end | ||
| # The SignatureError class is the base class for signature and algorithm related errors. | ||
| class SignatureError < TokenError; end | ||
|
|
||
| # The ImmatureSignature class is raised when the JWT signature is immature. | ||
| class ImmatureSignature < DecodeError; end | ||
| # The VerificationError class is raised when there is an error verifying a JWT signature. | ||
| class VerificationError < SignatureError; end | ||
|
anakinj marked this conversation as resolved.
|
||
|
|
||
| # The InvalidIssuerError class is raised when the JWT issuer is invalid. | ||
| class InvalidIssuerError < DecodeError; end | ||
| # The IncorrectAlgorithm class is raised when the JWT algorithm is incorrect. | ||
| class IncorrectAlgorithm < SignatureError; end | ||
|
|
||
| # The UnsupportedEcdsaCurve class is raised when the ECDSA curve is unsupported. | ||
| class UnsupportedEcdsaCurve < IncorrectAlgorithm; end | ||
|
anakinj marked this conversation as resolved.
|
||
|
|
||
| # The ClaimValidationError class is the base class for all claim validation errors. | ||
| class ClaimValidationError < TokenError; end | ||
|
|
||
| # The ExpiredSignature class is raised when the JWT token has expired. | ||
| class ExpiredSignature < ClaimValidationError; end | ||
|
|
||
| # The ImmatureSignature class is raised when the JWT token is not yet valid (nbf). | ||
| class ImmatureSignature < ClaimValidationError; end | ||
|
|
||
| # The InvalidIssuerError class is raised when the JWT issuer is invalid. | ||
| class InvalidIssuerError < ClaimValidationError; end | ||
|
|
||
| # The InvalidIatError class is raised when the JWT issued at (iat) claim is invalid. | ||
| class InvalidIatError < DecodeError; end | ||
| class InvalidIatError < ClaimValidationError; end | ||
|
|
||
| # The InvalidAudError class is raised when the JWT audience (aud) claim is invalid. | ||
| class InvalidAudError < DecodeError; end | ||
| class InvalidAudError < ClaimValidationError; end | ||
|
|
||
| # The InvalidSubError class is raised when the JWT subject (sub) claim is invalid. | ||
| class InvalidSubError < DecodeError; end | ||
| class InvalidSubError < ClaimValidationError; end | ||
|
|
||
| # The InvalidCritError class is raised when the JWT crit header is invalid. | ||
| class InvalidCritError < DecodeError; end | ||
| class InvalidCritError < ClaimValidationError; end | ||
|
|
||
| # The InvalidJtiError class is raised when the JWT ID (jti) claim is invalid. | ||
| class InvalidJtiError < DecodeError; end | ||
| class InvalidJtiError < ClaimValidationError; end | ||
|
|
||
| # The InvalidPayload class is raised when the JWT payload is invalid. | ||
| class InvalidPayload < DecodeError; end | ||
| class InvalidPayload < ClaimValidationError; end | ||
|
|
||
| # The MissingRequiredClaim class is raised when a required claim is missing from the JWT. | ||
| class MissingRequiredClaim < DecodeError; end | ||
|
|
||
| # The Base64DecodeError class is raised when there is an error decoding a Base64-encoded string. | ||
| class Base64DecodeError < DecodeError; end | ||
| class MissingRequiredClaim < ClaimValidationError; end | ||
|
|
||
| # The JWKError class is raised when there is an error with the JSON Web Key (JWK). | ||
| class JWKError < DecodeError; end | ||
| class JWKError < Error; end | ||
|
|
||
| # Raised when a JWK uses a key type (kty) that this library does not support. | ||
| class UnsupportedKeyType < JWKError; end | ||
|
|
||
| # @deprecated Use {JWT::Error}, {JWT::TokenError}, or a more specific error class instead. | ||
| DecodeError = Error | ||
| end | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.