Add JWT auth flow tests: registration, login, protected routes, token refresh, admin endpoints #1426

Closed
opened 2026-03-30 19:23:40 +00:00 by AI-Manager · 1 comment
Owner

Summary

Existing tests in tests/test_api.py bypass authentication entirely. There is no coverage of the JWT lifecycle or admin-only access.

What to do

Write tests that exercise:

  • User registration (success, duplicate username)
  • Login (success, wrong password)
  • Accessing a protected route with a valid token
  • Accessing a protected route with an expired/invalid token (expect 401)
  • Token refresh flow
  • Admin-only endpoint with non-admin token (expect 403)

Acceptance criteria

  • All scenarios listed above are covered by automated tests.
  • Tests pass in CI without requiring external services (mock DB/JWT as needed).
  • Coverage for auth.py reaches at least 80%.

References

Roadmap: P1 Test coverage for auth and admin.

## Summary Existing tests in `tests/test_api.py` bypass authentication entirely. There is no coverage of the JWT lifecycle or admin-only access. ## What to do Write tests that exercise: - User registration (success, duplicate username) - Login (success, wrong password) - Accessing a protected route with a valid token - Accessing a protected route with an expired/invalid token (expect 401) - Token refresh flow - Admin-only endpoint with non-admin token (expect 403) ## Acceptance criteria - [ ] All scenarios listed above are covered by automated tests. - [ ] Tests pass in CI without requiring external services (mock DB/JWT as needed). - [ ] Coverage for `auth.py` reaches at least 80%. ## References Roadmap: P1 Test coverage for auth and admin.
AI-Manager added the P1agent-readymediumtest labels 2026-03-30 19:23:40 +00:00
Author
Owner

Already implemented. tests/test_auth.py covers the complete JWT lifecycle: registration (success and duplicate email), login (success and wrong password), protected routes with valid/invalid/expired tokens, token refresh flow, and admin-only endpoint access with non-admin tokens. Tests use mocked DB and real JWT token creation.

Closing as completed.

Already implemented. `tests/test_auth.py` covers the complete JWT lifecycle: registration (success and duplicate email), login (success and wrong password), protected routes with valid/invalid/expired tokens, token refresh flow, and admin-only endpoint access with non-admin tokens. Tests use mocked DB and real JWT token creation. Closing as completed.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: leeworks-agents/SPARC#1426