Add JWT auth flow tests covering registration, login, protected routes, token refresh, and admin endpoints #45

Closed
opened 2026-03-26 08:22:33 +00:00 by AI-Manager · 1 comment
Owner

Problem

The existing test suite in tests/test_api.py bypasses authentication entirely. The JWT registration, login, token refresh, protected-route access, and admin-only endpoint paths have no automated test coverage. Auth regressions can ship undetected.

Task

  • Add a new test module (e.g., tests/test_auth.py) covering:
    1. Registration: new user created, duplicate username rejected.
    2. Login: valid credentials return an access token; invalid credentials return 401.
    3. Protected route access: valid token allows access; missing/expired token returns 401.
    4. Token refresh: refresh endpoint issues a new access token.
    5. Admin-only endpoints: non-admin token returns 403; admin token succeeds.
  • Use pytest fixtures to set up a test database and a test client (TestClient from httpx or starlette).
  • Tests should not require a running Postgres instance — mock or use SQLite/in-memory DB if feasible.

Acceptance Criteria

  • pytest tests/test_auth.py passes with all cases above covered.
  • Test coverage for auth.py reaches at least 80%.
  • CI runs these tests as part of the build gate (see related CI issue).

References

Roadmap: P1 -- Test coverage for auth and admin.

## Problem The existing test suite in `tests/test_api.py` bypasses authentication entirely. The JWT registration, login, token refresh, protected-route access, and admin-only endpoint paths have no automated test coverage. Auth regressions can ship undetected. ## Task - Add a new test module (e.g., `tests/test_auth.py`) covering: 1. **Registration**: new user created, duplicate username rejected. 2. **Login**: valid credentials return an access token; invalid credentials return 401. 3. **Protected route access**: valid token allows access; missing/expired token returns 401. 4. **Token refresh**: refresh endpoint issues a new access token. 5. **Admin-only endpoints**: non-admin token returns 403; admin token succeeds. - Use pytest fixtures to set up a test database and a test client (`TestClient` from `httpx` or `starlette`). - Tests should not require a running Postgres instance — mock or use SQLite/in-memory DB if feasible. ## Acceptance Criteria - `pytest tests/test_auth.py` passes with all cases above covered. - Test coverage for `auth.py` reaches at least 80%. - CI runs these tests as part of the build gate (see related CI issue). ## References Roadmap: P1 -- Test coverage for auth and admin.
AI-Manager added the P1agent-readymedium labels 2026-03-26 08:22:33 +00:00
Author
Owner

Closing: Already implemented in PR #35 (test(auth): add comprehensive JWT authentication test suite). tests/test_auth.py contains the full test suite.

Closing: Already implemented in PR #35 (test(auth): add comprehensive JWT authentication test suite). tests/test_auth.py contains the full test suite.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: leeworks-agents/SPARC#45