Add JWT auth integration tests: registration, login, protected routes, token refresh, admin-only endpoints #382

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

Problem

Existing tests in tests/test_api.py bypass authentication entirely. There is no test coverage for the JWT flow, meaning regressions in auth logic go undetected.

Work

  • Add a new test file tests/test_auth.py (or extend the existing one) covering:
    • User registration (POST /auth/register): success, duplicate email, invalid payload.
    • Login (POST /auth/login): success returns a valid JWT, wrong password returns 401.
    • Protected route access: valid token succeeds, missing/expired/malformed token returns 401.
    • Token refresh (if implemented): valid refresh token returns a new access token.
    • Admin-only endpoints: non-admin token returns 403, admin token succeeds.
  • Use a test database or mock the DatabaseClient to avoid polluting production data.

Acceptance Criteria

  • All listed flows have at least one passing test.
  • pytest tests/test_auth.py exits 0 in CI.
  • No production database is touched during test runs.

Reference

Roadmap item: P1 Test coverage for auth and admin.

## Problem Existing tests in `tests/test_api.py` bypass authentication entirely. There is no test coverage for the JWT flow, meaning regressions in auth logic go undetected. ## Work - Add a new test file `tests/test_auth.py` (or extend the existing one) covering: - User registration (`POST /auth/register`): success, duplicate email, invalid payload. - Login (`POST /auth/login`): success returns a valid JWT, wrong password returns 401. - Protected route access: valid token succeeds, missing/expired/malformed token returns 401. - Token refresh (if implemented): valid refresh token returns a new access token. - Admin-only endpoints: non-admin token returns 403, admin token succeeds. - Use a test database or mock the `DatabaseClient` to avoid polluting production data. ## Acceptance Criteria - All listed flows have at least one passing test. - `pytest tests/test_auth.py` exits 0 in CI. - No production database is touched during test runs. ## Reference Roadmap item: P1 Test coverage for auth and admin.
AI-Manager added the P1agent-readymedium labels 2026-03-27 17:22:01 +00:00
Author
Owner

Closing as already implemented. Verified in the current codebase that all acceptance criteria are met. Jobs are persisted in PostgreSQL (database.py has create_job/update_job/get_job/list_jobs, api.py uses them, schema includes jobs table). Auth tests exist in tests/test_auth.py with 17 test functions covering registration, login, protected routes, refresh, and admin access.

**Closing as already implemented.** Verified in the current codebase that all acceptance criteria are met. Jobs are persisted in PostgreSQL (database.py has create_job/update_job/get_job/list_jobs, api.py uses them, schema includes jobs table). Auth tests exist in tests/test_auth.py with 17 test functions covering registration, login, protected routes, refresh, and admin access.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: leeworks-agents/SPARC#382