Skip to content

fix(admin): session persistence, token timestamps, audit log filters + test coverage - #7

Merged
wangrh0909 merged 2 commits into
masterfrom
fix/admin-session-and-test-coverage
Jul 2, 2026
Merged

wangrh0909 merged 2 commits into
masterfrom
fix/admin-session-and-test-coverage

Conversation

@voidvec

@voidvec voidvec commented Jul 2, 2026

Copy link
Copy Markdown
Owner

Summary

Three bug fixes found via manual browser testing of the admin console, plus E2E test coverage for previously untested mock-dependent cases.

Fixes

  • A-LOGIN-014 / A-SEC-002 — Session persistence. The auth store kept tokens only in memory, so any page refresh kicked the user back to /admin/login. Now persists the refresh token in sessionStorage (access token stays in memory — XSS-safe). Router guard awaits a one-shot, deduplicated restore promise to avoid the initial-navigation race; refresh-token requests are deduplicated to survive the backend's refresh-token rotation.
  • A-TOK-012 — Token expiry timestamps. The backend returns expires_at / created_at as Unix-epoch-seconds strings; new Date(string) produced "Invalid Date". formatTime now detects epoch-seconds and converts to ms.
  • A-LOG-004 — Audit log filters. The backend built a filtered WHERE clause but then discarded it, running an unfiltered query. Now applies action / outcome / actor_id server-side (parameterized). Frontend adds Action / Outcome filter UI.

Test coverage added

  • A-DASH-006 — stats API failure surfaces the localized error banner.
  • A-USR-RL-005 — assigning a non-existent role surfaces the localized error.
  • A-SEC-001 — redefined for the Bearer-token + CORS architecture: classic CSRF does not apply (auth credential not in a cookie). Added tests verifying no auth cookie is set and API requests carry a Bearer Authorization header. test-cases.md updated.

Test plan

  • Manual browser verification: refresh stays on Dashboard, token timestamps render, audit log action/outcome filters reduce result set correctly
  • npx playwright test dashboard users security — 27/27 pass
  • Reviewer: spot-check that refresh-token rotation + concurrent request dedup behaves under load

🤖 Generated with Claude Code

voidvec and others added 2 commits July 2, 2026 21:08
- Persist refresh_token in sessionStorage and restore it on page load so a
  refresh no longer kicks the user to /login (A-LOGIN-014/A-SEC-002). Access
  token stays in memory only. Router guard awaits a one-shot, deduplicated
  restore promise to avoid the initial-navigation timing race; refresh token
  requests are deduplicated to survive the backend's refresh-token rotation.
- Format token expires_at/created_at as locale strings by converting the
  epoch-seconds strings the backend returns (A-TOK-012, was "Invalid Date").
- Apply action/outcome/actor_id filters server-side in listLogs (previously
  the WHERE clause was built then discarded) and add filter UI to the audit
  logs page (A-LOG-004).

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- A-DASH-006: assert dashboard shows the localized error banner when
  /api/admin/dashboard/stats fails (INTERNAL_ERROR -> 服务器内部错误 via
  normalizeError, raw backend message intentionally not surfaced).
- A-USR-RL-005: assert assigning a non-existent role surfaces the localized
  error (VALIDATION_RESOURCE_NOT_FOUND -> 资源不存在).
- A-SEC-001: redefine for the Bearer-token + CORS architecture. Classic CSRF
  does not apply (auth credential is not in a cookie); add tests verifying the
  invariants — no auth cookie is set, and API requests carry a Bearer
  Authorization header. Update test-cases.md accordingly.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@wangrh0909
wangrh0909 merged commit ad2dda2 into master Jul 2, 2026
3 checks passed
@voidvec
voidvec deleted the fix/admin-session-and-test-coverage branch July 31, 2026 06:17
voidvec added a commit that referenced this pull request Aug 30, 2026
…loor, bootstrap self-heal, review cleanups

Address PR #141 review (1 must-fix, 8 should-fix, quick considers):

- #1 consent_csrf declared as a required query parameter in openapi.yaml
  and the C++ endpoint doc registration; apps/server/docs/api/openapi.json
  regenerated from a live server run; Python/Go clients regenerated.
