feat(e2e): un-fixme OIDC token-flow via replayed OP cookies (PMS-143) #132
Loading…
Reference in a new issue
No description provided.
Delete branch "feat/pms-143-oidc-unfixme"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Summary
Closes PMS-143. The OIDC PKCE token-flow test (
e2e/tests/oidc.spec.ts) was quarantined in PMS-140 because theapiproject's request context only carried a Bearer header. Bunyip's/oauth2/authorizegates code minting on a server-validated OP session cookie (bunyip PR #67), so authorize 302'd to the hub login screen instead of the registered redirect_uri and the test failed at thestate mismatchassertion.This PR adds an OP-cookie replay path through the setup project and switches the OIDC test onto it.
Changes
e2e/tests/global.setup.ts: after the bearer is captured, also persist the browser context's cookies filtered to the OP host and its parent domain (e.g.api.a8n.systemsplusa8n.systems) toe2e/.auth/op-state.jsonin PlaywrightstorageStateshape. Throws if zero cookies match, with a diagnostic that names what was actually in the context.e2e/lib/auth-state.ts: exposeOP_STORAGE_STATE_FILEandreadOpStorageState(). Both file-missing and empty-cookies cases throw with messages that point at the likely cause (setup did not run, or filter excluded everything).e2e/lib/fixtures.ts: add anoidcTestfixture that builds a request context with the replayed OP cookies viastorageStateand deliberately omits the Bearer header. The OP reads the session from the cookie; an inbound bearer with the wrong audience would just be noise.e2e/tests/oidc.spec.ts: switch to theoidcTestfixture (import { oidcTest as test } from '../lib/fixtures'), droptest.fixme, replace the historical PMS-140 quarantine comment with a short PMS-143 note.e2e/README.md: drop the OIDCtest.fixmeannotation in theWhat it coverstable; update the harness-shape paragraph to describe the new dual-fixture layout (bearer for PSA-API specs, storageState for OIDC)..auth/is already ine2e/.gitignoresoop-state.jsonwill not be committed.Why this works against bunyip PR #67
The OP session cookie is named
bunyip_op_session(bunyip/crates/bunyip-domain/src/middleware/auth.rs:248), opaque, validated server-side. The hub login handler sets it alongsideaccess_token/refresh_tokenon a successful login. After the setup project'sloginViaSpacompletes, all three cookies live in the browser context; capturing them intoop-state.jsonand replaying viastorageStategives the OIDC test the same session signal a real browser would carry to/oauth2/authorize.Test plan
Checkgreen.e2epost-merge: setup logspersisted N OP cookie(s)line, OIDC test passes the full happy path (authorize 302 -> code -> token -> userinfo -> refresh).Rollback plan
If the cookie replay does not establish the OP session on staging (e.g. bunyip pins sessions to user-agent or IP), re-fixme
oidc.spec.tsand fall back to the alternative the spec named: drive the OIDC flow through a real Page that already completed the SPA login. That trade-off costs a second login per CI run (rate-limit pressure) but is guaranteed to inherit the session.Setup persists OP cookies correctly (`persisted 3 OP cookie(s) (api.a8n.systems, a8n.systems)`), but the authorize call returns HTTP 400 instead of the expected 3xx. The current assertion only reports the status code, so the actual rejection (invalid_request? unknown client_id? unregistered redirect_uri?) was invisible. Replace the `expect(...).toContain(status)` with an explicit branch that, on a non-3xx response, throws an error carrying: - the configured `client_id` and `redirect_uri` (so the most likely mismatch is at hand without grepping CI secrets) - the response `content-type` and the first 2000 chars of the body (bunyip's OIDC errors are JSON `{error, error_description}`, and AppError-derived 400s emit a similar text body, both small enough to fit) Comment names the three most plausible root causes so the next iteration off the diagnostic is targeted, not speculative. #PMS-143