Skip to content

♻️ Refactor JWT key management and enhance authentication tests#822

Merged
yezz123 merged 7 commits intomainfrom
websocket
Mar 20, 2026
Merged

♻️ Refactor JWT key management and enhance authentication tests#822
yezz123 merged 7 commits intomainfrom
websocket

Conversation

@yezz123
Copy link
Copy Markdown
Owner

@yezz123 yezz123 commented Mar 20, 2026

No description provided.

yezz123 added 4 commits March 20, 2026 12:18
- Eliminated `python-jose` from the dependencies list in both `pyproject.toml` and `uv.lock` to streamline package management and reduce unnecessary dependencies.
- Added `JWT_PREVIOUS_SECRET_KEY` and `JWT_PREVIOUS_PUBLIC_KEY` to `AuthXConfig` for key rotation.
- Implemented fallback logic in token verification methods to use the previous public key if the current key fails.
- Introduced WebSocket authentication handling with token verification, supporting both query parameters and headers.
- Introduced a new test suite in `test_key_rotation.py` to validate JWT signing key rotation functionality for both symmetric and asymmetric keys.
- Implemented tests for token creation and decoding with current and previous keys, ensuring proper fallback behavior and error handling.
- Added configuration property tests for `previous_public_key` in `AuthXConfig` to verify correct retrieval of previous keys.
- Introduced a new test suite in `test_websocket.py` to validate WebSocket authentication using JWT tokens.
- Implemented tests for token retrieval from query parameters and authorization headers, including scenarios for missing, invalid, and revoked tokens.
- Added support for custom query parameter names and token scopes in the authentication process.
@vercel
Copy link
Copy Markdown

vercel bot commented Mar 20, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
authx Ready Ready Preview, Comment Mar 20, 2026 0:47am

- Modified the type hint for the `headers` parameter in the `_ws` function to use `Optional` for better clarity and to handle potential None values.
- Adjusted the import statement to include `Optional` from the typing module.
@codecov
Copy link
Copy Markdown

codecov bot commented Mar 20, 2026

Codecov Report

❌ Patch coverage is 92.85714% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 98.54%. Comparing base (93b13ab) to head (a3a3346).
⚠️ Report is 10 commits behind head on main.

Files with missing lines Patch % Lines
authx/config.py 77.77% 1 Missing and 1 partial ⚠️
authx/main.py 96.96% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #822      +/-   ##
==========================================
- Coverage   98.83%   98.54%   -0.29%     
==========================================
  Files          16       16              
  Lines         856      894      +38     
  Branches       90       99       +9     
==========================================
+ Hits          846      881      +35     
- Misses          5        7       +2     
- Partials        5        6       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

- Removed the use of `MutableHeaders` and `Headers` from the request setup in `test_key_rotation.py` and `test_authx_extend.py`.
- Introduced a new helper function `_make_request` to streamline request creation with authorization headers.
- Updated tests to utilize the new request creation method, improving code clarity and maintainability.
- Moved RSA and EC key pair generation functions to `tests/utils.py` for better reusability.
- Updated `test_asymmetric.py` and `test_key_rotation.py` to utilize the new key pair generation functions, improving code clarity and maintainability.
@sonarqubecloud
Copy link
Copy Markdown

@yezz123 yezz123 merged commit 19eb23e into main Mar 20, 2026
19 of 21 checks passed
@yezz123 yezz123 deleted the websocket branch March 20, 2026 12:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant