Skip to content

test(axum): cover JWT claim fallbacks and missing-context rejection#753

Merged
EffortlessSteven merged 1 commit into
mainfrom
claude/coverage-axum-fallbacks-OA2NV
May 17, 2026
Merged

test(axum): cover JWT claim fallbacks and missing-context rejection#753
EffortlessSteven merged 1 commit into
mainfrom
claude/coverage-axum-fallbacks-OA2NV

Conversation

@EffortlessSteven

Copy link
Copy Markdown
Member

Summary

Adds 4 tests in crates/uselesskey-axum/tests/auth_fallbacks.rs covering JWT claim-fallback branches and the extractor-missing rejection path. Tokens are hand-crafted with jsonwebtoken directly (matching the pattern in tests/integration.rs) so individual claims can be omitted.

Tests added:

  1. missing_sub_claim_falls_back_to_unknown_sentinel — token omitting sub exercises the unwrap_or("unknown") fallback.
  2. missing_iss_claim_falls_back_to_empty_string — token omitting iss exercises the unwrap_or_default() fallback for iss.
  3. missing_aud_claim_falls_back_to_empty_string — token omitting aud exercises the unwrap_or_default() fallback for aud.
  4. test_auth_context_extractor_rejects_when_not_injected — extractor returns 401 UNAUTHORIZED with body "missing auth context" when no middleware injected the context.

The verifier's deterministic signing key is recreated by mirroring the DeterministicJwksPhase derivation (auth-suite:primary label). Tests follow the panic-free TestResult<()> / require_ok / ensure_eq! pattern from tests/accessors.rs.

Test plan

  • cargo test -p uselesskey-axum — 4 new + 25 existing tests pass.
  • cargo clippy -p uselesskey-axum --tests --all-features -- -D warnings — clean.
  • cargo fmt --check — clean.

Notes

Missing exp claim intentionally skipped: not reachable through the public middleware. jsonwebtoken 10.4 includes exp in Validation::required_spec_claims by default, so a token without exp is rejected by decode::<Value> (returns MissingRequiredClaim) before extraction runs. The exp.unwrap_or_default() line in verify_bearer_token is defensive code unreachable via public API. Rationale documented in the test file's module-level comment.


Generated by Claude Code

Add `tests/auth_fallbacks.rs` exercising verifier and extractor branches
that the happy-path integration tests do not reach:

- Token omitting `sub` exercises the `unwrap_or("unknown")` fallback in
  `verify_bearer_token`.
- Token omitting `iss` exercises the `unwrap_or_default()` fallback for
  the `iss` claim (jsonwebtoken only validates `iss` when present).
- Token omitting `aud` exercises the `unwrap_or_default()` fallback for
  the `aud` claim (jsonwebtoken only validates `aud` when present).
- `TestAuthContext::from_request_parts` returns `401 UNAUTHORIZED` with
  `"missing auth context"` when no middleware injected the context.

The `exp.unwrap_or_default()` branch is unreachable via the public
middleware (`exp` is in `required_spec_claims` by default), so no test
is added for it; the rationale is documented in the file's header
comment.

Co-authored-by: Claude <noreply@anthropic.com>
@gemini-code-assist

Copy link
Copy Markdown

Warning

You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again!

@coderabbitai

coderabbitai Bot commented May 16, 2026

Copy link
Copy Markdown

Warning

Rate limit exceeded

@EffortlessSteven has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 10 minutes and 43 seconds before requesting another review.

You’ve run out of usage credits. Purchase more in the billing tab.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 71e5f621-58a5-4fd8-91d5-afc9fdf29799

📥 Commits

Reviewing files that changed from the base of the PR and between 4c2da13 and e220da4.

📒 Files selected for processing (1)
  • crates/uselesskey-axum/tests/auth_fallbacks.rs
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch claude/coverage-axum-fallbacks-OA2NV

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@EffortlessSteven EffortlessSteven marked this pull request as ready for review May 17, 2026 05:39
@gemini-code-assist

Copy link
Copy Markdown

Warning

You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again!

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.
To continue using code reviews, add credits to your account and enable them for code reviews in your settings.

@EffortlessSteven EffortlessSteven merged commit e7a6be1 into main May 17, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants