forked from 0xWheatyz/SPARC
Add JWT authentication tests (registration, login, protected routes, token refresh, admin) #617
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?
Context
Existing API tests in
tests/test_api.pybypass authentication entirely. There is no test coverage for the JWT flow, protected-route enforcement, or admin-only endpoints.Roadmap item: P1 > Test coverage for auth and admin
What to do
Add a new test file
tests/test_auth.py(or extend the existing file) covering:POST /auth/registerwith valid payload returns 201 and a user object.POST /auth/loginwith valid credentials returns a JWT access token.GET /patents(or any protected endpoint) without a token returns 401; with a valid token returns 200.POST /auth/refresh(if implemented) returns a new token.Use pytest fixtures for creating test users and tokens.
Acceptance criteria
pytest tests/test_auth.pywith no external dependencies beyond the test database.Closing: already implemented on main.
tests/test_auth.py(302 lines) covers registration, duplicate registration, login success/failure, protected routes, token refresh, and admin-only endpoints with 17 test functions.