Skip to content

refactor(auth): extract password-login session state writes (S08-C1a) - #357

Merged
voidvec merged 1 commit into
masterfrom
refactor/password-login-session-c1a-implementation
Nov 19, 2026
Merged

voidvec merged 1 commit into
masterfrom
refactor/password-login-session-c1a-implementation

Conversation

@voidvec

@voidvec voidvec commented Nov 19, 2026

Copy link
Copy Markdown
Owner

Summary

S08-C1a extracts the existing password-login session writes into two private, non-installed helpers. A fresh login still replaces the internal ID/public subject, records password authentication, clears the two stale markers and rotates JSESSIONID once. The controller's original clock read stays between the two helpers; the audit/policy/database/callback continuation is byte-identical.

Add five real-Session unit cases in a dedicated executable and two HTTP characterization cases covering account switching, rejected credentials, forced-password/MFA gates and MFA-to-password relogin. The private fixture uses a framework-created session, a loopback ephemeral listener and one start/quit/join cycle; it is excluded from the existing event-loop-free adapter test executable.

No public headers, SDK/OpenAPI, routes, storage, schema, configuration or authentication policy change. This does not fix #350, #351 or #353.

Validation

  • Independent plan, updated-baseline and final implementation reviews passed.
  • Original inline implementation: full manage.sh test-backend, 654 CTest entries; complete main binary 753 cases / 62,547 assertions.
  • Extracted implementation: the same HTTP source and private PostgreSQL/Redis configuration, 655 CTest entries with zero failures/errors/skipped entries; complete main binary 753 cases / 62,576 assertions.
  • The added standalone CTest entry ran all five real-Session cases successfully, including typed overwrites, preserved unrelated keys and actual JSESSIONID rotation.
  • Saved inline and extracted binaries each passed the two exact HTTP cases with 50 + 41 assertions using the same test/configuration. Both cases created isolated API fixtures; they did not return early for unavailable PostgreSQL.
  • Real out-of-process endpoints, feature-surface probe and social-login-state regression passed. Endpoint scripts reported OAuth 62/63 passed with 0 failed and admin 61/61 passed.
  • Thirteen local architecture, API, migration, naming, macro, manage-parity, doc-link and OpenAPI/spec checks passed. Release/C++17/WERROR, all optional features enabled, local resource override -O1 -DNDEBUG; examples were disabled locally.
  • Published tree 7329b7d978f9c8dc4543026773587edb3a208a74 exactly matches the independently reviewed native tree.

Known validation limits: the existing CSP broker-profile sub-branch is skipped in this test wiring; the wrapper's second memory-config round is skipped because its nested staged-config path is absent. PostgreSQL HTTP coverage is real; active email-verification policy, database-failure injection and the independent fallback HTTP path were not separately exercised. An initial runner configuration mismatch was retained and excluded from the accepted paired baseline; the corrected run checks the expected and staged configuration hashes. Full-suite assertion totals are reported per run rather than treated as a fixed equality check. Fixture users are retired through the API; UUID clients remain because of existing token references.

Fresh three-platform CI/SDK-consumer/Sanitizers results and a manually dispatched client-SDK drift workflow remain to be checked. No merge or deployment is requested.

Type of change

Internal refactor, non-breaking.

Checklist

  • Characterization and unit tests added; complete local backend suite passed
  • CHANGELOG updated
  • Public API/schema/SDK unchanged; no mirror or generated baseline update required

wangrh0909
wangrh0909 previously approved these changes Nov 19, 2026
@voidvec

voidvec commented Nov 19, 2026

Copy link
Copy Markdown
Owner Author

Deep review — S08-C1a password-login session-state extraction (head fe3f057a)

Verdict: no P0/P1/P2 code issues introduced. Behavior parity, boundary/exception paths, and architecture verified against base f720d5d9; one mechanical merge blocker registered below.

