Repository navigation
feat(compat): the auth stage, S03 to S06: CSRF token, email-check, sign-up and sign-in as JSON - #80
Merged
Merged
Conversation
…gn-up and sign-in as JSON Second stage of #44. The four /auth/ routes the stock sign-up and sign-in pages call, as the JSON contract Thrust's copy of the auth client will use (D-022): a success is a 200 with {"redirect_path"} and the session cookies, a failure a 400 (429 for the rate limit) with Plane's error_code, error_message and email. Plane's order of checks is kept; the fixtures pin it with two-fault exchanges. Core gets sign_up, email_exists, is_valid_email and password_is_strong (D-023: a modest rule in place of zxcvbn, which would put a dictionary in the Worker bundle). Ports and both adapters get insert_user: a taken email or id is a Conflict from the unique index. The Postgres-vs-model sequences generate it (UserInsert, three new step classes). The recorder now runs the whole journey on a fresh stack, paced under the pin's 10-a-minute throttle, and refuses a used stack (tools/compat-record/fresh-oracle.sh recreates one). Recordings on two independent fresh stacks are byte-identical. The harness replays the journey in order and projects the pin's 302 onto Thrust's JSON by rules it documents. Controls shown red: swapping the taken-email and weak-password checks fails parity_s05 with "recorded 5030, answered 5021"; Postgres insert_user with ON CONFLICT DO NOTHING fails the model, shrunk to UserInsert{EmailTaken}; a router that strips Set-Cookie fails the cookie check; mutated fixtures fail the projection. cargo-mutants: compat crate 54 caught, 14 unviable, 0 missed (4 missed on the first run, each fixed by a test or a recorded exchange); core's new code 49 caught, 1 unviable, 0 missed; memory insert_user 3 of 3. Not mutated: the Postgres adapter (covered by the generated model). EXPECT_MAIN 39 -> 44, native-memory and native-pg 44/44; workspace nextest 1228 passed; worker wasm32 builds. Refs: plane-byd.12.2 Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
This was referenced Nov 15, 2026
Closed
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Second of nine PRs for #44. The four
/auth/routes the stock sign-up and sign-in pages call, as the JSON contract Thrust's copy of the React auth client will use (D-022):GET /auth/get-csrf-token/{"csrf_token"}and the CSRF cookiePOST /auth/email-check/{"existing", "status": "CREDENTIAL"}, or Plane's 400EMAIL_REQUIRED/INVALID_EMAILPOST /auth/sign-up/{"redirect_path"}and the session cookies, or 400 witherror_code,error_message,emailPOST /auth/sign-in/Plane's order of checks is kept (required, valid email, taken, strong password), and the fixtures pin it with exchanges that have two faults at once.
Underneath: core gets
sign_up,email_exists,is_valid_emailandpassword_is_strong. The ports and both adapters getinsert_user(a taken email or id is aConflictfrom the unique index).thrust-apimakes its cookie helpers public so the compat routes spell the cookies the same way.Owner decisions needed
Both are recorded as deviations and marked pending owner confirmation:
{"redirect_path"}on success, 400 (429 for 5900) with the pin's error dict on failure, and a stricternext_paththat is percent-encoded when kept (the pin writes it into the query raw, so a&or#corrupts the query). This is the contract PR 8 (the React client change) will code against.zxcvbncrate is the alternative.Gaps you should know about (G-16)
email-check, sign-in and sign-up to 10 a minute per IP. Thrust keeps only sign-in's per-email limit, so sign-up andemail-checkare unthrottled, andemail-checktells anyone whether an email has an account, as the pin does. Core never sees the address, and a global limit would let anyone lock everyone out.ENABLE_SIGNUP, magic-code and OAuth codes do not exist.Controls (each shown failing)
parity_s05_sign_upfails:recorded 5030, answered 5021insert_userwithON CONFLICT DO NOTHINGUserInsert{EmailTaken}:got Ok(()), want conflictSet-Cookienext_pathor a password changed in a fixturetokioadded to the compat cratescripts/check-deps.shexits 1 (shown in #79; the crate is covered)Mutation testing (cargo-mutants 27.1.0, nextest 0.9.140):
thrust-compat-planethrust-core(--in-diff, the new code)insert_userThe first runs found seven real gaps: the
||in both "required fields" checks (no exchange had one field present and one missing, so I recorded them),origin()for the base URLs (the normaliser erases them, so a hermetic test now setsHostandX-Forwarded-Proto), the exact-5-distinct-characters password boundary, a top-level domain with a digit, and a deadlen > 4clause that I removed. Not mutated: the Postgres adapter, which the generated model covers.Recording
tools/compat-record/record.pynow records the whole journey on a fresh stack, paced under the pin's throttle (about three minutes), and refuses a stack that has been used.tools/compat-record/fresh-oracle.shrecreates one (ORACLE_DIRpoints at the fork checkout; the pin tag is local to the fork). Recordings on two independent fresh stacks are byte-identical, which closes the gap I left open in #79.The harness replays the journey in order and projects the pin's 302 onto Thrust's JSON by the rules in
tests/common/mod.rs. A sign-in or sign-up that the recording says worked must set the session cookie, and one that failed must not.Verified
cargo nextest run --workspace: 1228 passed.scripts/contract.sh native-memoryandnative-pg: 44 of 44 (EXPECT_MAIN39 to 44). The other two targets are for CI.cargo nextest run --ignore-default-filter -E 'binary(pg_adapter)', 13 passed.scripts/check-deps.sh: no forbidden dependency;cargo check -p thrust-worker --target wasm32-unknown-unknown: builds.CLEAN, after one re-run of themutantsjob. Its first run reportedcsrf-switch-ignored-when-off ... did not run (exit=4):contract.shexit 4 means the target never became healthy or exited early, and the CI log does not show why. I could not reproduce it: the same mutant build (THRUST_SERVER_FEATURES=mutant_csrf_always scripts/contract.sh native-memory csrfoff) is killed locally (3 tests fail, exit 101), and the other eight mutants were killed in the failing run. I believe it was a startup flake (a random port inpick_portis one candidate), but I have not proved that. If it recurs,mutants.shshould keep the server log of a mutant that does not start.Effort
Modelled for the rows (research/0003 §8.1): S03 0.3, S04 0.8, S05 1.5, S06 1.5, so 4.1 pd of
auth-redirect, which the model prices as 302 emulation; this PR builds JSON instead, plus a use-case, an adapter method and a password rule the model excludes. I did not time the work, so there is no actual pd to report.Refs: plane-byd.12.2
🤖 Generated with Claude Code