Public: anyone can read this; the crew can change it.
A forge link's landing page works with no script at 360 px and says what it is in one sentence #12438
Check · Review · Land · Live done — Landed and live in production.
scout/forge:scout/12416-a-forge-link-s-landing-page-works-with-n → main 7 commits fork 1 thread · 1 unresolved
9 files
changed +211
−62
docs/features/forge-link-states.md +22
| @@ -28,3 +28,25 @@ name. A claimed forge is never marked. | ||
| 28 | 28 | |
| 29 | 29 | - The first tell's time: the heartbeat carries only the latest tell. |
| 30 | 30 | - A one-call resend in MCP: `claim_link` is that call. |
| 31 | ||
| 32 | ## What a client's link page says | |
| 33 | ||
| 34 | `/claim` (tested in `test/forge-link-landing.test.ts`, no cookie, no script): | |
| 35 | ||
| 36 | - **A good link** is server-rendered under 20 KB: one sentence naming who made | |
| 37 | the forge for them ("alice made maria for you."), a username and one button | |
| 38 | (the passkey button, or a password form where the browser cannot make one). | |
| 39 | The page has no top bar or footer. The link's secret rides the `#` | |
| 40 | fragment, so it is in no request, no outgoing link and no Referer; a script | |
| 41 | moves it into a hidden field. **With no script** the server cannot see a | |
| 42 | fragment, so a `<noscript>` field asks for the part of the link after the `#` | |
| 43 | to be pasted, beside the password form; the test submits that form and | |
| 44 | succeeds. The page sends the security floor and `Referrer-Policy`. | |
| 45 | - **The terminal** has no claim screen: a claim link is for a client in a | |
| 46 | browser, and the terminal has no account to claim into before it exists. | |
| 47 | - **A revoked, expired or unknown link** answers the same 404 page, word for | |
| 48 | word: "Sorry, this link does not work any more. Please ask whoever sent it | |
| 49 | for a new one." It names no sender and does not say which of the three it | |
| 50 | is. A link already used still says so and offers sign-in, since its owner | |
| 51 | needs that. | |
| 52 | - Link validation itself is unchanged. |
src/web/pages/claim.ts +39 −44
| @@ -100,31 +100,25 @@ function dead( | ||
| 100 | 100 | ctx: Ctx, |
| 101 | 101 | state: Exclude<ClaimState["state"], "ok">, |
| 102 | 102 | sender?: string, |
| 103 | endedAt?: string, | |
| 104 | 103 | own = false, |
| 105 | 104 | ): Response { |
| 106 | 105 | const ask = sender === undefined ? "whoever sent it" : sender; |
| 106 | // A stranger must not learn which of unknown, expired or revoked this is: | |
| 107 | // one status, one title, one kind sentence, naming no one. | |
| 108 | const gone = { | |
| 109 | status: 404, | |
| 110 | title: "This link does not work", | |
| 111 | text: "Sorry, this link does not work any more. Please ask whoever sent it for a new one.", | |
| 112 | }; | |
| 107 | 113 | const says = { |
| 108 | unknown: { | |
| 109 | status: 404, | |
| 110 | title: "This is not a forge link", | |
| 111 | text: "The link may have been cut short, or replaced by a newer one. Ask whoever sent it for the latest.", | |
| 112 | }, | |
| 114 | unknown: gone, | |
| 113 | 115 | used: { |
| 114 | 116 | status: 410, |
| 115 | 117 | title: "This link has already been used", |
| 116 | 118 | text: `Each link works once. If it was you, sign in with the account you made; if not, ask ${ask} to send you a new one.`, |
| 117 | 119 | }, |
| 118 | expired: { | |
| 119 | status: 410, | |
| 120 | title: "This link has expired", | |
| 121 | text: `It stopped working${endedAt === undefined ? "" : ` on ${whenWords(endedAt)}`}. Ask ${ask} to send you a new one.`, | |
| 122 | }, | |
| 123 | revoked: { | |
| 124 | status: 410, | |
| 125 | title: "This link has ended", | |
| 126 | text: `Whoever sent it took it back. Ask ${ask} to send you a new one.`, | |
| 127 | }, | |
| 120 | expired: gone, | |
| 121 | revoked: gone, | |
| 128 | 122 | owned: { |
| 129 | 123 | status: 410, |
| 130 | 124 | title: "This forge already has an owner", |
| @@ -133,10 +127,10 @@ function dead( | ||
| 133 | 127 | }[state]; |
| 134 | 128 | // The person who started this forge themselves has no sender to ask. |
| 135 | 129 | const mine: Partial<Record<typeof state, string>> = { |
| 136 | unknown: "The link may have been cut short or replaced. Start the forge again from the home page.", | |
| 130 | unknown: "This link does not work any more. Start the forge again from the home page.", | |
| 137 | 131 | used: "Each link works once. If it was you, sign in with the account you made. Otherwise start a forge of your own from the home page.", |
| 138 | expired: "Your link stopped working. Start the forge again from the home page.", | |
| 139 | revoked: "This link has ended. Start the forge again from the home page.", | |
| 132 | expired: "This link does not work any more. Start the forge again from the home page.", | |
| 133 | revoked: "This link does not work any more. Start the forge again from the home page.", | |
| 140 | 134 | }; |
| 141 | 135 | if (own) says.text = mine[state] ?? says.text; |
| 142 | 136 | return page( |
| @@ -216,7 +210,7 @@ function claimForm( | ||
| 216 | 210 | return html`<div class="narrow"> |
| 217 | 211 | ${pageHead("This forge is yours")} |
| 218 | 212 | <section class="settings-block"> |
| 219 | <p class="mb">${spawned.org.username} was made for you. Your account will be its admin, so it can change everything here.</p> | |
| 213 | <p class="mb">${spawner === undefined ? `${spawned.org.username} was made` : `${spawner.username} made ${spawned.org.username}`} for you. Your account will be its admin, so it can change everything here.</p> | |
| 220 | 214 | ${expiresAt === undefined |
| 221 | 215 | ? null |
| 222 | 216 | : html`<p class="mb" id="claim-expiry">This link works until |
| @@ -239,15 +233,17 @@ function claimForm( | ||
| 239 | 233 | */ |
| 240 | 234 | function accountForm(ctx: Ctx, action: "/claim" | "/welcome", values: Values, errors: Errors): Html { |
| 241 | 235 | return html`<form method="post" action="${action}"> |
| 242 | <div id="claim-token-field" ${values.token ? html`hidden` : null}> | |
| 243 | ${formField({ | |
| 244 | label: "Link code", | |
| 245 | name: "token", | |
| 246 | value: values.token ?? "", | |
| 247 | required: true, | |
| 248 | hint: "The part of your link after the #. Opening the link fills it in.", | |
| 249 | })} | |
| 250 | </div> | |
| 236 | ${values.token | |
| 237 | ? html`<input type="hidden" name="token" value="${values.token}" />` | |
| 238 | : html`<input type="hidden" name="token" id="claim-token" /> | |
| 239 | <noscript> | |
| 240 | ${formField({ | |
| 241 | label: "Link code", | |
| 242 | name: "code", | |
| 243 | required: true, | |
| 244 | hint: "Without script, paste the part of your link after the #.", | |
| 245 | })} | |
| 246 | </noscript>`} | |
| 251 | 247 | ${formField({ |
| 252 | 248 | label: "Username", |
| 253 | 249 | name: "username", |
| @@ -299,18 +295,16 @@ function accountForm(ctx: Ctx, action: "/claim" | "/welcome", values: Values, er | ||
| 299 | 295 | /** |
| 300 | 296 | * The fragment link's page script: take the claim code from `` into the |
| 301 | 297 | * form and drop it from the address bar, so it is never in a request line, |
| 302 | * a Referer, the history or a screenshot of the URL. Without JavaScript the | |
| 303 | * code field stays visible and takes a paste. | |
| 298 | * a Referer, the history or a screenshot of the URL. Without JavaScript a | |
| 299 | * <noscript> code field takes a paste (the server cannot see a fragment). | |
| 304 | 300 | */ |
| 305 | 301 | const fragmentJs = /* js */ ` |
| 306 | 302 | (function () { |
| 307 | var field = document.querySelector('input[name="token"]'); | |
| 303 | var field = document.getElementById('claim-token'); | |
| 308 | 304 | if (!field) return; |
| 309 | 305 | var code = location.hash.slice(1); |
| 310 | 306 | if (!code) return; |
| 311 | 307 | field.value = code; |
| 312 | var box = document.getElementById('claim-token-field'); | |
| 313 | if (box) box.hidden = true; | |
| 314 | 308 | history.replaceState(null, '', location.pathname + location.search); |
| 315 | 309 | })(); |
| 316 | 310 | `; |
| @@ -324,7 +318,7 @@ export const welcomePage = (ctx: Ctx): Promise<Response> => fragmentPage(ctx, tr | ||
| 324 | 318 | async function fragmentPage(ctx: Ctx, own: boolean): Promise<Response> { |
| 325 | 319 | notePhase(ctx.request, "session", takeSessionTime(ctx.request)); |
| 326 | 320 | const spawned = await timePhaseAsync(ctx.request, "spawned", () => spawnedOrg(ctx.app)); |
| 327 | if (spawned === undefined) return timePhase(ctx.request, "render", () => dead(ctx, "unknown", undefined, undefined, own)); | |
| 321 | if (spawned === undefined) return timePhase(ctx.request, "render", () => dead(ctx, "unknown", undefined, own)); | |
| 328 | 322 | const { spawner } = timePhase(ctx.request, "owners", () => owners(ctx, spawned)); |
| 329 | 323 | // The forge has one link at a time, so its state says nothing about any |
| 330 | 324 | // particular code: a stale or made-up code only ever meets "unknown" on the POST. |
| @@ -334,7 +328,6 @@ async function fragmentPage(ctx: Ctx, own: boolean): Promise<Response> { | ||
| 334 | 328 | ctx, |
| 335 | 329 | link.state === "used" ? "used" : link.revokedAt !== null ? "revoked" : "expired", |
| 336 | 330 | own ? undefined : spawner?.username, |
| 337 | link.expiresAt, | |
| 338 | 331 | own, |
| 339 | 332 | ); |
| 340 | 333 | const rendering = performance.now(); |
| @@ -343,6 +336,7 @@ async function fragmentPage(ctx: Ctx, own: boolean): Promise<Response> { | ||
| 343 | 336 | title: own ? "Make your account" : "This forge is yours", |
| 344 | 337 | body: claimForm(ctx, spawned, spawner, {}, {}, link?.expiresAt, own), |
| 345 | 338 | scriptJs: fragmentJs + passkeyJs, |
| 339 | bare: true, | |
| 346 | 340 | }); |
| 347 | 341 | notePhase(ctx.request, "render", performance.now() - rendering); |
| 348 | 342 | return response; |
| @@ -376,10 +370,10 @@ const emailGiven = (ctx: Ctx, raw: string): string => (mailConfigured(ctx.app) ? | ||
| 376 | 370 | |
| 377 | 371 | /** Why a passkey challenge was refused, in the passkey note's plain words. */ |
| 378 | 372 | const LINK_REFUSED: Record<Exclude<ClaimState["state"], "ok">, string> = { |
| 379 | unknown: "This is not a forge link.", | |
| 373 | unknown: "This link does not work any more.", | |
| 380 | 374 | used: "This link has already been used.", |
| 381 | expired: "This link has expired.", | |
| 382 | revoked: "This link has ended.", | |
| 375 | expired: "This link does not work any more.", | |
| 376 | revoked: "This link does not work any more.", | |
| 383 | 377 | owned: "This forge already has an owner.", |
| 384 | 378 | }; |
| 385 | 379 | |
| @@ -397,7 +391,7 @@ export async function claimOptions(ctx: Ctx): Promise<Response> { | ||
| 397 | 391 | const spawned = await spawnedOrg(ctx.app); |
| 398 | 392 | if (spawned === undefined) return refuse(404, LINK_REFUSED.unknown); |
| 399 | 393 | const state = readClaim(ctx.app.db, spawned.org.id, str(data.token)).state; |
| 400 | if (state !== "ok") return refuse(state === "unknown" ? 404 : 410, LINK_REFUSED[state]); | |
| 394 | if (state !== "ok") return refuse(state === "used" || state === "owned" ? 410 : 404, LINK_REFUSED[state]); | |
| 401 | 395 | const username = str(data.username).trim(); |
| 402 | 396 | const bad = problems(ctx, spawned, username, emailGiven(ctx, str(data.email))); |
| 403 | 397 | const first = bad.username ?? bad.email; |
| @@ -414,15 +408,15 @@ async function submit(ctx: Ctx, own: boolean): Promise<Response> { | ||
| 414 | 408 | const form = await readForm(ctx); |
| 415 | 409 | if (form instanceof Response) return form; |
| 416 | 410 | const spawned = await spawnedOrg(ctx.app); |
| 417 | if (spawned === undefined) return dead(ctx, "unknown", undefined, undefined, own); | |
| 411 | if (spawned === undefined) return dead(ctx, "unknown", undefined, own); | |
| 418 | 412 | const orgId = spawned.org.id; |
| 419 | 413 | // From the form's body — never from the path or a query string, which |
| 420 | 414 | // proxies and logs would keep. |
| 421 | const token = field(form, "token"); | |
| 415 | const token = field(form, "token") || field(form, "code"); | |
| 422 | 416 | const before = readClaim(ctx.app.db, orgId, token); |
| 423 | 417 | const { spawner } = owners(ctx, spawned); |
| 424 | 418 | if (before.state !== "ok") |
| 425 | return dead(ctx, before.state, own ? undefined : spawner?.username, linkOf(ctx.app.db)?.expiresAt, own); | |
| 419 | return dead(ctx, before.state, own ? undefined : spawner?.username, own); | |
| 426 | 420 | |
| 427 | 421 | const values = { |
| 428 | 422 | username: field(form, "username"), |
| @@ -436,6 +430,7 @@ async function submit(ctx: Ctx, own: boolean): Promise<Response> { | ||
| 436 | 430 | title: own ? "Make your account" : "This forge is yours", |
| 437 | 431 | body: claimForm(ctx, spawned, spawner, values, e, linkOf(ctx.app.db)?.expiresAt, own), |
| 438 | 432 | scriptJs: fragmentJs + passkeyJs, |
| 433 | bare: true, | |
| 439 | 434 | }, |
| 440 | 435 | 422, |
| 441 | 436 | ); |
| @@ -463,7 +458,7 @@ async function submit(ctx: Ctx, own: boolean): Promise<Response> { | ||
| 463 | 458 | (founder === undefined && !takesName) || credential !== undefined ? "" : await Bun.password.hash(password, "argon2id"); |
| 464 | 459 | // Spent first, in one statement: of two people on one link, one wins. |
| 465 | 460 | const spent = burnClaim(ctx.app.db, orgId, token); |
| 466 | if (spent.state !== "ok") return dead(ctx, spent.state, undefined, undefined, own); | |
| 461 | if (spent.state !== "ok") return dead(ctx, spent.state, undefined, own); | |
| 467 | 462 | if (founder !== undefined) { |
| 468 | 463 | const taken = takeFounder(ctx.app.db, founder.id, { |
| 469 | 464 | hash: founderHash, |
test/claim-page-words.test.ts +4 −4
| @@ -80,7 +80,7 @@ describe("the claim page in plain words", () => { | ||
| 80 | 80 | expect(html).toContain("alice"); |
| 81 | 81 | }); |
| 82 | 82 | |
| 83 | test("an expired link answers 410 in plain words", async () => { | |
| 83 | test("an expired link answers 404 in plain words", async () => { | |
| 84 | 84 | setStored({ e: new Date(Date.now() - 3_600_000).toISOString() }); |
| 85 | 85 | for (const res of [ |
| 86 | 86 | await get(), |
| @@ -88,10 +88,10 @@ describe("the claim page in plain words", () => { | ||
| 88 | 88 | method: "POST", headers: { origin: childServers.url }, body: new URLSearchParams({ token }), |
| 89 | 89 | }), |
| 90 | 90 | ]) { |
| 91 | expect(res.status).toBe(410); | |
| 91 | expect(res.status).toBe(404); | |
| 92 | 92 | const text = await res.text(); |
| 93 | expect(text).toContain("This link has expired"); | |
| 94 | expect(text).toContain("Ask alice to send you a new one"); | |
| 93 | expect(text).toContain("This link does not work"); | |
| 94 | expect(text).toContain("ask whoever sent it for a new one"); | |
| 95 | 95 | expect(text).not.toMatch(/token|\b4\d\d\b/i); |
| 96 | 96 | } |
| 97 | 97 | }); |
test/claim-revoke.test.ts +4 −4
| @@ -95,13 +95,13 @@ describe("revoking a forge link", () => { | ||
| 95 | 95 | await rm(dir, { recursive: true, force: true }); |
| 96 | 96 | }); |
| 97 | 97 | |
| 98 | test("revoke-then-use answers 410 in plain words and sets no session", async () => { | |
| 98 | test("revoke-then-use answers 404 in plain words and sets no session", async () => { | |
| 99 | 99 | expect(state("one")).toBe("open"); |
| 100 | 100 | const done = await revoke("one", "revoke"); |
| 101 | 101 | expect(done.ok).toBe(true); |
| 102 | 102 | expect(state("one")).toBe("ended"); |
| 103 | 103 | const res = await claim("one"); |
| 104 | expect(res.status).toBe(410); | |
| 104 | expect(res.status).toBe(404); | |
| 105 | 105 | expect(res.headers.get("set-cookie")).toBeNull(); |
| 106 | 106 | const form = { token: kids["one"]!.token, username: "x", email: "[email protected]" }; |
| 107 | 107 | const post = await fetch(`${kids["one"]!.servers.url}/claim`, { |
| @@ -110,9 +110,9 @@ describe("revoking a forge link", () => { | ||
| 110 | 110 | body: new URLSearchParams({ ...form, ...(await passkeyFields(kids["one"]!.servers.url, "/claim/options", form).catch(() => ({}))) }), |
| 111 | 111 | redirect: "manual", |
| 112 | 112 | }); |
| 113 | expect(post.status).toBe(410); | |
| 113 | expect(post.status).toBe(404); | |
| 114 | 114 | expect(post.headers.get("set-cookie")).toBeNull(); |
| 115 | expect(await post.text()).toContain("This link has ended"); | |
| 115 | expect(await post.text()).toContain("This link does not work"); | |
| 116 | 116 | }); |
| 117 | 117 | |
| 118 | 118 | test("a revoke is receipted, and undone within the minute", async () => { |
test/console-clean.test.ts +1 −1
| @@ -174,6 +174,6 @@ function guarded(code: string, at: number, len: number): boolean { | ||
| 174 | 174 | |
| 175 | 175 | test("the claim page's own elements are present", async () => { |
| 176 | 176 | const html = await (await fetch(`${childServers.url}/claim`)).text(); |
| 177 | for (const id of ["claim-token-field", "passkey-make", "passkey-make-note"]) expect(html).toContain(`id="${id}"`); | |
| 177 | for (const id of ["claim-token", "passkey-make", "passkey-make-note"]) expect(html).toContain(`id="${id}"`); | |
| 178 | 178 | expect(html).toContain('name="token"'); |
| 179 | 179 | }); |
test/forge-link-landing.test.ts added +132
| @@ -0,0 +1,132 @@ | ||
| 1 | /** | |
| 2 | * A forge link's landing page (#12416), fetched with no cookie and no script: | |
| 3 | * a good link is server-rendered, small, names who made the forge, leaks no | |
| 4 | * token, and carries the security floor; a revoked, expired or unknown link | |
| 5 | * answers one identical kind page, so a stranger cannot tell which it is. | |
| 6 | */ | |
| 7 | import { afterAll, beforeAll, describe, expect, test } from "bun:test"; | |
| 8 | import { mkdtemp, rm } from "node:fs/promises"; | |
| 9 | import { tmpdir } from "node:os"; | |
| 10 | import { join } from "node:path"; | |
| 11 | import { childDirOf } from "../src/actions/spawn.ts"; | |
| 12 | import { createApp, type App } from "../src/app.ts"; | |
| 13 | import { createToken } from "../src/core/tokens.ts"; | |
| 14 | import { createUser } from "../src/core/users.ts"; | |
| 15 | import { serve, type Servers } from "../src/http/server.ts"; | |
| 16 | import { firstBoot } from "../src/spawn/first-boot.ts"; | |
| 17 | import { quietLogs } from "./helpers/globals.ts"; | |
| 18 | ||
| 19 | quietLogs(); | |
| 20 | ||
| 21 | describe("a forge link's landing page", () => { | |
| 22 | let dir = ""; | |
| 23 | let parent: App; | |
| 24 | let parentServers: Servers; | |
| 25 | let child: App; | |
| 26 | let childServers: Servers; | |
| 27 | let token = ""; | |
| 28 | ||
| 29 | const get = () => fetch(`${childServers.url}/claim`, { redirect: "manual" }); | |
| 30 | const setStored = (patch: Record<string, unknown>) => { | |
| 31 | const row = child.db.query<{ value: string }, []>("SELECT value FROM user_setting WHERE key = 'spawn_claim'").get(); | |
| 32 | child.db | |
| 33 | .query("UPDATE user_setting SET value = ?1 WHERE key = 'spawn_claim'") | |
| 34 | .run(JSON.stringify({ ...JSON.parse(row!.value), ...patch })); | |
| 35 | }; | |
| 36 | const future = () => new Date(Date.now() + 3_600_000).toISOString(); | |
| 37 | ||
| 38 | beforeAll(async () => { | |
| 39 | dir = await mkdtemp(join(tmpdir(), "forge-landing-")); | |
| 40 | parent = createApp({ dataDir: dir, url: "https://forge.test", port: 0 }); | |
| 41 | const alice = await createUser(parent.db, { | |
| 42 | origin: "seed", trusted: true, username: "alice", email: "[email protected]", | |
| 43 | password: "a-long-claim-passphrase", isAdmin: true, | |
| 44 | }); | |
| 45 | if (!alice.ok) throw new Error("user"); | |
| 46 | const rw = createToken(parent.db, alice.value.id, "rw", "rw").token; | |
| 47 | parentServers = await serve(parent); | |
| 48 | const made = await fetch(`${parentServers.url}/api/v1/forges`, { | |
| 49 | method: "POST", | |
| 50 | headers: { authorization: `Bearer ${rw}`, "content-type": "application/json" }, | |
| 51 | body: JSON.stringify({ name: "maria", apps: [], dryRun: false }), | |
| 52 | }); | |
| 53 | if (made.status !== 201) throw new Error(`spawn ${made.status}`); | |
| 54 | const body = (await made.json()) as { claimUrl: string; bodyId: string }; | |
| 55 | token = body.claimUrl.split("#")[1] ?? ""; | |
| 56 | child = createApp({ dataDir: childDirOf(parent, body.bodyId), port: 0 }); | |
| 57 | await firstBoot(child); | |
| 58 | childServers = await serve(child); | |
| 59 | }, 60_000); | |
| 60 | ||
| 61 | afterAll(async () => { | |
| 62 | childServers.stop(); | |
| 63 | child.close(); | |
| 64 | parentServers.stop(); | |
| 65 | parent.close(); | |
| 66 | await rm(dir, { recursive: true, force: true }); | |
| 67 | }); | |
| 68 | ||
| 69 | test("a good link: one sentence naming the maker, one way forward, small, floor kept, no token", async () => { | |
| 70 | const res = await get(); | |
| 71 | expect(res.status).toBe(200); | |
| 72 | const text = await res.text(); | |
| 73 | expect(text).toContain("alice made maria for you."); | |
| 74 | expect(Buffer.byteLength(text)).toBeLessThan(20 * 1024); | |
| 75 | expect(res.headers.get("x-content-type-options")).toBe("nosniff"); | |
| 76 | expect(res.headers.get("referrer-policy")).toBeTruthy(); | |
| 77 | expect(res.headers.get("content-security-policy")).toBeTruthy(); | |
| 78 | expect(res.headers.get("set-cookie")).toBeNull(); | |
| 79 | // Server-rendered: the form is in the HTML, not built by script. | |
| 80 | expect(text).toContain('<form method="post" action="/claim">'); | |
| 81 | expect(text).toContain("Make my account"); | |
| 82 | // The token is nowhere in the page nor any outgoing link. | |
| 83 | expect(text).not.toContain(token); | |
| 84 | expect(text).not.toMatch(/href="[^"]*token[^"]*"/i); | |
| 85 | }); | |
| 86 | ||
| 87 | test("revoked, expired and unknown answer the same page and status", async () => { | |
| 88 | setStored({ e: future(), r: new Date().toISOString() }); | |
| 89 | const revoked = await get(); | |
| 90 | setStored({ r: undefined, e: new Date(Date.now() - 3_600_000).toISOString() }); | |
| 91 | const expired = await get(); | |
| 92 | const unknown = await fetch(`${childServers.url}/claim`, { | |
| 93 | method: "POST", | |
| 94 | headers: { origin: childServers.url }, | |
| 95 | body: new URLSearchParams({ token: "x".repeat(43) }), | |
| 96 | }); | |
| 97 | const bodies = await Promise.all([revoked, expired, unknown].map((r) => r.text())); | |
| 98 | for (const r of [revoked, expired, unknown]) { | |
| 99 | expect(r.status).toBe(404); | |
| 100 | expect(r.headers.get("x-content-type-options")).toBe("nosniff"); | |
| 101 | expect(r.headers.get("set-cookie")).toBeNull(); | |
| 102 | } | |
| 103 | const strip = (t: string) => t.replace(/nonce="[^"]*"|<time[^>]*>/g, ""); | |
| 104 | expect(strip(bodies[0]!)).toBe(strip(bodies[1]!)); | |
| 105 | expect(strip(bodies[1]!)).toBe(strip(bodies[2]!)); | |
| 106 | expect(bodies[0]).toContain("does not work any more"); | |
| 107 | expect(bodies[0]).not.toMatch(/expired|revoked|ended|alice|made-up/i); | |
| 108 | expect(Buffer.byteLength(bodies[0]!)).toBeLessThan(20 * 1024); | |
| 109 | }); | |
| 110 | ||
| 111 | test("with no script: the server-rendered form, filled as a person would paste it, makes the account", async () => { | |
| 112 | setStored({ r: undefined, e: future() }); | |
| 113 | const html = await (await get()).text(); | |
| 114 | // No top bar, no footer: the sentence, a code to paste, a username, a password, one button. | |
| 115 | expect(html).not.toContain("<footer"); | |
| 116 | expect(html).toContain("<noscript>"); | |
| 117 | // Submit exactly the fields the form names, with the pasted code in the no-script field. | |
| 118 | const form = html.slice(html.indexOf('<form method="post" action="/claim">'), html.indexOf("</form>")); | |
| 119 | const names = [...form.matchAll(/<input[^>]*\sname="([a-z]+)"/g)].map((m) => m[1]); | |
| 120 | expect(names).toContain("code"); | |
| 121 | expect(names).toContain("username"); | |
| 122 | expect(names).toContain("password"); | |
| 123 | const res = await fetch(`${childServers.url}/claim`, { | |
| 124 | method: "POST", | |
| 125 | headers: { origin: childServers.url }, | |
| 126 | body: new URLSearchParams({ code: token, username: "maria", password: "a-long-enough-password" }), | |
| 127 | redirect: "manual", | |
| 128 | }); | |
| 129 | expect(res.status).toBe(303); | |
| 130 | expect(res.headers.get("set-cookie")).toContain("HttpOnly"); | |
| 131 | }); | |
| 132 | }); |
test/spawn-first-boot.test.ts +3 −3
| @@ -258,7 +258,7 @@ describe("a spawned child's first boot", () => { | ||
| 258 | 258 | test("a made-up code says it is not a forge link", async () => { |
| 259 | 259 | const res = await claim("x".repeat(43), maria); |
| 260 | 260 | expect(res.status).toBe(404); |
| 261 | expect(await res.text()).toContain("not a forge link"); | |
| 261 | expect(await res.text()).toContain("does not work"); | |
| 262 | 262 | expect(getUserByName(child.db, "maria")).toBeUndefined(); |
| 263 | 263 | }); |
| 264 | 264 | |
| @@ -368,8 +368,8 @@ describe("a spawned child's first boot", () => { | ||
| 368 | 368 | username: "late", |
| 369 | 369 | email: "[email protected]", |
| 370 | 370 | }); |
| 371 | expect(res.status).toBe(410); | |
| 372 | expect(await res.text()).toContain("expired"); | |
| 371 | expect(res.status).toBe(404); | |
| 372 | expect(await res.text()).toContain("does not work"); | |
| 373 | 373 | expect(getUserByName(child.db, "late")).toBeUndefined(); |
| 374 | 374 | }); |
| 375 | 375 |
test/stranger-words.test.ts +2 −2
| @@ -139,10 +139,10 @@ describe("a stranger's way to their own forge", () => { | ||
| 139 | 139 | screens.push(["/claim passkey note, unknown", await note(404, { ...who, token: "nope" })]); |
| 140 | 140 | screens.push(["/claim, a passkey that failed", await submit(422, { ...who, challenge: "x", clientDataJSON: "x", attestationObject: "x" })]); |
| 141 | 141 | expect(revokeClaim(db, org)).toBe(true); |
| 142 | await both("revoked", 410); | |
| 142 | await both("revoked", 404); | |
| 143 | 143 | expect(restoreClaim(db, org)).toBe(true); |
| 144 | 144 | as({ e: "2000-01-01T00:00:00.000Z" }); |
| 145 | await both("expired", 410); | |
| 145 | await both("expired", 404); | |
| 146 | 146 | as({ u: new Date().toISOString() }); |
| 147 | 147 | await both("used", 410); |
| 148 | 148 | setStored(live); |
test/welcome.test.ts +4 −4
| @@ -62,7 +62,8 @@ test("a refused welcome says nothing of a sender, and a good one signs in", asyn | ||
| 62 | 62 | // The page comes back with the password kept in sight (the script would hide it), and the link code out of sight. |
| 63 | 63 | const again = await short.text(); |
| 64 | 64 | expect(again).toMatch(/<div data-passkey="off" data-keep>/); |
| 65 | expect(again).toMatch(/<div id="claim-token-field" hidden>/); | |
| 65 | expect(again).toMatch(/<input type="hidden" name="token" value="[^"]+"/); | |
| 66 | expect(again).not.toContain('name="code"'); | |
| 66 | 67 | const ok = await post({ token: fresh.token, username: "maria", password: "a-long-enough-password" }); |
| 67 | 68 | expect(ok.status).toBe(303); |
| 68 | 69 | expect(ok.headers.get("location")).toBe("/"); |
| @@ -140,12 +141,11 @@ test("the home's scripts join without calling the one before", () => { | ||
| 140 | 141 | for (const part of [funnelJs, startNameJs]) expect(part.trimEnd().endsWith(";")).toBe(true); |
| 141 | 142 | }); |
| 142 | 143 | |
| 143 | test("the link code field is visible and required in the server render, and the forge's own name is a name a person may take (#11948)", async () => { | |
| 144 | test("the no-script link code field is required in the server render, and the forge's own name is a name a person may take (#11948)", async () => { | |
| 144 | 145 | const started = await startedForge("forge-welcome-name-"); |
| 145 | 146 | try { |
| 146 | 147 | const html = await (await fetch(`${started.base}/welcome`)).text(); |
| 147 | expect(html).not.toMatch(/<div id="claim-token-field"[^>]*hidden/); | |
| 148 | expect(html).toMatch(/<input[^>]*name="token"[^>]*required|<input[^>]*required[^>]*name="token"/); | |
| 148 | expect(html).toMatch(/<noscript>[\s\S]*<input[^>]*name="code"[^>]*required|<noscript>[\s\S]*<input[^>]*required[^>]*name="code"/); | |
| 149 | 149 | const org = started.child.db.query<{ username: string }, []>("SELECT username FROM user WHERE kind = 'org' LIMIT 1").get()!.username; |
| 150 | 150 | const res = await fetch(`${started.base}/welcome`, { |
| 151 | 151 | method: "POST", |
new above
offline
void endedAt;is dead code silenced. Drop the unused parameter (principle 8 / Clean).