- #2 nonce one-shot is now atomic: the find/verify/erase sequence is
  serialized by a process-wide mutex (consent traffic is tiny; in-process
  session storage).
- #3 identity AuthService no longer captures this in the async validateUser
  callback — the legacy-hash policy flag is value-captured
  (db-operations rule 4).
- #4/#12 AdminBootstrapper reworked as ensure-* steps: an existing admin
  user row is reused and role/mapping completed (partial failures self-heal
  on restart); the random password is printed only after the insert
  succeeded; a mapping failure no longer reports created=true.
- #5 POST /api/admin/users enforces auth.min_password_length
  (VALIDATION_PASSWORD_TOO_SHORT) — closing the admin bypass.
- #6 consent integration tests reworked: missing-nonce now drives the real
  authorize-minted slot (400), deny-to-unregistered-uri (400, no Location)
  and deny-to-registered-uri (302 access_denied) branches are covered.
- #7/#8 deployment.md: auto-bootstrap wording fixed, bogus ADMIN_SALT
  removed (PBKDF2 keeps salt empty); website i18n error table mirrored
  (3014/4007).
- #9 main.cc bootstrap probes with backoff (5 attempts) and LOG_WARN on
  failure instead of a single silent 2s probe.
- #13 unique-violation detection layered (SqlError 23505 -> constraint
  name -> english/zh localized text), mirroring the
  PostgresSocialAccountRepository pattern.
- #11 gate-4 comment corrected; #15 CHANGELOG duplicate Unreleased merged;
  #17 AGENTS.md consent.csp entry removed.

Considered-but-not-taken: #10 multi-slot nonces (tracked follow-up), #14
admin UI hardcode (server now enforces; hint stays), #18 MFA-pending
session through consent (pre-existing authorize behavior, tracked).
voidvec added a commit that referenced this pull request Aug 30, 2026
…loor, bootstrap self-heal, review cleanups

Address PR #141 review (1 must-fix, 8 should-fix, quick considers):

- #1 consent_csrf declared as a required query parameter in openapi.yaml
  and the C++ endpoint doc registration; apps/server/docs/api/openapi.json
  regenerated from a live server run; Python/Go clients regenerated.
- #2 nonce one-shot is now atomic: the find/verify/erase sequence is
  serialized by a process-wide mutex (consent traffic is tiny; in-process
  session storage).
- #3 identity AuthService no longer captures this in the async validateUser
  callback — the legacy-hash policy flag is value-captured
  (db-operations rule 4).
- #4/#12 AdminBootstrapper reworked as ensure-* steps: an existing admin
  user row is reused and role/mapping completed (partial failures self-heal
  on restart); the random password is printed only after the insert
  succeeded; a mapping failure no longer reports created=true.
- #5 POST /api/admin/users enforces auth.min_password_length
  (VALIDATION_PASSWORD_TOO_SHORT) — closing the admin bypass.
- #6 consent integration tests reworked: missing-nonce now drives the real
  authorize-minted slot (400), deny-to-unregistered-uri (400, no Location)
  and deny-to-registered-uri (302 access_denied) branches are covered.
- #7/#8 deployment.md: auto-bootstrap wording fixed, bogus ADMIN_SALT
  removed (PBKDF2 keeps salt empty); website i18n error table mirrored
  (3014/4007).
- #9 main.cc bootstrap probes with backoff (5 attempts) and LOG_WARN on
  failure instead of a single silent 2s probe.
- #13 unique-violation detection layered (SqlError 23505 -> constraint
  name -> english/zh localized text), mirroring the
  PostgresSocialAccountRepository pattern.
- #11 gate-4 comment corrected; #15 CHANGELOG duplicate Unreleased merged;
  #17 AGENTS.md consent.csp entry removed.

Considered-but-not-taken: #10 multi-slot nonces (tracked follow-up), #14
admin UI hardcode (server now enforces; hint stays), #18 MFA-pending
session through consent (pre-existing authorize behavior, tracked).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants