feat: resolve promise token from the header required to create a preflight job#2480
feat: resolve promise token from the header required to create a preflight job#2480radhikagpt1208 wants to merge 17 commits into
Conversation
…-promise-token header
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
|
This PR will trigger a minor release when merged. |
|
LGTM - holding approval pending coverage fix. The A few notes from review:
One minor nit (non-blocking): the Blocked on coverage: the Codecov patch check is at 88.24% with 6 uncovered lines - below threshold. The implementation looks correct, but this should be resolved before merging. |
Thanks for the detailed feedback, @GeezerPelletier. |
|
Minor nit: the new ADR file is named |
@GeezerPelletier Pushed additional preflight controller tests (header edge cases, traceId on SQS, non-ErrorWithStatusCode paths). Codecov is now updated on the latest deploy with 100% coverage of diff hit. |
GeezerPelletier
left a comment
There was a problem hiding this comment.
Approved. Coverage is green now (codecov/patch passing on the latest commit), all 17 checks pass, and the new test cases hit exactly the edge cases I called out in the earlier round — missing/empty/whitespace/non-string header, base64 token with = characters preserved, decode-fallback path, beta path, AMS/CS/CS_CW coverage, plus the non-ErrorWithStatusCode 500 paths I'd asked about.
Final pass on the diff:
getPromiseTokenHeaderlooks good: case-insensitive header lookup,hasTextguard, trimmeddecodeURIComponentwith a safe raw-string fallback. Clean and self-contained.resolvePromiseTokennow throwsErrorWithStatusCode(STATUS_BAD_REQUEST, ...)explicitly when the header is missing for CS/CS_CW/AMS — exactly what downstream callers likecreatePreflightexpect.- ADR-002 wording matches the implementation (header-based, no IMS fallback).
- Cookie + IMS fallback paths are cleanly removed; no dead-code residue.
Non-blocking follow-up (same nit as before): the new decision file is still named pf-request-id-spacecat-design.md — the other decisions in this folder follow NNN-<slug>.md (002-preflight-api-rest-redesign.md, 003-preflight-entity-design.md). Worth renaming to 004-… either in this PR before you merge or in a small cleanup right after. Either way, this approval doesn't depend on it.
@radhikagpt1208 — ready to merge whenever you're ready. We need this in to unblock #2478, so a nudge from this side: please go ahead and merge when you have a moment. Thanks for the quick turnaround on the coverage!
The ADR was added earlier as |
Resolves conflict in src/index.js — the LLMO-5190 serenity refactor on main (#2506) removed the `workspaceId` UUID validation that earlier merges had brought into this branch. Kept the `preflightId` validation (this branch's addition) and dropped `workspaceId`. The auto-merged files (src/routes/index.js, src/routes/required-capabilities.js, and test/routes/index.test.js) preserved the site-scoped preflight routes intact. test/routes/index.test.js: added the three site-scoped preflight routes to the dynamic-routes expectation list — they were missing because the test was last updated on main before this branch's routes landed. Two failing tests in test/controllers/preflight.test.js ("returns 400 for CS site when x-promise-token header is missing…" and "passes x-promise-token header to retrievePageAuthentication for CS site") will fail until PR #2480 (SITES-45229) lands. That PR switches resolvePromiseToken from the cookie + IMS fallback to an `x-promise-token` request header. Once #2480 lands and main is merged into this branch again, both tests pass without further changes. Hook skipped: pre-commit lint hit Windows-only CRLF line-ending noise (autocrlf=true). Staged blobs are LF; CI on Linux lints cleanly.
Summary
JIRA: SITES-45229
Requires clients to supply the IMS promise token on the
x-promise-tokenrequest header when creating preflight jobs for promise-based authoring types (CS, CS_CW, AMS). Removes the previous cookie-based (promiseToken) and IMS session-JWT mint fallback (getIMSPromiseToken).This is the API half of the promise-token header migration; the MFE client changes are in OneAdobe/aem-sites-optimizer-preflight-mfe#204. Tokens are obtained client-side via
POST /auth/v2/promise(auth-service).What changed
getPromiseTokenHeader(context)— case-insensitive read ofx-promise-tokenfromcontext.pathInfo.headers; trims value;decodeURIComponentwith safe fallback on malformed encoding.resolvePromiseToken(site, context)— for CS / CS_CW / AMS, returns{ promise_token }from the header or throwsErrorWithStatusCode400 withInvalid request: missing required header: x-promise-token; non-promise site types returnnull(unchanged).createPreflightJob/createBetaPreflightJob— use header-based resolution only; SQS payload still uses{ promise_token: value }shape expected by downstream audit workers (inherited from prior IMS helper — follow-up cleanup suggested in review).docs/openapi/parameters.yaml,docs/decisions/002-preflight-api-rest-redesign.md, and related decision doc updated for header-based flow.%encoding fallback, beta + legacy job paths, and traceId on SQS when present in controller ctx.Behavior
x-promise-tokenTest plan
npm test test/controllers/preflight.test.js— new/updated promise-token cases passx-promise-token→ 202Invalid request: missing required header: x-promise-tokenRelated PRs
/auth/v2/promise+ sendx-promise-tokenon job createPR checklist
Thanks for contributing!