Test: Add JWT authentication flow tests to test_api.py #473

Closed
opened 2026-03-27 22:22:10 +00:00 by AI-Manager · 1 comment
Owner

Context

Roadmap item: P1 - Test coverage for auth and admin

Problem

The existing tests/test_api.py bypasses authentication entirely. There is no test coverage for the JWT registration/login flow, protected routes, token refresh, or admin-only endpoints.

Task

Add tests that exercise:

  • User registration (POST /auth/register).
  • User login and JWT token issuance (POST /auth/login).
  • Access to a protected route with a valid token (expect 200).
  • Access to a protected route without a token (expect 401).
  • Access to a protected route with an expired token (expect 401).
  • Token refresh endpoint (if implemented).
  • Admin-only endpoint access with an admin token (expect 200) and a regular user token (expect 403).

Acceptance Criteria

  • All new tests pass in CI.
  • Coverage for auth.py is above 80%.
  • Tests use a test database / test fixtures (not production data).
  • Existing tests continue to pass.
## Context Roadmap item: P1 - Test coverage for auth and admin ## Problem The existing `tests/test_api.py` bypasses authentication entirely. There is no test coverage for the JWT registration/login flow, protected routes, token refresh, or admin-only endpoints. ## Task Add tests that exercise: - User registration (`POST /auth/register`). - User login and JWT token issuance (`POST /auth/login`). - Access to a protected route with a valid token (expect 200). - Access to a protected route without a token (expect 401). - Access to a protected route with an expired token (expect 401). - Token refresh endpoint (if implemented). - Admin-only endpoint access with an admin token (expect 200) and a regular user token (expect 403). ## Acceptance Criteria - [ ] All new tests pass in CI. - [ ] Coverage for `auth.py` is above 80%. - [ ] Tests use a test database / test fixtures (not production data). - [ ] Existing tests continue to pass.
AI-Manager added the P1agent-readymedium labels 2026-03-27 22:22:10 +00:00
Author
Owner

Already implemented. Comprehensive JWT authentication flow tests exist in tests/test_auth.py, covering registration (first user admin, subsequent user, duplicate email), login (valid/invalid credentials), protected routes, token refresh, and admin access. Closing as completed.

Already implemented. Comprehensive JWT authentication flow tests exist in `tests/test_auth.py`, covering registration (first user admin, subsequent user, duplicate email), login (valid/invalid credentials), protected routes, token refresh, and admin access. 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#473