test(auth): add unit test coverage for JWT issuance, decoding and AuthUser extractor (#43) - #70
Open
ghzhost wants to merge 1 commit into
Open
test(auth): add unit test coverage for JWT issuance, decoding and AuthUser extractor (#43)#70ghzhost wants to merge 1 commit into
ghzhost wants to merge 1 commit into
Conversation
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary of Changes
Adds comprehensive unit test coverage for
src/middleware/auth.rscovering JWT issuance, validation/decoding, algorithm enforcement, expiry behavior, signature verification, and request extractor edge cases, addressing #43.Tests Added
round_trip_issue_and_decode_recovers_claims:issue_jwtfollowed bydecode_jwtsuccessfully recovers originalsub(user UUID),email, and correct timestamp claims (exp - iat == 24h).decode_fails_with_invalid_token_when_secret_mismatches:AppError::InvalidToken.decode_specifically_fails_with_token_expired_when_past_exp:expiry_hours: -1) maps specifically toAppError::TokenExpired, verifying the distinction fromInvalidToken.decode_fails_when_signature_is_tampered:AppError::InvalidToken.decode_fails_when_algorithm_is_different:HS256(such asHS384) are rejected asAppError::InvalidToken.extractor_rejects_missing_authorization_header:AuthUser::from_request_partsreturnsAppError::Unauthorizedwhen theAuthorizationheader is missing.extractor_rejects_malformed_auth_scheme:AuthUser::from_request_partsreturnsAppError::Unauthorizedfor non-Bearer schemes (e.g.Basic ...).extractor_rejects_non_uuid_sub:AuthUser::from_request_partsrejects tokens wheresubis not a valid UUID withAppError::InvalidToken.extractor_succeeds_with_valid_bearer_token:AuthUserstruct with populateduser_id,email, andclaims.Fixes #43