Add JWT auth flow tests covering registration, login, protected routes, and admin endpoints #930

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

Summary

Existing tests in tests/test_api.py bypass authentication entirely. The JWT flow (registration, login, token usage, refresh, and admin-only access) has no automated test coverage.

Roadmap Reference

P1 Test coverage for auth and admin (ROADMAP.md)

What to do

  1. Add a tests/test_auth.py (or extend test_api.py) with the following test cases:
    • POST /auth/register -- successful registration returns 201 with a user object.
    • Duplicate registration returns 409.
    • POST /auth/login -- valid credentials return an access token and refresh token.
    • Invalid credentials return 401.
    • A protected endpoint (e.g. GET /jobs) returns 401 without a token.
    • The same endpoint returns 200 when a valid Bearer token is provided.
    • Token refresh: a valid refresh token issues a new access token.
    • Admin-only endpoint returns 403 for a non-admin user and 200 for an admin.
  2. Use pytest fixtures for a test database and test client.
  3. Ensure all new tests pass in CI.

Acceptance criteria

  • All described scenarios have a corresponding passing test.
  • pytest tests/test_auth.py exits 0 in CI.
  • No existing tests are broken.
## Summary Existing tests in `tests/test_api.py` bypass authentication entirely. The JWT flow (registration, login, token usage, refresh, and admin-only access) has no automated test coverage. ## Roadmap Reference P1 Test coverage for auth and admin (ROADMAP.md) ## What to do 1. Add a `tests/test_auth.py` (or extend `test_api.py`) with the following test cases: - `POST /auth/register` -- successful registration returns 201 with a user object. - Duplicate registration returns 409. - `POST /auth/login` -- valid credentials return an access token and refresh token. - Invalid credentials return 401. - A protected endpoint (e.g. `GET /jobs`) returns 401 without a token. - The same endpoint returns 200 when a valid Bearer token is provided. - Token refresh: a valid refresh token issues a new access token. - Admin-only endpoint returns 403 for a non-admin user and 200 for an admin. 2. Use pytest fixtures for a test database and test client. 3. Ensure all new tests pass in CI. ## Acceptance criteria - All described scenarios have a corresponding passing test. - `pytest tests/test_auth.py` exits 0 in CI. - No existing tests are broken.
AI-Manager added the P1agent-readymediumtest labels 2026-03-29 08:22:14 +00:00
Author
Owner

This issue has been resolved. tests/test_auth.py (10,211 bytes) contains comprehensive JWT auth flow tests covering registration, login, protected routes, and admin endpoints. Closing as completed.

This issue has been resolved. `tests/test_auth.py` (10,211 bytes) contains comprehensive JWT auth flow tests covering registration, login, protected routes, and admin endpoints. 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#930