Public: anyone can read this; the crew can change it.
The forge pill shows on an app whose CSP allows only its own scripts: the proxy serves it from the app's host #8228
scout/forge:scout/8209-the-forge-pill-shows-on-an-app-whose-csp → main 10 commits fork
8 files
changed +210
−22
src/apps/proxy.ts +8 −1
| @@ -53,7 +53,7 @@ import { notFound, securityFloor } from "../http/respond.ts"; | ||
| 53 | 53 | import { appMeasure } from "./measure.ts"; |
| 54 | 54 | import { holdPortRequest, holdPortSocket } from "./handoff.ts"; |
| 55 | 55 | import { secureFor } from "../http/cookie_secure.ts"; |
| 56 | import { htmlAnswer, readPage, rewritable, withToolbar, type PillWhere } from "./toolbar.ts"; | |
| 56 | import { APP_TOOLBAR_PATH, toolbarResponse, htmlAnswer, readPage, rewritable, withToolbar, type PillWhere } from "./toolbar.ts"; | |
| 57 | 57 | |
| 58 | 58 | const proxySecure = (request: Request, url: URL, forgeUrl: string): boolean => |
| 59 | 59 | secureFor(url, forgeUrl) || |
| @@ -816,6 +816,13 @@ export async function proxyApp( | ||
| 816 | 816 | server: Bun.Server<AppSocket>, |
| 817 | 817 | ): Promise<Response | undefined> { |
| 818 | 818 | const url = new URL(request.url); |
| 819 | // The pill's script, from the app's own host so a page that allows only | |
| 820 | // its own scripts still loads it. Public bytes, named by their hash. | |
| 821 | if ( | |
| 822 | url.pathname === APP_TOOLBAR_PATH && | |
| 823 | (request.method === "GET" || request.method === "HEAD") | |
| 824 | ) | |
| 825 | return securityFloor(toolbarResponse(request)); | |
| 819 | 826 | // A grant with this forge's own token is answered here. On a nested |
| 820 | 827 | // hostname a grant this forge did not sign is the guest forge's, and |
| 821 | 828 | // goes through to it like any other request. |
src/apps/toolbar.ts +11 −6
| @@ -20,8 +20,10 @@ export const toolbarJs = `(function () { | ||
| 20 | 20 | if (window.__forgeToolbar) return; |
| 21 | 21 | window.__forgeToolbar = true; |
| 22 | 22 | var me = document.currentScript; |
| 23 | // The forge's address: a data attribute when the script is the app's own, else where the script came from. | |
| 24 | var forgeAt = (me.dataset && me.dataset.forge) || me.src; | |
| 23 | 25 | var home = "/"; |
| 24 | try { home = new URL(me.src).origin + "/"; } catch (e) {} | |
| 26 | try { home = new URL(forgeAt).origin + "/"; } catch (e) {} | |
| 25 | 27 | var host = document.createElement("div"); |
| 26 | 28 | host.id = "forge-toolbar"; |
| 27 | 29 | host.style.cssText = "all:initial;position:fixed;z-index:2147483647"; |
| @@ -74,7 +76,7 @@ export const toolbarJs = `(function () { | ||
| 74 | 76 | var pullHref = ""; |
| 75 | 77 | // The pull this preview shows, one tap away: built from the script's own origin, never from page text. |
| 76 | 78 | if (d.env !== "production" && /^\\d{1,9}$/.test(d.pull || "") && /^[\\w.-]+\\/[\\w.-]+$/.test(d.repo || "")) { |
| 77 | try { pullHref = new URL("/" + d.repo + "/pulls/" + d.pull, me.src).href; } catch (e) {} | |
| 79 | try { pullHref = new URL("/" + d.repo + "/pulls/" + d.pull, forgeAt).href; } catch (e) {} | |
| 78 | 80 | } |
| 79 | 81 | if (d.env === "production") {} |
| 80 | 82 | else if (pullHref) { |
| @@ -92,13 +94,13 @@ export const toolbarJs = `(function () { | ||
| 92 | 94 | link.style.cssText = LS; |
| 93 | 95 | try { |
| 94 | 96 | var target = new URL(home); |
| 95 | if (target.origin === new URL(me.src).origin) link.href = target.href; | |
| 97 | if (target.origin === new URL(forgeAt).origin) link.href = target.href; | |
| 96 | 98 | } catch (e) {} |
| 97 | 99 | // Tell the builders: one box, one button, no account. The note goes to |
| 98 | 100 | // this app's own host (same-origin, so the sender's cookie goes along) and |
| 99 | 101 | // the answer is a live status the panel keeps fresh while it is open. |
| 100 | 102 | var forgeOrigin = ""; |
| 101 | try { forgeOrigin = new URL(me.src).origin; } catch (e) {} | |
| 103 | try { forgeOrigin = new URL(forgeAt).origin; } catch (e) {} | |
| 102 | 104 | var tellBox = document.createElement("form"); |
| 103 | 105 | tellBox.setAttribute("aria-label", "Tell the builders"); |
| 104 | 106 | tellBox.style.cssText = "display:flex;flex-direction:column;gap:6px;margin:6px 0"; |
| @@ -320,7 +322,7 @@ export const toolbarJs = `(function () { | ||
| 320 | 322 | .then(function (r) { return r.ok ? r.json() : {}; }) |
| 321 | 323 | .then(function (c) { |
| 322 | 324 | if (!c) return; |
| 323 | var forge = new URL(me.src).origin; | |
| 325 | var forge = new URL(forgeAt).origin; | |
| 324 | 326 | // Signed in, the crew can be told from here. The form is the forge's |
| 325 | 327 | // own page, on its own origin, with its own CSRF check: the app's |
| 326 | 328 | // page only carries the address and the pull to it. |
| @@ -507,6 +509,8 @@ const name = `toolbar-${hash.slice(0, 16)}`; | ||
| 507 | 509 | /** The path the script is served from on the forge, content-addressed. */ |
| 508 | 510 | export const TOOLBAR_PATH = `/assets/${name}.js`; |
| 509 | 511 | export const TOOLBAR_NAME = name; |
| 512 | /** The same bytes on every app's own host, so a `script-src 'self'` page loads them. */ | |
| 513 | export const APP_TOOLBAR_PATH = `/__forge/${name}.js`; | |
| 510 | 514 | |
| 511 | 515 | /** The forge's answer for the script: immutable, because its name is its hash. */ |
| 512 | 516 | export function toolbarResponse(request: Request): Response { |
| @@ -586,7 +590,8 @@ export function toolbarTag(forgeUrl: string, where?: PillWhere, proof?: string): | ||
| 586 | 590 | .map(([k, v]) => ` data-${k}="${escapeAttr(v)}"`) |
| 587 | 591 | .join(""); |
| 588 | 592 | const token = proof === undefined ? "" : ` data-proof="${escapeAttr(proof)}"`; |
| 589 | return `<script src="${new URL(TOOLBAR_PATH, forgeUrl).href}"${data}${token} defer></script>`; | |
| 593 | const forge = ` data-forge="${escapeAttr(new URL("/", forgeUrl).origin)}"`; | |
| 594 | return `<script src="${APP_TOOLBAR_PATH}"${forge}${data}${token} defer></script>`; | |
| 590 | 595 | } |
| 591 | 596 | |
| 592 | 597 | /** |
test/apps-pill-where.test.ts +1 −1
| @@ -168,6 +168,6 @@ describe("the pill's script", () => { | ||
| 168 | 168 | test("puts text in with textContent and checks the home href against the forge origin", () => { |
| 169 | 169 | expect(toolbarJs).toContain("textContent = text"); |
| 170 | 170 | expect(toolbarJs).not.toMatch(/innerHTML|outerHTML|insertAdjacentHTML|document\.write/); |
| 171 | expect(toolbarJs).toContain("target.origin === new URL(me.src).origin"); | |
| 171 | expect(toolbarJs).toContain("target.origin === new URL(forgeAt).origin"); | |
| 172 | 172 | }); |
| 173 | 173 | }); |
test/apps-toolbar-same-origin.test.ts added +176
| @@ -0,0 +1,176 @@ | ||
| 1 | /** | |
| 2 | * The pill on an app whose CSP allows only its own scripts: the tag's src is | |
| 3 | * the app's own origin, the forge's address rides in data-forge, and the app's | |
| 4 | * host answers the script's bytes (and only for GET and HEAD at the exact, | |
| 5 | * hash-named path). One forge, one app serving one HTML page with a strict | |
| 6 | * CSP, asked through the app proxy; the script itself runs against a fake page. | |
| 7 | */ | |
| 8 | ||
| 9 | import { afterAll, beforeAll, describe, expect, spyOn, test } from "bun:test"; | |
| 10 | import { mkdtemp, rm } from "node:fs/promises"; | |
| 11 | import { tmpdir } from "node:os"; | |
| 12 | import { join } from "node:path"; | |
| 13 | import { createApp, type App } from "../src/app.ts"; | |
| 14 | import { newApp } from "../src/actions/apps.ts"; | |
| 15 | import { AppsRuntime, type EnvStatus } from "../src/apps/runtime.ts"; | |
| 16 | import { APP_TOOLBAR_PATH, toolbarJs, toolbarTag } from "../src/apps/toolbar.ts"; | |
| 17 | import { createUser } from "../src/core/users.ts"; | |
| 18 | import { serve, type Servers } from "../src/http/server.ts"; | |
| 19 | import { quietLogs } from "./helpers/globals.ts"; | |
| 20 | ||
| 21 | quietLogs(); | |
| 22 | ||
| 23 | const DOMAIN = "apps.test"; | |
| 24 | const HTML = "<html><body><h1>hi</h1></body></html>"; | |
| 25 | ||
| 26 | describe("the pill loads on an app whose CSP allows only its own scripts", () => { | |
| 27 | let dataDir: string; | |
| 28 | let app: App; | |
| 29 | let servers: Servers; | |
| 30 | let runtime: AppsRuntime; | |
| 31 | let backend: ReturnType<typeof Bun.serve>; | |
| 32 | let status: ReturnType<typeof spyOn>; | |
| 33 | ||
| 34 | beforeAll(async () => { | |
| 35 | backend = Bun.serve({ | |
| 36 | port: 0, | |
| 37 | fetch: () => | |
| 38 | new Response(HTML, { | |
| 39 | headers: { "content-type": "text/html; charset=utf-8", "content-security-policy": "default-src 'self'; script-src 'self'" }, | |
| 40 | }), | |
| 41 | }); | |
| 42 | dataDir = await mkdtemp(join(tmpdir(), "forge-pill-same-origin-")); | |
| 43 | app = createApp({ dataDir, port: 0, host: "forge.test" }); | |
| 44 | servers = await serve(app); | |
| 45 | runtime = new AppsRuntime(app, { | |
| 46 | domain: DOMAIN, | |
| 47 | scheme: "http", | |
| 48 | publicPort: servers.port, | |
| 49 | forgeUrl: servers.url, | |
| 50 | concurrency: 1, | |
| 51 | }); | |
| 52 | await runtime.start(); | |
| 53 | status = spyOn(AppsRuntime.prototype, "envStatus").mockImplementation( | |
| 54 | (_app: unknown, env: string) => | |
| 55 | ({ | |
| 56 | env, | |
| 57 | state: "running", | |
| 58 | port: backend.port, | |
| 59 | commitOid: "a".repeat(40), | |
| 60 | }) as EnvStatus, | |
| 61 | ); | |
| 62 | const u = await createUser(app.db, { | |
| 63 | origin: "seed", | |
| 64 | trusted: true, | |
| 65 | username: "alice", | |
| 66 | email: "[email protected]", | |
| 67 | password: "a-good-passphrase", | |
| 68 | adminIfFirst: true, | |
| 69 | }); | |
| 70 | if (!u.ok) throw new Error(u.error); | |
| 71 | ||
| 72 | const made = await newApp(app, u.value, { name: "notes", description: "x", visibility: "public" }); | |
| 73 | if (!made.ok) throw new Error(String(made.error)); | |
| 74 | }, 120_000); | |
| 75 | ||
| 76 | afterAll(async () => { | |
| 77 | status.mockRestore(); | |
| 78 | await runtime.stop(); | |
| 79 | servers.stop(); | |
| 80 | backend.stop(true); | |
| 81 | app.close(); | |
| 82 | await rm(dataDir, { recursive: true, force: true }); | |
| 83 | }); | |
| 84 | ||
| 85 | const ask = (path: string) => | |
| 86 | fetch(`${servers.url}${path}`, { headers: { host: `notes.${DOMAIN}`, accept: "text/html" }, redirect: "manual" }); | |
| 87 | ||
| 88 | test("the tag's src is the app's own origin and the forge's address rides in data-forge", async () => { | |
| 89 | const res = await ask("/"); | |
| 90 | expect(res.headers.get("content-security-policy")).toContain("script-src 'self'"); | |
| 91 | const html = await res.text(); | |
| 92 | const tag = /<script src="([^"]+)"([^>]*) defer><\/script>/.exec(html); | |
| 93 | expect(tag).not.toBeNull(); | |
| 94 | expect(tag![1]).toBe(APP_TOOLBAR_PATH); | |
| 95 | expect(tag![1]!.startsWith("/")).toBe(true); | |
| 96 | expect(tag![2]).toContain(` data-forge="${servers.url}"`); | |
| 97 | }); | |
| 98 | ||
| 99 | test("the app's host answers the pill's bytes, immutable, with the security headers", async () => { | |
| 100 | const res = await ask(APP_TOOLBAR_PATH); | |
| 101 | expect(res.status).toBe(200); | |
| 102 | expect(res.headers.get("content-type")).toStartWith("text/javascript"); | |
| 103 | expect(res.headers.get("cache-control")).toBe("public, max-age=31536000, immutable"); | |
| 104 | expect(res.headers.get("x-content-type-options")).toBe("nosniff"); | |
| 105 | expect(res.headers.get("referrer-policy")).not.toBeNull(); | |
| 106 | expect(res.headers.get("content-security-policy")).not.toBeNull(); | |
| 107 | expect(await res.text()).toBe(toolbarJs); | |
| 108 | }); | |
| 109 | ||
| 110 | test("the tag escapes what it carries", () => { | |
| 111 | const tag = toolbarTag("https://forge.example", { app: 'a"b', repo: "x/y", env: "production" }); | |
| 112 | expect(tag).toContain('src="/__forge/toolbar-'); | |
| 113 | expect(tag).toContain('data-forge="https://forge.example"'); | |
| 114 | expect(tag).toContain("data-app=\"a"b\""); | |
| 115 | }); | |
| 116 | ||
| 117 | test("HEAD answers without a body", async () => { | |
| 118 | const res = await fetch(`${servers.url}${APP_TOOLBAR_PATH}`, { method: "HEAD", headers: { host: `notes.${DOMAIN}` } }); | |
| 119 | expect(res.status).toBe(200); | |
| 120 | expect(res.headers.get("content-type")).toStartWith("text/javascript"); | |
| 121 | expect(await res.text()).toBe(""); | |
| 122 | }); | |
| 123 | ||
| 124 | test("POST on the pill's path is not served the script", async () => { | |
| 125 | const res = await fetch(`${servers.url}${APP_TOOLBAR_PATH}`, { | |
| 126 | method: "POST", | |
| 127 | body: "x", | |
| 128 | headers: { host: `notes.${DOMAIN}` }, | |
| 129 | }); | |
| 130 | expect(await res.text()).not.toContain("__forgeToolbar"); | |
| 131 | }); | |
| 132 | ||
| 133 | test("a wrong hash under /__forge/ is not served the script", async () => { | |
| 134 | const res = await ask("/__forge/toolbar-0000000000000000.js"); | |
| 135 | expect(await res.text()).not.toContain("__forgeToolbar"); | |
| 136 | }); | |
| 137 | ||
| 138 | test("run with src on the app's host, the links still point at the forge", () => { | |
| 139 | const links: { text: string; href: string }[] = []; | |
| 140 | const fake = (): any => | |
| 141 | new Proxy( | |
| 142 | { style: {}, dataset: {}, children: [] as any[] }, | |
| 143 | { | |
| 144 | get: (t: any, k: string) => (k in t ? t[k] : k === "then" ? undefined : (..._a: any[]) => fake()), | |
| 145 | set: (t: any, k: string, v: unknown) => { | |
| 146 | t[k] = v; | |
| 147 | if (k === "href") links.push({ text: String(t.textContent ?? ""), href: String(v) }); | |
| 148 | return true; | |
| 149 | }, | |
| 150 | }, | |
| 151 | ); | |
| 152 | const script: any = { | |
| 153 | src: `http://notes.${DOMAIN}${APP_TOOLBAR_PATH}`, | |
| 154 | dataset: { forge: "https://forge.example", env: "preview", pull: "7", repo: "alice/notes", app: "notes" }, | |
| 155 | }; | |
| 156 | const doc: any = { | |
| 157 | currentScript: script, | |
| 158 | createElement: () => fake(), | |
| 159 | body: fake(), | |
| 160 | documentElement: fake(), | |
| 161 | addEventListener() {}, | |
| 162 | }; | |
| 163 | const win: any = { innerWidth: 1000, innerHeight: 800, addEventListener() {}, matchMedia: () => ({ matches: false, addEventListener() {} }) }; | |
| 164 | const loc = { href: `http://notes.${DOMAIN}/`, pathname: "/", search: "", origin: `http://notes.${DOMAIN}` }; | |
| 165 | const run = new Function("document", "window", "location", "fetch", "localStorage", toolbarJs); | |
| 166 | try { | |
| 167 | run(doc, win, loc, () => new Promise(() => {}), { getItem: () => null, setItem() {} }); | |
| 168 | } catch { | |
| 169 | // Whatever the fake page cannot do comes after the links were set. | |
| 170 | } | |
| 171 | const hrefs = links.map((l) => l.href); | |
| 172 | expect(hrefs).toContain("https://forge.example/"); | |
| 173 | expect(hrefs).toContain("https://forge.example/alice/notes/pulls/7"); | |
| 174 | expect(hrefs.every((h) => h.startsWith("https://forge.example/"))).toBe(true); | |
| 175 | }); | |
| 176 | }); |
test/apps-toolbar.test.ts +9 −9
| @@ -17,7 +17,7 @@ import { getAppByRepo } from "../src/core/apps.ts"; | ||
| 17 | 17 | import { listRuns } from "../src/core/runs.ts"; |
| 18 | 18 | import { AppsRuntime, type EnvStatus } from "../src/apps/runtime.ts"; |
| 19 | 19 | import { parseManifest } from "../src/apps/manifest.ts"; |
| 20 | import { REWRITE_MAX, TOOLBAR_PATH, readPage, toolbarJs, withToolbar } from "../src/apps/toolbar.ts"; | |
| 20 | import { APP_TOOLBAR_PATH, REWRITE_MAX, TOOLBAR_PATH, readPage, toolbarJs, withToolbar } from "../src/apps/toolbar.ts"; | |
| 21 | 21 | import { createUser } from "../src/core/users.ts"; |
| 22 | 22 | import { serve, type Servers } from "../src/http/server.ts"; |
| 23 | 23 | import { quietLogs } from "./helpers/globals.ts"; |
| @@ -187,7 +187,7 @@ describe("the forge pill", () => { | ||
| 187 | 187 | redirect: "manual", |
| 188 | 188 | }); |
| 189 | 189 | const tag = () => |
| 190 | `<script src="${servers.url}${TOOLBAR_PATH}" data-app="notes" data-repo="alice/notes" data-env="production" defer></script>`; | |
| 190 | `<script src="${APP_TOOLBAR_PATH}" data-forge="${servers.url}" data-app="notes" data-repo="alice/notes" data-env="production" defer></script>`; | |
| 191 | 191 | |
| 192 | 192 | test("HTML gets one script tag before </body>, with its length fixed", async () => { |
| 193 | 193 | toolbar = undefined; |
| @@ -227,7 +227,7 @@ describe("the forge pill", () => { | ||
| 227 | 227 | const got = Buffer.from(await res.arrayBuffer()).toString(); |
| 228 | 228 | const piece = "<p>" + "b".repeat(1024 * 1024) + "</p>"; |
| 229 | 229 | expect(got).toBe("<html><body>" + piece.repeat(5) + "</body></html>"); |
| 230 | expect(got).not.toContain(TOOLBAR_PATH); | |
| 230 | expect(got).not.toContain(APP_TOOLBAR_PATH); | |
| 231 | 231 | }); |
| 232 | 232 | |
| 233 | 233 | test("a streamed page still open after the wait arrives whole with no pill", async () => { |
| @@ -273,7 +273,7 @@ describe("the forge pill", () => { | ||
| 273 | 273 | }); |
| 274 | 274 | expect(plain.headers.get("content-encoding")).toBeNull(); |
| 275 | 275 | expect(plain.headers.get("vary")).toContain("accept-encoding"); |
| 276 | expect(await plain.text()).toContain(TOOLBAR_PATH); | |
| 276 | expect(await plain.text()).toContain(APP_TOOLBAR_PATH); | |
| 277 | 277 | }); |
| 278 | 278 | |
| 279 | 279 | test("a client that refuses gzip with q=0 gets the page plain", async () => { |
| @@ -284,7 +284,7 @@ describe("the forge pill", () => { | ||
| 284 | 284 | } as RequestInit); |
| 285 | 285 | expect(res.headers.get("content-encoding")).toBeNull(); |
| 286 | 286 | expect(res.headers.get("vary")).toContain("accept-encoding"); |
| 287 | expect(await res.text()).toContain(TOOLBAR_PATH); | |
| 287 | expect(await res.text()).toContain(APP_TOOLBAR_PATH); | |
| 288 | 288 | }); |
| 289 | 289 | |
| 290 | 290 | test("a client that accepts br is sent brotli", async () => { |
| @@ -309,7 +309,7 @@ describe("the forge pill", () => { | ||
| 309 | 309 | } as RequestInit); |
| 310 | 310 | expect(res.headers.get("content-encoding")).toBeNull(); |
| 311 | 311 | expect(res.headers.get("vary")).toContain("accept-encoding"); |
| 312 | expect(await res.text()).toContain(TOOLBAR_PATH); | |
| 312 | expect(await res.text()).toContain(APP_TOOLBAR_PATH); | |
| 313 | 313 | }); |
| 314 | 314 | |
| 315 | 315 | test("an app with the pill off is sent the client's encoding and its gzip passes through", async () => { |
| @@ -375,7 +375,7 @@ describe("the forge pill", () => { | ||
| 375 | 375 | const out = new TextDecoder().decode( |
| 376 | 376 | withToolbar(new TextEncoder().encode("<BODY>x</BODY>"), "http://f.test"), |
| 377 | 377 | ); |
| 378 | expect(out).toBe(`<BODY>x<script src="http://f.test${TOOLBAR_PATH}" defer></script></BODY>`); | |
| 378 | expect(out).toBe(`<BODY>x<script src="${APP_TOOLBAR_PATH}" data-forge="http://f.test" defer></script></BODY>`); | |
| 379 | 379 | }); |
| 380 | 380 | |
| 381 | 381 | test("forge.json toolbar is validated", () => { |
| @@ -612,7 +612,7 @@ describe("the opt-out, from forge.json to the proxy", () => { | ||
| 612 | 612 | // As created: the pill is on, so the page below has something to lose. |
| 613 | 613 | expect((await settled()).state).toBe("ok"); |
| 614 | 614 | expect(runtime.envStatus(record, "production")?.toolbar).toBe(true); |
| 615 | expect(await page()).toContain(TOOLBAR_PATH); | |
| 615 | expect(await page()).toContain(APP_TOOLBAR_PATH); | |
| 616 | 616 | |
| 617 | 617 | const off = await commitToBranch(app, a.value, repo, { |
| 618 | 618 | message: "Turn the pill off", |
| @@ -628,7 +628,7 @@ describe("the opt-out, from forge.json to the proxy", () => { | ||
| 628 | 628 | expect(runtime.envStatus(record, "production")?.toolbar).toBe(false); |
| 629 | 629 | const html = await page(); |
| 630 | 630 | expect(html).toContain("<"); |
| 631 | expect(html).not.toContain(TOOLBAR_PATH); | |
| 631 | expect(html).not.toContain(APP_TOOLBAR_PATH); | |
| 632 | 632 | }, 180_000); |
| 633 | 633 | }); |
| 634 | 634 |
test/never-lost.test.ts +2 −2
| @@ -13,7 +13,7 @@ import { createApp, type App } from "../src/app.ts"; | ||
| 13 | 13 | import { newApp } from "../src/actions/apps.ts"; |
| 14 | 14 | import { signGrant, type AppTarget } from "../src/apps/proxy.ts"; |
| 15 | 15 | import { AppsRuntime, type EnvStatus } from "../src/apps/runtime.ts"; |
| 16 | import { TOOLBAR_PATH } from "../src/apps/toolbar.ts"; | |
| 16 | import { APP_TOOLBAR_PATH } from "../src/apps/toolbar.ts"; | |
| 17 | 17 | import { getAppByRepo, type AppRecord } from "../src/core/apps.ts"; |
| 18 | 18 | import { createIssue } from "../src/core/issues.ts"; |
| 19 | 19 | import { createToken } from "../src/core/tokens.ts"; |
| @@ -119,7 +119,7 @@ describe("never lost: the pill from production and from a preview", () => { | ||
| 119 | 119 | const html = await res.text(); |
| 120 | 120 | const tag = /<script src="([^"]+)"([^>]*) defer><\/script>/.exec(html); |
| 121 | 121 | expect(tag).not.toBeNull(); |
| 122 | expect(tag![1]).toBe(`${servers.url}${TOOLBAR_PATH}`); | |
| 122 | expect(tag![1]).toBe(APP_TOOLBAR_PATH); | |
| 123 | 123 | expect(tag![2]).toContain(' data-app="notes"'); |
| 124 | 124 | expect(tag![2]).toContain(' data-repo="alice/notes"'); |
| 125 | 125 | expect(tag![2]).toContain(` data-env="${env()}"`); |
test/toolbar-body-close.test.ts +1 −1
| @@ -2,7 +2,7 @@ | ||
| 2 | 2 | import { expect, test } from "bun:test"; |
| 3 | 3 | import { withToolbar } from "../src/apps/toolbar.ts"; |
| 4 | 4 | |
| 5 | const TAG = `<script src="http://f.test/`; | |
| 5 | const TAG = `<script src="/__forge/`; | |
| 6 | 6 | const put = (html: string): string => |
| 7 | 7 | new TextDecoder().decode(withToolbar(new TextEncoder().encode(html), "http://f.test")); |
| 8 | 8 | /** Where the tag landed, as the text before it. */ |
test/toolbar-keyboard.test.ts +2 −2
| @@ -11,7 +11,7 @@ import { mkdtempSync, rmSync } from "node:fs"; | ||
| 11 | 11 | import { tmpdir } from "node:os"; |
| 12 | 12 | import { join } from "node:path"; |
| 13 | 13 | import { childEnv } from "../src/apps/process.ts"; |
| 14 | import { TOOLBAR_PATH, toolbarJs, toolbarTag } from "../src/apps/toolbar.ts"; | |
| 14 | import { APP_TOOLBAR_PATH, toolbarJs, toolbarTag } from "../src/apps/toolbar.ts"; | |
| 15 | 15 | import { findChromium } from "../src/looks/capture.ts"; |
| 16 | 16 | import { chromiumRuns } from "./helpers/chrome.ts"; |
| 17 | 17 | |
| @@ -70,7 +70,7 @@ describe.skipIf(chromium === undefined)("the pill by keyboard", () => { | ||
| 70 | 70 | hostname: "127.0.0.1", |
| 71 | 71 | fetch(req) { |
| 72 | 72 | const url = new URL(req.url); |
| 73 | if (url.pathname === TOOLBAR_PATH) | |
| 73 | if (url.pathname === APP_TOOLBAR_PATH) | |
| 74 | 74 | return new Response(toolbarJs, { headers: { "content-type": "text/javascript" } }); |
| 75 | 75 | if (url.pathname === "/__forge/notes") return Response.json({ notes: [] }); |
| 76 | 76 | if (url.pathname === "/__forge/crew") return Response.json({}); |
new above
offline