Behavior parity (byte-level verification)

  • The two helpers reproduce the removed inline block statement-for-statement: erase-before-insert order, std::to_string(int32_t) for userId, int64_t auth_time, amr="pwd", both stale-marker erases (mfa_pending, must_change_password), and a single changeSessionIdToClient() at the end. The original clock read stays between the two helper calls, exactly at its original position.
  • Programmatic comparison confirms everything from the audit call onward is byte-identical: forced-password gate including the conditional must_change_password re-insert, evaluateLoginPolicy, MFA session writes + pending-binding DB chain, code-issuance guards, PKCE. The onValidated capture list is unchanged; the only other delta in the file is the new include.
  • No public header / route / OpenAPI / error-code change, so no sync-point obligations; CHANGELOG entry added in correct section order.
  • Boundary coverage: int32 min/max, int64 {0, min, max}, "pwd mfa" → "pwd" downgrade, unowned-key preservation with an exact key-count assertion, rotate-once semantics. Exception paths: wrong password / absent user / missing password (401/401/400) with no cookie rotation and no session-identity change, forced-password gate (consent 403, mfa-verify 403), MFA gate, and MFA → password-only relogin.

Architecture

  • Session writes are an adapter concern; the helpers live in libs/drogon/src/controllers under controllers::detail (existing precedent: social_detail, storage::postgres::detail), in a src-local private header with a forward-declared drogon::Session — no public-API surface, no api-diff impact. Authentication policy stays in the controller; dependency direction is clean, no domain leakage.
  • Test wiring is correct: REMOVE_ITEM uses the absolute CMAKE_CURRENT_SOURCE_DIR path matching the GLOB result; the dedicated executable links fulla::drogon + gtest with compat/warnings/gcov/sanitizer flags and one CTest entry (single Drogon start/quit cycle); the HTTP test follows Integration_P0_<Module>_<Name> naming and is picked up by the integration GLOB.

P2 register (merge-blocking)

  1. P2 — branch conflicts with master (mechanical, no code defect). mergeable=CONFLICTING; git merge-tree shows the only conflict is CHANGELOG.md (Unreleased entries landed via fix(storage): preserve access-token timestamps and reject future introspection nbf #344 / fix(observability): export bounded cache counters through PromExporter #345 / refactor(drogon): share token grant response presentation #346 after base f720d5d9). Rebase onto current master keeping both sets of entries; no code change required. For reference, CI on the current head is fully green (14 pass / 2 expected skips: three-platform builds, ASan+UBSan, SDK smoke, feature matrix).

Callback safety audit — no issues

  • The helpers are synchronous free functions taking Session&; they introduce no callbacks, captures, or async hops. The existing chain (onValidated value captures, sharedCb = make_shared<function> in the MFA branch, guard continuations) is byte-identical; no double-move of callback.
  • Unit-test handler invokes its callback exactly once on every path (400 / success / 500); capture entries are erased under mutex before use and again after send (idempotent); a timed-out observe() cannot leave a dangling promise consumer.

Lifetime audit — no issues

  • Production: req (and thus the session) is held by value in onValidated; the helpers borrow Session& synchronously — no new ownership, identical lifetime to the removed inline code.
  • Unit fixture: SessionPtr kept alive via promise/future and the fixture member across assertions; the server thread captures shared_ptr promise/flag; app().quit() + join() run on every exit path including startup-deadline failure; late set_exception guards future_error.
  • HTTP fixture: explicit per-browser cookie jars, single physical requests (no write/grant retries), deterministic retirement in the destructor with a catch-all, and a hard 3s deadline on scope-visibility polling.

Preserve password-login overwrite order, the controller clock read, marker cleanup and session-ID rotation in two private helpers. Add an isolated real-Session fixture and paired HTTP characterization coverage without changing policy, storage, routes or public APIs.
@voidvec
voidvec force-pushed the refactor/password-login-session-c1a-implementation branch from fe3f057 to c3e5b0d Compare November 19, 2026 08:56
@voidvec
voidvec marked this pull request as ready for review November 19, 2026 09:48
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 19, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-19T09:49:49.338529Z c3e5b0d Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@voidvec
voidvec merged commit 12c6fdb into master Nov 19, 2026
16 checks passed
@voidvec
voidvec deleted the refactor/password-login-session-c1a-implementation branch November 19, 2026 09:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants