Public: anyone can read this; the crew can change it.
From an owner's app and a preview, the toolbar's home, comment and tell links all answer, proven by one journey test #13608
Check · Review · Land · Live done — Landed and live in production.
mason/forge:mason/13602-from-an-owner-s-app-and-a-preview-the-to → main 1 commit fork
1 file
changed +65
−0
test/lost-journey.test.ts +65
| @@ -289,6 +289,71 @@ describe("lost journey: where you are and three exits", () => { | ||
| 289 | 289 | expect(html).not.toContain("/pulls/"); |
| 290 | 290 | }); |
| 291 | 291 | |
| 292 | // ---- The journey: read each toolbar's links and follow them. ---- | |
| 293 | const ownerSession = async () => { | |
| 294 | const res = await fetch(`${servers.url}/signin`, { | |
| 295 | method: "POST", | |
| 296 | body: new URLSearchParams({ username: "alice", password: "a-good-passphrase" }), | |
| 297 | redirect: "manual", | |
| 298 | }); | |
| 299 | return (res.headers.get("set-cookie") ?? "").split(";")[0]!; | |
| 300 | }; | |
| 301 | /** | |
| 302 | * Follow `href` (on the forge's origin) by hand, up to five redirects; every hop must be 2xx/3xx | |
| 303 | * and stay on the origin. | |
| 304 | */ | |
| 305 | const follow = async (href: string, cookie?: string) => { | |
| 306 | const origin = new URL(servers.url).origin; | |
| 307 | let url = new URL(href); | |
| 308 | for (let hop = 0; hop < 6; hop++) { | |
| 309 | expect(url.origin).toBe(origin); | |
| 310 | const res = await fetch(url, { headers: cookie ? { cookie } : {}, redirect: "manual" }); | |
| 311 | expect(res.status).toBeGreaterThanOrEqual(200); | |
| 312 | expect(res.status).toBeLessThan(400); | |
| 313 | if (res.status < 300) return res; | |
| 314 | url = new URL(res.headers.get("location")!, url); | |
| 315 | await res.arrayBuffer(); | |
| 316 | } | |
| 317 | throw new Error(`too many redirects from ${href}`); | |
| 318 | }; | |
| 319 | ||
| 320 | for (const preview of [false, true]) { | |
| 321 | test(`journey, ${preview ? "preview" : "owner's app"}: home, comment and tell answer for the owner; home for a stranger`, async () => { | |
| 322 | const { pull } = apps.public!; | |
| 323 | const env = preview ? `pull-${pull}` : "production"; | |
| 324 | const host = preview ? `public--${pull}.${DOMAIN}` : `public.${DOMAIN}`; | |
| 325 | const cookie = cookieFor("public", env); | |
| 326 | const html = await (await ask(host, "/", cookie)).text(); | |
| 327 | const run = await boot(html, await crewOf(host, cookie), `http://${host}/page`); | |
| 328 | const origin = new URL(servers.url).origin; | |
| 329 | ||
| 330 | const links = run.built.filter((e) => e.tag === "a" && typeof e.href === "string" && e.href !== ""); | |
| 331 | expect(links.length).toBeGreaterThanOrEqual(3); | |
| 332 | // No link leaves the forge's origin, to anywhere the person did not come from. | |
| 333 | // "Open on production" is the one link to the app's own production host; every other stays on | |
| 334 | // the forge. | |
| 335 | for (const l of links) { | |
| 336 | const where = new URL(l.href as string); | |
| 337 | if (l.textContent === "Open on production") expect(where.hostname).toBe(`public.${DOMAIN}`); | |
| 338 | else expect([l.textContent, where.origin]).toEqual([l.textContent, origin]); | |
| 339 | } | |
| 340 | ||
| 341 | const session = await ownerSession(); | |
| 342 | expect(session).toContain("="); | |
| 343 | for (const text of ["Home", "Comment, tell, make it yours", "Tell the crew"]) { | |
| 344 | const link = run.named(text); | |
| 345 | expect(link, text).toBeDefined(); | |
| 346 | const res = await follow(link!.href as string, session); | |
| 347 | expect(res.status, text).toBe(200); | |
| 348 | } | |
| 349 | ||
| 350 | const strangerHtml = await (await ask(host, "/")).text(); | |
| 351 | const stranger = await boot(strangerHtml, await crewOf(host), `http://${host}/page`); | |
| 352 | const res = await follow(stranger.named("Home")!.href as string); | |
| 353 | expect(res.status).toBe(200); | |
| 354 | }); | |
| 355 | } | |
| 356 | ||
| 292 | 357 | test("security: the script has no eval and no dynamic code", () => { |
| 293 | 358 | expect(toolbarJs).not.toMatch(/\beval\s*\(|new Function/); |
| 294 | 359 | }); |
new above
offline