Skip to content

Add JWT validation test and dependency lock file#1479

Merged
anth-volk merged 20 commits into
mainfrom
fix/pin-authlib-add-jwt-validation-test
Apr 27, 2026
Merged

Add JWT validation test and dependency lock file#1479
anth-volk merged 20 commits into
mainfrom
fix/pin-authlib-add-jwt-validation-test

Conversation

@PavelMakarchuk
Copy link
Copy Markdown
Contributor

@PavelMakarchuk PavelMakarchuk commented Apr 23, 2026

Summary

  • Adds a unit test exercising the exact JWTBearerTokenValidator.authenticate_token() code path used in production — using self-signed RSA keys, no secrets, no network calls
  • Adds pyproject.toml + uv.lock for reproducible builds (matching policyengine-us/uk conventions)
  • Updates the production Dockerfile to use uv sync --frozen

Context

authlib 1.7.0 silently broke production JWT validation by delegating to joserfc, which rejected authlib's KeySet type in guess_key(). This wasn't caught because:

  1. Integration tests use StaticBearerTokenValidator (fake token matching), never exercising the real validator
  2. No lock file meant pip install pulled the latest authlib on every Docker build

Maintenance

When bumping dependencies in pyproject.toml, regenerate the lock file:

uv lock

The weekly bot PRs (policyengine-us bumps) should include this step.

Test plan

  • test_authenticate_token_with_valid_jwt — confirms the keyset + validator path works
  • test_authenticate_token_handles_expired_jwt — confirms expired tokens don't crash
  • test_authenticate_token_rejects_wrong_key — confirms wrong-key tokens are rejected
  • test_import_key_set_returns_usable_keyset — confirms JsonWebKey.import_key_set output is compatible with JWTBearerTokenValidator
  • Verified: all 4 tests fail with authlib 1.7.0, pass with 1.6.11

🤖 Generated with Claude Code

PavelMakarchuk and others added 20 commits April 23, 2026 16:35
Prevent transitive dependency breakage (like authlib 1.7.0 + joserfc)
from reaching production undetected:

- Add unit test exercising JWTBearerTokenValidator.authenticate_token()
  with self-signed RSA keys (no secrets, no network calls)
- Generate requirements.lock via pip-compile for reproducible builds
- Update Dockerfile to install from lock file

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Replace pip-compile/requirements.lock with uv.lock to match
policyengine-us and policyengine-uk conventions:

- Add pyproject.toml (migrated deps from setup.py, hatchling build)
- Generate uv.lock pinning all transitive dependencies
- Update Dockerfile to use uv sync --frozen
- Remove uv.lock from .gitignore (it must be committed)

To update deps: edit pyproject.toml then run `uv lock`.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@anth-volk anth-volk marked this pull request as ready for review April 27, 2026 21:01
@anth-volk anth-volk merged commit 71bd9e2 into main Apr 27, 2026
3 checks passed
@anth-volk anth-volk deleted the fix/pin-authlib-add-jwt-validation-test branch April 27, 2026 21:01
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