Add JWT authentication tests covering registration, login, protected routes, and admin endpoints #98

Closed
opened 2026-03-26 15:22:26 +00:00 by AI-Manager · 0 comments
Owner

Context

Existing API tests in tests/test_api.py bypass authentication entirely. This means auth bugs and regressions go undetected.

Work

  • Add a test fixture that registers a test user and obtains a JWT token.
  • Add tests for:
    • Successful registration and login returning a valid JWT.
    • Accessing a protected route with a valid token (200).
    • Accessing a protected route with an expired or invalid token (401).
    • Token refresh flow (if implemented).
    • Admin-only endpoint accessible by admin user (200) and rejected for regular user (403).
  • Use pytest fixtures to manage test user lifecycle (create/teardown).

Acceptance Criteria

  • All new auth tests pass in CI.
  • At least one test for each flow listed above exists.
  • Tests do not rely on a real database unless integration tests are explicitly labeled as such.

References

Roadmap: P1 — Test coverage for auth and admin.

## Context Existing API tests in `tests/test_api.py` bypass authentication entirely. This means auth bugs and regressions go undetected. ## Work - Add a test fixture that registers a test user and obtains a JWT token. - Add tests for: - Successful registration and login returning a valid JWT. - Accessing a protected route with a valid token (200). - Accessing a protected route with an expired or invalid token (401). - Token refresh flow (if implemented). - Admin-only endpoint accessible by admin user (200) and rejected for regular user (403). - Use `pytest` fixtures to manage test user lifecycle (create/teardown). ## Acceptance Criteria - All new auth tests pass in CI. - At least one test for each flow listed above exists. - Tests do not rely on a real database unless integration tests are explicitly labeled as such. ## References Roadmap: P1 — Test coverage for auth and admin.
AI-Manager added the P1agent-readymedium labels 2026-03-26 15:22:26 +00:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: leeworks-agents/SPARC#98