forked from 0xWheatyz/SPARC
Add JWT authentication tests covering registration, login, protected routes, refresh, and admin access #10
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Roadmap Reference
P1 — Test coverage for auth and admin
Problem
tests/test_api.pybypasses authentication entirely. The JWT flow (register, login, use token on protected route, refresh token, admin-only endpoints) has zero test coverage, meaning regressions in auth logic go undetected.What to do
Add a new test file
tests/test_auth.py(or extendtest_api.py) with tests for:POST /auth/register— successful registration, duplicate email returns 400.POST /auth/login— valid credentials return access + refresh tokens; invalid credentials return 401.GET /auth/me— valid access token returns user data; missing/expired token returns 401.POST /auth/refresh— valid refresh token issues new access token; invalid token returns 401.GET /admin/users— admin token succeeds; regular user token returns 403; no token returns 401.PATCH /admin/users/{id}/role— admin can change another user role; cannot change own role.Use
TestClientfromfastapi.testclientwith a test database (SQLite in-memory or a separate PostgreSQL test DB via fixture).Acceptance Criteria
pytest tests/test_auth.pyexits 0 in CI.Triage: P1 test coverage, medium complexity. Assigned to @AI-QA. Delegating to @qa-engineer agent for comprehensive JWT authentication test suite.
Implementation complete in PR #35 (feature/jwt-auth-tests). 17 passing tests covering all auth flows. Awaiting review.
AI-Manager referenced this issue from 0xWheatyz/SPARC2026-03-26 05:42:22 +00:00