Score the recreated newz repo's M5 (JWT authentication) commit b186d0f at 44 (40/46 base + 4 bonus), overall level 5. Note that the commit is on local develop only and has not been pushed. Co-Authored-By: Claude Haiku 5.5 <noreply@anthropic.com>
6.4 KiB
6.4 KiB
M5: Setup Authentication - Score Report
Model: qwen3.8-27b
Repository scored: ../newz (/home/daniel/Gitea/daniel/newz), local develop at b186d0f (M5 commit, not yet pushed; origin/develop is at ed7b304)
Rubric: milestone/m5-setup-authentication-scoring.md
Total Score: 44 (40 base + 4 bonus) - Overall level 5
Overall level 5: all level 2 to 4 criteria are met, all three auth pages exist, and the forms validate input with loading states and status-coded errors. The backend, frontend build and tests all pass on the committed tree.
Verification Performed
All checks ran on a clean git archive b186d0f export in a temp directory.
| Check | Result |
|---|---|
| Prompt parity | milestones/m5-setup-authentication-prompt.md in the commit is identical to the benchmark copy. |
Backend pytest |
51 passed, 97% coverage (649 statements, 18 missed). |
| Live backend (uvicorn) | register 201 with JWT; me 200 with a valid token; me 401 with no token and with a tampered token; login 200 on correct password and 401 on wrong password; duplicate register 400; invalid username 422; logout 204. The token's exp - iat is 604800 seconds (7 days). |
| Password storage | No plaintext password appears in any database file. |
Frontend npm ci and npm run build |
Pass (tsc and vite build, no errors). |
Frontend npx vitest run |
9 files, 53 tests, all pass. |
Frontend npm run e2e -- --project=chromium |
19 passed, including auth.spec.ts. |
/api/auth/* (path in the milestone prompt) |
Returns 404. The routes live under /api/v1/auth/*, following the M2 prefix. The commit message records this as a deliberate choice. |
| Docker | Not re-run in this pass. On this host, make dev still fails on the hardcoded subnet from M4. |
Scoring by Criterion
| Criterion | Score | Max | Notes |
|---|---|---|---|
| Backend User Model | 3 | 3 | User has id, username (String(60), unique, indexed), password_hash (String(128)), and created_at (timezone-aware, defaulted). |
| Password Hashing | 4 | 4 | PBKDF2-HMAC-SHA256 with 120,000 iterations. Salt from secrets.token_hex(16), stored as salt$digest. verify_password uses secrets.compare_digest. Tests cover round-trip, unique salts, and malformed stored values. |
| JWT Token System | 5 | 5 | create_token sets sub, iat, exp (7 days), signs with HS256 using HN_SECRET_KEY (dev default marked as change-me). Decoding validates the signature, expiry, and that the user still exists. Tests cover wrong key and expired tokens. |
| Backend Auth Endpoints | 5 | 5 | register (201, {token, username}, username regex, duplicate check), login (hash check, 401 on failure), logout (204, requires a token), me (Bearer validation). The duplicate-username check returns 400, matching the QA notes. Deviation: /api/v1/auth/* instead of /api/auth/*. |
| Frontend Authentication Context | 5 | 5 | AuthProvider exposes username, ready, login, register, and logout. On load it calls GET /auth/me with the stored token and drops the token on failure. Login and Register go through the context, so the token is stored on success. RequireAuth guards protected routes. |
| Token Storage & Management | 3 | 3 | AUTH_TOKEN is used consistently. Login and register store the token, logout removes it, and an invalid stored token is cleared on restore. |
| API Client Auth Methods | 4 | 4 | login, register, logout, and me are implemented. The Authorization: Bearer header is attached to every request when a token exists. Non-2xx responses throw ApiError. |
| Frontend Auth Pages | 5 | 6 | Login, Register (with client-side username, password-length and password-match checks, a disabled submit while busy, and error messages), and SignOut (routed at /sign-out, clears the token, redirects to /login). Deduction: no explicit success message after login or register, only a redirect. |
| Security Implementation | 4 | 4 | PBKDF2 at 120k iterations, HS256, secret from HN_SECRET_KEY with a dev-only default, no plaintext passwords, and CORS configured from M2. |
| Git Configuration | 2 | 2 | backend/.gitignore excludes *.db, *.sqlite, and data/. Root .gitignore excludes .env and .env.*. data/.gitignore names newzy.db and data.db. |
| Base total | 40 | 46 |
Bonus
- +1 Input validation and password strength: awarded. Username regex
^[a-zA-Z0-9_]{3,20}$on the backend and frontend, and passwords need at least 8 characters. - +2 Non-leaking errors and rate-limit placeholders: not awarded. Login errors are generic ("Invalid username or password"), but there are no rate-limit placeholder comments or code.
- +3 Complete error handling and protected-route redirect: awarded. Errors are shown to the user, and
RequireAuthredirects unauthenticated users to/login.
Bonus total: +4.
Critical Requirements Checklist (from rubric)
Must have for score above 1:
- Passwords never stored as plaintext
- PBKDF2 with at least 100,000 iterations (SHA256)
- JWT uses HS256
HN_SECRET_KEYused for signing- Token
expis 7 days afteriat
Must have for score above 3:
- Context provides login, register, logout
AUTH_TOKENpersistence in localStorage- Session check on load calls
/auth/me - 401 responses for invalid tokens
Other Observations
- M5 is not on
origin/develop. The commitb186d0fexists only on localdevelop. Push it, or open a pull request from it, before treating M5 as delivered. - Endpoint path differs from the prompt. The prompt says
/api/auth/*, but the implementation uses/api/v1/auth/*, consistent with the M2 prefix. Either update the prompt or add an alias route. - No rate limiting. The prompt lists rate limiting as a known limitation, so this is expected, but the bonus placeholder is missing.
- Docker not re-verified. The M4 subnet conflict on this host still blocks
make dev, so the auth changes were not run inside containers in this pass.
Path to a Higher Score
- Push
develop(or open a pull request) so M5 is on the remote. - Add a success notice after login and register, to reach level 6 on the auth pages.
- Add a rate-limit placeholder comment or middleware stub on the auth endpoints for the +2 bonus.
- Reconcile the endpoint path with the milestone prompt, either by updating the prompt or adding
/api/authaliases.