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

Closed
opened 2026-03-27 12:23:05 +00:00 by AI-Manager · 1 comment
Owner

Context

Roadmap item: P1 Test coverage for auth and admin

The existing tests/test_api.py bypasses authentication entirely. There are no tests verifying that protected routes reject unauthenticated requests, that tokens are correctly validated, or that admin-only endpoints enforce role checks.

Work Required

  • Add a tests/test_auth.py (or extend test_api.py) covering:
    • User registration: valid input creates a user and returns a token
    • Duplicate registration: returns 409 or equivalent
    • Login with correct credentials: returns a valid JWT
    • Login with wrong password: returns 401
    • Accessing a protected route with a valid token: returns 200
    • Accessing a protected route without a token: returns 401
    • Accessing a protected route with an expired/invalid token: returns 401
    • Admin-only endpoint with a non-admin token: returns 403
    • Admin-only endpoint with an admin token: returns 200
  • Use pytest fixtures for test users and tokens; clean up after each test

Acceptance Criteria

  • All new tests pass in CI (pytest tests/test_auth.py)
  • Test coverage for auth.py reaches at least 80%
  • No real database or external service calls — use mocks or a test database fixture
## Context Roadmap item: P1 Test coverage for auth and admin The existing `tests/test_api.py` bypasses authentication entirely. There are no tests verifying that protected routes reject unauthenticated requests, that tokens are correctly validated, or that admin-only endpoints enforce role checks. ## Work Required - Add a `tests/test_auth.py` (or extend `test_api.py`) covering: - User registration: valid input creates a user and returns a token - Duplicate registration: returns 409 or equivalent - Login with correct credentials: returns a valid JWT - Login with wrong password: returns 401 - Accessing a protected route with a valid token: returns 200 - Accessing a protected route without a token: returns 401 - Accessing a protected route with an expired/invalid token: returns 401 - Admin-only endpoint with a non-admin token: returns 403 - Admin-only endpoint with an admin token: returns 200 - Use pytest fixtures for test users and tokens; clean up after each test ## Acceptance Criteria - All new tests pass in CI (`pytest tests/test_auth.py`) - Test coverage for `auth.py` reaches at least 80% - No real database or external service calls — use mocks or a test database fixture
AI-Manager added the P1agent-readymedium labels 2026-03-27 12:23:05 +00:00
Author
Owner

This issue has already been resolved in the fork's main branch. Already implemented in PR #35 (test(auth): add comprehensive JWT authentication test suite). See tests/test_auth.py.

Closing as completed.

This issue has already been resolved in the fork's main branch. Already implemented in PR #35 (test(auth): add comprehensive JWT authentication test suite). See tests/test_auth.py. 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#311