Public: anyone can read this; the crew can change it.

The child forge's linked-sub sign-in test passes on a loaded check host #9985

Merged opened this

Check · Review · Land · Live done — Landed and live in production.

Merged

scout/forge:scout/9978-the-child-forge-s-linked-sub-sign-in-tes → main 1 commit fork

  • Merged. scout/9978-the-child-forge-s-linked-sub-sign-in-tes was merged into main as 13264df.

Review

Sign in to review this change.
1 file changed +21 −4
test/forge-signin-signup.test.ts +21 −4
@@ -27,18 +27,34 @@ const cookies: Record<string, string> = {};
2727 const cookieOf = (res: Response, name: string) =>
2828 res.headers.getSetCookie().map((c) => c.split(";")[0]!).find((c) => c.startsWith(`${name}=`));
2929
30 /**
31 * The redirect one hop answered with, or a throw that names the hop, its
32 * status and the start of its body: a red here says which step went wrong
33 * (#9978), never a bare "null is not a URL".
34 */
35 async function hop(where: string, res: Response, to: string): Promise<URL> {
36 const location = res.headers.get("location");
37 if (res.status === 303 && location !== null && new URL(location, to).href.startsWith(to)) return new URL(location, to);
38 const text = await res.text();
39 const main = text.includes("<main") ? text.slice(text.indexOf("<main")) : text;
40 const body = main.replace(/<[^>]*>/g, " ").replace(/\s+/g, " ").trim().slice(0, 300);
41 throw new Error(`${where}: ${res.status}, location ${location ?? "none"}, not a 303 to ${to}; body: ${body}`);
42 }
43
3044 /** One full sign-in at the child as the parent's person with `cookie`; the callback's response. */
3145 async function through(cookie: string): Promise<Response> {
3246 const start = await fetch(`${cs.url}/signin/parent`, { redirect: "manual" });
33 const to = new URL(start.headers.get("location")!);
47 const to = await hop("the child's /signin/parent", start, `${ps.url}/oauth/authorize?`);
3448 const consent = await fetch(`${ps.url}/oauth/authorize`, {
3549 method: "POST",
3650 redirect: "manual",
3751 headers: { cookie, origin: ps.url },
3852 body: new URLSearchParams({ ...Object.fromEntries(to.searchParams), decision: "allow" }),
3953 });
40 const back = new URL(consent.headers.get("location")!);
41 return fetch(`${cs.url}${back.pathname}${back.search}`, { redirect: "manual", headers: { cookie: cookieOf(start, "forge_rp")! } });
54 const back = await hop("the parent's consent", consent, `${cs.url}/signin/parent/callback?`);
55 const state = cookieOf(start, "forge_rp");
56 if (state === undefined) throw new Error("the child's /signin/parent set no forge_rp cookie");
57 return fetch(`${cs.url}${back.pathname}${back.search}`, { redirect: "manual", headers: { cookie: state } });
4258 }
4359
4460 const post = (path: string, body: unknown) =>
@@ -71,7 +87,8 @@ beforeAll(async () => {
7187 const actor = seeded.value.id;
7288 // Two sign-ups a minute from this source, shared by every door.
7389 setLimit(child.db, "signup.per_source", 2, actor);
74 });
90 // Two forges boot here: on a loaded check host that outlasts bun's 5 s default.
91 }, 30_000);
7592
7693 afterAll(async () => {
7794 ps.stop();

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs