Skip to content

test(contract): sign-in, the CSRF token and sign-out go through Plane's routes - #136

Merged
aRustyDev merged 2 commits into
mainfrom
refactor/contract-auth-on-compat
Nov 12, 2026
Merged

aRustyDev merged 2 commits into
mainfrom
refactor/contract-auth-on-compat

Conversation

@aRustyDev

Copy link
Copy Markdown
Owner

What

Stage 3 of moving the contract suite off the slice (G-26 in docs/src/testing/status.md is the ledger; stages 1, 2a and 2b were #122, #125 and #128). The sign-in, CSRF and sign-out tests go through Plane's routes, the ones the stock app calls, and not the slice's.

Part of #58 (not closing it).

What moved

  • Target::sign_in and sign_in_raw post to POST /auth/sign-in/. Plane's answer names no user and holds no token (only where to go), so the session's user is the caller's.
  • The CSRF endpoint test goes to GET /auth/get-csrf-token/; sign-out to POST /auth/sign-out/ (X06, feat(web): the auth client posts JSON, and POST /auth/sign-out/ answers it (X06) #130).
  • A session is read back through GET /api/users/me/ (Target::me, me_status), not the slice's session info or a slice work-item list. The three tests of the slice's that stay (sign-out-everywhere, the API keys, OIDC) use it as their probe too.
  • The cookie and CSRF tests (both modes) make and change a work item through Plane's routes (S48, X03, read by S47), not the slice's.
  • The credential matrix (4 kinds x states x 3 methods x 3 token positions = 126 requests, both modes) runs on the same routes. Those take a bearer session, an X-Api-Key and the cookie through thrust_api::Authed, the extractor the slice's routes use, so the table is the credential layer's and not a route's.

What the move had to accept

Each is a difference of the Plane route, not of the test:

  • A wrong password and an unknown email are two answers (5065 and 5060, the pin's, G-16); the slice's sign-in had one body for both and its test asserted that. The rule is core's (every_failed_sign_in_is_the_same_error) and is no longer an HTTP assertion. A refused sign-in is a 400, where the slice's was a 401.
  • A sign-out is a 200 with where to go, and the same answer for a session that is already over or none (D-036); the slice's was a 204, then a 401.
  • The matrix's third method is a change (X03, 204), not a delete: Plane's internal API has no delete route here. Its effect check reads the project's list afterwards: the shared victim is as it was, each change the table let through took effect, and the rows are exactly the ones the table predicts.

No test was deleted or weakened to get here: each assertion either moved, or is replaced by the pin's answer for the same property (and the commit message says which).

Still the slice's

Sign-out-everywhere, the API-key routes, the OIDC login, and the tests whose vehicle is a slice work item (a_revoked_session_is_rejected_on_the_next_request, a_session_is_not_bound_to_a_workspace, the slice's model and access matrix, the outbox, redelivery, sweeper and panic tests, the create limit, the bench).

Two things this leaves behind (both in G-26): the slice's own sign-in, sign-out and CSRF routes are called by no test after this, and scripts/measure-argon2.sh (run by hand against a deployed Worker) still posts to the slice's sign-in, so it has to move to /auth/sign-in/ before the slice goes.

Evidence (2026-11-12, local)

  • scripts/contract.sh <target> main: 65 passed, 65 expected, and csrfoff: 6 of 6, on native-memory, native-pg, worker-memory and worker-cf. No test was added or removed, so EXPECT_MAIN (65) and stage2-contract.sh do not change and this PR does not touch them (so it should not conflict on them the way each earlier stage did).
  • Controls, native-memory, each must fail its pass and does:
    • ignore-revoked (main): 7 tests fail, among them both compat sign-out tests, the moved sign_out_ends_that_session_only, sign_out_everywhere_... and the matrix;
    • skip-csrf (main): 5, among them the moved a_cookie_authenticated_mutation_needs_the_csrf_token, compat_sign_out_...needs_the_csrf_token... and the matrix;
    • csrf-switch-ignored-when-on (main): the same 5;
    • csrf-switch-ignored-when-off (csrfoff): 3 of the 6 csrf_off_ tests, among them the matrix.
  • The matrix's new effect check was broken on purpose (the expected row count and the shared victim's name each off by one): the test failed naming both ("rows in the project: 15, the table lets 15 ..." with the count off, and "a refused change renamed the shared victim"). Restored.
  • cargo fmt --all --check and cargo clippy -p thrust-contract-tests --all-targets -- -D warnings: clean.
  • Not run locally: the whole scripts/mutants.sh (the mutants job runs it; the four mutants above are its CSRF and session ones, run by hand the way it runs them).
  • One failure on the first run, fixed: oidc_there_is_no_provisioning_and_a_deactivated_user_cannot_log_in asserted the slice's 401 for a sign-in as an email nobody has; Plane's route is a 400 with USER_DOES_NOT_EXIST (5060), which says "no user was made" more exactly, and the test asserts that now.

Not done

The compat test compat_csrf_token_is_json_and_sets_the_csrf_cookie (S03) is a strict subset of the moved the_csrf_endpoint_hands_out_a_fresh_token_in_json_and_in_the_cookie (the same route, now also the cookie's attributes, the hex lengths and one cookie only). It stays as it is, so this PR is a move and not a merge of tests; folding them is a one-line follow-up if wanted.

🤖 Generated with Claude Code

aRustyDev and others added 2 commits November 11, 2026 22:38
…'s routes

The sign-in, CSRF and sign-out tests went through the slice's routes
(`/api/_slice/auth/sign-in/email`, `/auth/csrf`, `/auth/sign-out`) and used a
slice work item as the vehicle of a cookie mutation. They go through the routes
the stock app calls now: `POST /auth/sign-in/`, `GET /auth/get-csrf-token/` and
`POST /auth/sign-out/` (`thrust-compat-plane`), a session is read back through
`GET /api/users/me/`, and a cookie mutation is a work item made (S48) or changed
(X03) through Plane's routes. Those take a bearer session, an API key and the
cookie through `thrust_api::Authed`, the extractor the slice's routes use, so the
credential matrix (126 requests, both modes) is still the credential layer's
table and not a route's.

`Target::sign_in` and `sign_in_raw` are Plane's. The session's user is the
caller's (Plane's answer names none and holds no token, only where to go).

What the move had to accept, each a difference of the Plane route and not of
the test:

- A wrong password and an unknown email are two answers (5065 and 5060, the
  pin's, G-16); the slice's sign-in had one body for both and the test said so.
  That rule is core's (`every_failed_sign_in_is_the_same_error`) and is no longer
  an HTTP assertion. A refused sign-in is a 400, where the slice's was a 401.
- A sign-out is a 200 with where to go, and the same answer for a session that
  is already over or none (D-036); the slice's was a 204, then a 401.
- The matrix's third method is a change (X03, 204), not a delete: Plane's
  internal API has no delete route here. Its effect check reads the project's
  list afterwards: the shared victim is as it was, each change that was let
  through took effect, and the rows are exactly the ones the table predicts.

Still the slice's, because no Plane route replaces it: sign-out-everywhere, the
API-key routes and the OIDC login (their probes of a live session use `me` now).
The slice's own sign-in, sign-out and CSRF routes are called by no test after
this.

Measured (2026-11-12): `scripts/contract.sh native-memory main` 65 of 65 and
`csrfoff` 6 of 6; the four mutants the moved tests answer for fail their pass
(`ignore-revoked`: 7 tests, among them both compat sign-out tests, the moved
`sign_out_ends_that_session_only` and the matrix; `skip-csrf` and
`csrf-switch-ignored-when-on`: 5, among them the moved CSRF test and the matrix;
`csrf-switch-ignored-when-off`: 3 of the 6 `csrf_off_` tests). The matrix's new
effect check was broken on purpose (a row count and the shared victim's name
off by one) and the test failed naming both.

Refs: #58
Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
…n Plane's routes

G-26 lists stage 3 as moved, with the differences the move accepted (two answers
for a refused sign-in, a 400 where the slice's was a 401, a sign-out that is a
200 and the same for a session already over, a change where the matrix had a
delete) and what is still the slice's. It also records two things the move
leaves behind: the slice's own sign-in, sign-out and CSRF routes are called by no
test, and `scripts/measure-argon2.sh` still posts to the slice's sign-in. G-12
and the contract-suite page say which routes the identity tests use, and the
defect matrix's X23 row no longer claims an HTTP test of the one answer for every
refusal (core's test has it; Plane's route differs on purpose).

Refs: #58
Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
@aRustyDev
aRustyDev enabled auto-merge (squash) November 12, 2026 03:43
@aRustyDev
aRustyDev merged commit c3a5b92 into main Nov 12, 2026
64 of 66 checks passed
@aRustyDev
aRustyDev deleted the refactor/contract-auth-on-compat branch November 12, 2026 03:54
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.

1 participant