Make every URL the console page uses page-relative, guarded by a source test

AI Assisted
This commit is contained in:
Seth committed 2026-12-05 00:10:44 -08:00
1 parent 4ced32be5c
commit 1d007737b1
47 files changed
+401 -202

No files matched your search

+1
View File
@@ -43,6 +43,7 @@
"test-web-console-diff-parse.mjs",
"test-web-console-git-board.mjs",
"test-web-console-prototypes.mjs",
"test-web-console-relative-urls.mjs",
"test-web-console-send-state.mjs",
"test-web-console-shape.mjs",
"test-web-console-skills.mjs",
+1 -1
View File
@@ -52,6 +52,6 @@ test("it asks once per page", async () => {
await load();
await load();
assert.equal(calls.length, 1);
assert.deepEqual(calls[0], ["/spec-carry", "POST"]);
assert.deepEqual(calls[0], ["spec-carry", "POST"]);
assert.equal(typeof loadSpecCarry, "function");
});
+1 -1
View File
@@ -280,7 +280,7 @@ test("the list names Snake, Mini golf, Light Trails, Bug Hunt, Sunset Drive, Sta
assert.equal(ACTIVITIES[12].title, "Flock Dash");
for (const a of ACTIVITIES) {
assert.ok(Object.isFrozen(a), `${a.id} is frozen`);
assert.equal(a.module, a.id === "ghoul" ? "/activities/ghoul-rush/ghoul.js" : `/activities/${a.id}.js`);
assert.equal(a.module, a.id === "ghoul" ? "activities/ghoul-rush/ghoul.js" : `activities/${a.id}.js`);
assert.equal(typeof a.title, "string");
assert.ok(typeof a.blurb === "string" && a.blurb.length > 10, `${a.id} has a line for its picker card`);
}
+1 -1
View File
@@ -121,6 +121,6 @@ test("the page-closed signal is a keepalive fetch, which carries the page's orig
const core = fs.readFileSync(path.join(ROOT, "src", "web-console", "public", "screens", "core.js"), "utf8");
const wire = core.slice(core.indexOf("export function wireChrome()"));
const pagehide = wire.slice(0, wire.indexOf("});"));
assert.match(pagehide, /fetch\("\/bye", \{ method: "POST", keepalive: true \}\)/, pagehide);
assert.match(pagehide, /fetch\("bye", \{ method: "POST", keepalive: true \}\)/, pagehide);
assert.doesNotMatch(core, /navigator\.sendBeacon\(/, "no beacon call left anywhere in the page's core");
});
+1 -1
View File
@@ -589,7 +589,7 @@ test("git board: the page draws it from git-board.js, with no inline styles", ()
const dir = path.join(path.dirname(CONSOLE_CLI), "public");
const html = fs.readFileSync(path.join(dir, "index.html"), "utf8");
const view = fs.readFileSync(path.join(dir, "git-board-view.js"), "utf8");
for (const m of ["git-board.js", "git-board-view.js", "pr-url.js"]) assert.ok(html.includes(`rel="modulepreload" href="/${m}"`), `the page preloads ${m}`);
for (const m of ["git-board.js", "git-board-view.js", "pr-url.js"]) assert.ok(html.includes(`rel="modulepreload" href="${m}"`), `the page preloads ${m}`);
const selectors = fs.readFileSync(path.join(dir, "selectors.js"), "utf8");
assert.match(selectors, /const isGitBoard = \(\) => page\.S && page\.S\.workflow === "git" && page\.S\.git;/);
assert.match(view, /a\.rel = "noopener"/, "the PR link opens with rel=noopener");
+1 -1
View File
@@ -2297,7 +2297,7 @@ test("page: the Workspace dialog, meter pill and new modules are in the page, wi
assert.ok(pill, "the pill sits in .ident");
assert.ok(pill[0].includes('class="meter-track"') && pill[0].includes('class="meter-fill"'));
for (const m of ["workspace.js", "meter.js", "mentions.js", "favicon.js"]) {
assert.ok(html.includes(`rel="modulepreload" href="/${m}"`), `the page preloads ${m}`);
assert.ok(html.includes(`rel="modulepreload" href="${m}"`), `the page preloads ${m}`);
}
// The CSP refuses style attributes and inline script: the new markup has neither.
const added = [
+18 -13
View File
@@ -144,14 +144,14 @@ test("pictures: JPEG only, listed oldest first, with thumbnails when sent", () =
const first = addImage(folder, tab, JPEG);
const second = addImage(folder, tab, JPEG);
assert.match(first.id, IMAGE_ID_RE);
assert.equal(first.url, `/notepad/images/${tab}/${first.id}.jpg`);
assert.equal(first.url, `notepad/images/${tab}/${first.id}.jpg`);
// Make the order unambiguous: the first is older.
const older = new Date(Date.now() - 60_000);
fs.utimesSync(path.join(tabDir(folder, tab), "images", first.id + ".jpg"), older, older);
addThumb(folder, tab, second.id, JPEG);
assert.deepEqual(readNotepad(folder).images, [
{ id: first.id, url: first.url, thumb: null },
{ id: second.id, url: second.url, thumb: `/notepad/images/${tab}/${second.id}.thumb.jpg` },
{ id: second.id, url: second.url, thumb: `notepad/images/${tab}/${second.id}.thumb.jpg` },
]);
});
@@ -509,8 +509,8 @@ test("the first shape reads as one Notes tab, and the read writes nothing", () =
[U1, U2],
"oldest first",
);
assert.equal(read.images[0].url, `/notepad/images/${LEGACY_TAB_ID}/${U1}.jpg`);
assert.equal(read.images[0].thumb, `/notepad/images/${LEGACY_TAB_ID}/${U1}.thumb.jpg`);
assert.equal(read.images[0].url, `notepad/images/${LEGACY_TAB_ID}/${U1}.jpg`);
assert.equal(read.images[0].thumb, `notepad/images/${LEGACY_TAB_ID}/${U1}.thumb.jpg`);
assert.equal(read.images[1].thumb, null);
assert.deepEqual(listTabs(folder), { tabs: [{ id: LEGACY_TAB_ID, name: "Notes" }], last: LEGACY_TAB_ID });
assert.equal(readNotepad(folder, LEGACY_TAB_ID).text, "old note\n");
@@ -564,7 +564,7 @@ test("any first write migrates: a picture, a new tab, and an old picture can be
const f2 = freshFolder("legacy");
legacyNotepad(f2);
const added = addImage(f2, LEGACY_TAB_ID, JPEG);
assert.equal(added.url, `/notepad/images/${LEGACY_TAB_ID}/${added.id}.jpg`);
assert.equal(added.url, `notepad/images/${LEGACY_TAB_ID}/${added.id}.jpg`);
assert.equal(readNotepad(f2).images.length, 3);
// A first-shape notepad with a picture and no note still migrates.
const f3 = freshFolder("legacy");
@@ -718,7 +718,10 @@ test("pictures through the routes: upload, thumb, fetch, delete and every refusa
const up = await postJpeg(s, "/notepad/image", JPEG);
assert.equal(up.status, 200);
const { id, url } = await up.json();
const { id, url: link } = await up.json();
assert.doesNotMatch(link, /^\//, "page-relative");
// The page at / asks for it here.
const url = `/${link}`;
assert.match(id, IMAGE_ID_RE);
const unknownThumb = await postJpeg(s, "/notepad/thumb?id=00000000-0000-0000-0000-000000000000", JPEG);
@@ -853,7 +856,7 @@ test("GET /notepad answers a notepad still in the first shape as a Notes tab, an
assert.equal(res.body.text, "old note\n");
assert.equal(res.body.images.length, 2);
assert.deepEqual(treeOf(dir), before, "the read wrote nothing");
const img = await fetch(`${s.base}${res.body.images[0].url}`, { headers: { cookie: s.cookie, connection: "close" } });
const img = await fetch(`${s.base}/${res.body.images[0].url}`, { headers: { cookie: s.cookie, connection: "close" } });
assert.equal(img.status, 200, "the picture is served from where it still is");
// The unchanged page's save, with no tab named, lands in Notes and migrates.
assert.equal((await s.send("/notepad/text", { text: "page save" })).status, 200);
@@ -1004,16 +1007,18 @@ test("pictures through ?tab=: upload, thumb, fetch and delete, each under the ta
const up = await postJpeg(s, `/notepad/image?tab=${a}`, JPEG);
assert.equal(up.status, 200);
const { id, url } = await up.json();
assert.equal(url, `/notepad/images/${a}/${id}.jpg`);
assert.equal(url, `notepad/images/${a}/${id}.jpg`);
// Page-relative: the page at / asks for it here.
const served = `/${url}`;
assert.equal((await postJpeg(s, `/notepad/thumb?tab=${a}&id=${id}`, JPEG)).status, 200);
assert.equal((await get(url)).status, 200);
assert.equal((await get(served)).status, 200);
assert.equal((await get(`/notepad/images/${a}/${id}.thumb.jpg`)).status, 200);
// Not under another tab, not in the old shape, not under a tab that is not there.
assert.equal((await get(`/notepad/images/${b}/${id}.jpg`)).status, 404);
assert.equal((await get(`/notepad/images/${id}.jpg`)).status, 404);
assert.equal((await get(`/notepad/images/ffffffffffff/${id}.jpg`)).status, 404);
assert.deepEqual((await getJson(s, `/notepad?tab=${b}`)).body.images, []);
assert.equal((await getJson(s, `/notepad?tab=${a}`)).body.images[0].thumb, `/notepad/images/${a}/${id}.thumb.jpg`);
assert.equal((await getJson(s, `/notepad?tab=${a}`)).body.images[0].thumb, `notepad/images/${a}/${id}.thumb.jpg`);
// A picture or thumb for a tab that is not there, and a delete from the wrong tab.
const stray = await postJpeg(s, "/notepad/image?tab=ffffffffffff", JPEG);
assert.equal(stray.status, 404);
@@ -1022,12 +1027,12 @@ test("pictures through ?tab=: upload, thumb, fetch and delete, each under the ta
assert.equal((await postJpeg(s, `/notepad/image?tab=nope`, JPEG)).status, 404);
assert.equal((await s.send(`/notepad/image/delete?tab=${b}`, { id })).status, 404, "tab B does not hold it");
assert.equal((await s.send(`/notepad/image/delete?tab=ffffffffffff`, { id })).status, 404);
assert.equal((await get(url)).status, 200, "still there");
assert.equal((await get(served)).status, 200, "still there");
assert.equal((await s.send(`/notepad/image/delete?tab=${a}`, { id })).status, 200);
assert.equal((await get(url)).status, 404);
assert.equal((await get(served)).status, 404);
// With no tab named, the picture goes to the last tab used.
const unnamed = await (await postJpeg(s, "/notepad/image", JPEG)).json();
assert.equal(unnamed.url.split("/")[3], b);
assert.equal(unnamed.url.split("/")[2], b);
assert.equal((await s.send("/notepad/image/delete", { id: unnamed.id })).status, 200);
assert.deepEqual(await (await postJpeg(s, "/notepad/thumb?id=00000000-0000-0000-0000-000000000000", JPEG)).json(), { error: "not-found" });
});
+3 -2
View File
@@ -579,7 +579,7 @@ test("each tab keeps its own text and pictures, and switching never saves into t
await tabNamed(s, "Ideas").click();
await s.page.waitForFunction(() => document.querySelectorAll("#notepad-strip > li.is-ready").length === 1);
const src = await s.page.locator("#notepad-strip img").getAttribute("src");
assert.match(src, new RegExp(`^/notepad/images/${ideas}/`), "the picture's address names its tab");
assert.match(src, new RegExp(`^notepad/images/${ideas}/`), "the picture's address names its tab");
// A save that cannot reach the server keeps you on the tab, with why.
await s.page.route("**/notepad/text*", (route) => route.abort());
@@ -1009,7 +1009,8 @@ test("the preview opens at the clicked picture, steps and wraps, and Esc closes
const s = await openSession(await suite.browser(), { t, workflow: "plan", payload: PLAN_QUESTION });
await openNotepad(s);
for (const color of ["#c33", "#3c3", "#33c"]) await addViaButton(s, color);
const urls = stored(s).map((img) => img.url);
// Page-relative: the page at / shows each one here.
const urls = stored(s).map((img) => `/${img.url}`);
const shown = () =>
s.page.evaluate(() => ({
src: new URL(document.getElementById("picview-img").src).pathname,
+1 -1
View File
@@ -432,7 +432,7 @@ test("kept attachments are served read-only from the session's spec, by their ex
assert.match(kept, /realpathSync/);
assert.match(kept, /path\.dirname\(real\)\.toLowerCase\(\) !== realDir\.toLowerCase\(\)/, "only files directly in attachments/");
const render = fs.readFileSync(path.join(ROOT, "src", "web-console", "public", "render.js"), "utf8");
assert.match(render, /return "\/attachments\/" \+ kept\[1\]\.toLowerCase\(\)/);
assert.match(render, /return "attachments\/" \+ kept\[1\]\.toLowerCase\(\)/);
assert.match(render, /function isComment\(t\)/, "HTML comments are not shown");
assert.match(render, /"!": \{ mark: "!", label: "blocked"/, "a blocked task gets its marker");
});
+182
View File
@@ -0,0 +1,182 @@
// Web console tests, the page's URLs: every URL the page uses is page-relative.
// The macOS app's frame gets no cookie, so it signs in by a path prefix
// (`/f/<key>/`, routes.mjs) and the page is served under it there, while a
// browser tab has it at `/`. A relative `state` reaches the server either
// way; a slash-leading `/state` drops the prefix and gets a 403, in the macOS
// app only, so no other test would notice. This guard reads the page's source
// (and the links the server hands it) and names each slash-leading one.
// Run with: node --test scripts/test-web-console-relative-urls.mjs
import test from "node:test";
import assert from "node:assert/strict";
import fs from "node:fs";
import path from "node:path";
import { ROOT } from "./web-console-test-helpers.mjs";
const CONSOLE_DIR = path.join(ROOT, "src", "web-console");
const PUBLIC_DIR = path.join(CONSOLE_DIR, "public");
const WHY = "the macOS app serves the page under /f/<key>/, so a slash-leading URL misses the prefix and gets a 403 there; drop the leading slash";
// Slash-leading text that is not a URL. Any literal opening `/plan2code` is a
// slash command (no route starts so); anything else is named here, by file
// and exact literal, with its reason.
const SLASH_COMMAND = /^.\/plan2code(?![\w/])|^.\/plan2code-/;
const TEXT = new Map([
["answers.js", new Set(["`/${offer.skill}`"])], // a skill offer's slash command
["diff-parse.js", new Set(['"/dev/null"'])], // git's name for no file in a diff header, compared, never fetched
["loop-parts.js", new Set(['"/api/webhooks/"'])], // a path test on a Discord address the person typed
["skills.js", new Set(['"/"'])], // `"/" + entry.skill`, a skill's slash command
]);
// Every page file the rule reads: scripts, the page and stylesheets under
// public/, vendored code aside, as paths relative to it with forward slashes.
function pageFiles(rel = "") {
const out = [];
for (const e of fs.readdirSync(path.join(PUBLIC_DIR, rel), { withFileTypes: true })) {
const p = rel ? `${rel}/${e.name}` : e.name;
if (e.isDirectory()) {
if (p !== "vendor") out.push(...pageFiles(p));
} else if (/\.(js|html|css)$/.test(e.name)) out.push(p);
}
return out;
}
/**
* Each string literal in `text` (double quotes, single quotes or backticks)
* that makes a slash-leading URL, as `{ line, literal }`, in three shapes:
* text opening with `/` and a path character (a letter, digit, `_`, `.`, `-`
* or `${`); a lone `"/"` that starts an expression joined on with `+`
* (`fetch("/" + route)`; one joined in the middle of a path is fine); and
* markup in a string whose `src`, `href` or like attribute opens with `/`
* (`` `<img src="/x">` ``). A comment line and anything after a `//` outside
* a string are skipped; `//` opening a string is the protocol-relative case,
* which render.js blocks on its own. Quotes are tracked one line at a time, so
* a template literal that spans lines, or a regex literal holding a quote,
* can put the scan out of step for the rest of that line: a URL there goes
* unflagged, and only the frame page test, which loads the dashboard alone,
* would catch it at run time.
*/
function scriptUrls(text) {
const hits = [];
text.split("\n").forEach((line, i) => {
const t = line.trim();
if (t.startsWith("//") || t.startsWith("*") || t.startsWith("/*")) return;
for (let j = 0; j < line.length; j++) {
const c = line[j];
if (c === "/" && line[j + 1] === "/") break;
if (c !== '"' && c !== "'" && c !== "`") continue;
let k = j + 1;
while (k < line.length && line[k] !== c) k += line[k] === "\\" ? 2 : 1;
const body = line.slice(j + 1, k);
const opens = body[0] === "/" && /[A-Za-z0-9_.$-]/.test(body[1] || "");
const joined = body === "/" && /^\s*\+/.test(line.slice(k + 1)) && STARTS_EXPRESSION.test(line.slice(0, j));
if (opens || joined || ATTRIBUTE_URL.test(body)) hits.push({ line: i + 1, literal: line.slice(j, k + 1) });
j = k;
}
});
return hits;
}
// What may come right before an expression's first operand: nothing, an
// opening bracket, a separator, an operator or `return`.
const STARTS_EXPRESSION = /(?:^|[([{,=:?!&|>]|\breturn)\s*$/;
// An attribute that holds a URL, opening with `/` (but not `//`), in markup a
// script builds, quoted or not and with its quote escaped or not.
const ATTRIBUTE_URL = /\b(?:src|srcset|href|action|poster|data)=\\?["']?\/(?![/\\])/;
/** Each `src`, `srcset`, `href`, `action`, `poster` or `data` value opening with `/`, in either quotes. */
function htmlUrls(text) {
return text
.split("\n")
.flatMap((l, i) =>
[...l.matchAll(/\b(?:src|srcset|href|action|poster|data)=(?:"(\/[^"]*)"|'(\/[^']*)')/g)].map((m) => ({ line: i + 1, literal: m[1] ?? m[2] }))
);
}
/** Each `url(/...)` or `@import "/..."`. */
function cssUrls(text) {
return text
.split("\n")
.flatMap((l, i) => [...l.matchAll(/url\(\s*["']?(\/[^)"']*)|@import\s+["'](\/[^"']*)/g)].map((m) => ({ line: i + 1, literal: m[1] || m[2] })));
}
// A link the server builds for the page: a slash-leading literal given to a
// name holding `url`, `href` or `src` (`url: "/uploads/..."`, `imageUrl = (...) => "/..."`).
const SERVER_LINK = /\b\w*(?:url|href|src)\w*\s*[:=]\s*(?:\([^)]*\)\s*=>\s*)?["'`]\/(?!\/)/i;
function pageOffenders() {
const out = [];
for (const f of pageFiles()) {
const text = fs.readFileSync(path.join(PUBLIC_DIR, f), "utf8");
if (f.endsWith(".html")) {
out.push(...htmlUrls(text).map((h) => ({ file: f, ...h })));
continue;
}
if (f.endsWith(".css")) {
out.push(...cssUrls(text).map((h) => ({ file: f, ...h })));
continue;
}
for (const h of scriptUrls(text)) {
if (SLASH_COMMAND.test(h.literal) || TEXT.get(f)?.has(h.literal)) continue;
out.push({ file: f, ...h });
}
}
return out.map((h) => `public/${h.file}:${h.line} ${h.literal}`);
}
test("the scanner finds slash-leading literals and leaves comments, other schemes and slash commands alone", () => {
const found = (src) => scriptUrls(src).map((h) => h.literal);
assert.deepEqual(found('fetch("/state");'), ['"/state"']);
assert.deepEqual(found("x('/looks', `/${a}.mp3`)"), ["'/looks'", "`/${a}.mp3`"]);
assert.deepEqual(found('a("state"); b("https://x/y"); c("//cdn"); d("/");'), []);
assert.deepEqual(found('// fetch("/state")'), []);
assert.deepEqual(found(' * see "/state"'), []);
assert.deepEqual(found('go(); // then "/state"'), []);
assert.deepEqual(found('q("a\\"/b", "/c")'), ['"/c"']);
// A slash joined on at the start of an expression, and markup holding one.
assert.deepEqual(found('fetch("/" + route); x = "/" + y; return "/" + z;'), ['"/"', '"/"', '"/"']);
assert.deepEqual(found('a("notepad/images/" + tab + "/" + id); b(sep ? "/" : "")'), []);
assert.deepEqual(found('box.innerHTML = `<img src="/uploads/${id}.jpg">`;'), ['`<img src="/uploads/${id}.jpg">`']);
assert.deepEqual(found("h = '<a href=\\'/state\\'>'; s = \"<img src=\\\"/x.png\\\">\";").length, 2);
assert.deepEqual(found('h = `<img src="uploads/${id}.jpg"><a href="//cdn/x">`'), []);
assert.ok(SLASH_COMMAND.test('"/plan2code"') && SLASH_COMMAND.test('"/plan2code-review"'));
assert.ok(!SLASH_COMMAND.test('"/plan2codex"') && !SLASH_COMMAND.test('"/plan2code/x"'));
assert.deepEqual(htmlUrls('<link href="/app.css" /><script src="app.js"></script>'), [{ line: 1, literal: "/app.css" }]);
assert.deepEqual(htmlUrls("<img src='/x.png' srcset=\"/y.png 2x\">"), [
{ line: 1, literal: "/x.png" },
{ line: 1, literal: "/y.png 2x" },
]);
assert.deepEqual(cssUrls("a { background: url(/x.png) } @import \"/y.css\";"), [
{ line: 1, literal: "/x.png" },
{ line: 1, literal: "/y.css" },
]);
assert.ok(SERVER_LINK.test('url: "/uploads/" + id'));
assert.ok(SERVER_LINK.test('const imageUrl = (tab, id) => "/notepad/images/" + tab'));
assert.ok(!SERVER_LINK.test('url: "uploads/" + id') && !SERVER_LINK.test('{ path: "/state", run }'));
});
test("every URL in the page is page-relative", () => {
const offenders = pageOffenders();
assert.deepEqual(offenders, [], `${offenders.length} slash-leading URL(s) in the page (${WHY}):\n${offenders.join("\n")}`);
});
test("every link the server hands the page is page-relative", () => {
const offenders = [];
for (const f of fs.readdirSync(CONSOLE_DIR).filter((n) => n.endsWith(".mjs"))) {
fs.readFileSync(path.join(CONSOLE_DIR, f), "utf8")
.split("\n")
.forEach((l, i) => {
if (!l.trim().startsWith("//") && SERVER_LINK.test(l)) offenders.push(`${f}:${i + 1} ${l.trim()}`);
});
}
assert.deepEqual(offenders, [], `slash-leading link(s) the server builds for the page (${WHY}):\n${offenders.join("\n")}`);
});
test("every name the rule lets through is still in its file", () => {
for (const [file, literals] of TEXT) {
const found = new Set(scriptUrls(fs.readFileSync(path.join(PUBLIC_DIR, file), "utf8")).map((h) => h.literal));
for (const literal of literals) assert.ok(found.has(literal), `${file} no longer has ${literal}: drop it from TEXT`);
}
});
+1 -1
View File
@@ -83,7 +83,7 @@ test("the page carries its first state, title and badge, so the first paint need
assert.ok(html.includes(`<h1 id="title">Lunch &lt;/script&gt;&lt;script&gt;alert(1)&lt;/script&gt; $&amp; $&#39; app</h1>`));
assert.ok(html.includes('<span class="pill is-accent is-caps badge" id="badge">Building</span>'));
assert.ok(html.includes("Starting Implement"), "the static starting screen names the skill");
assert.ok(html.includes('rel="modulepreload" href="/app.js"'));
assert.ok(html.includes('rel="modulepreload" href="app.js"'));
cli(["stop", "--session", res.json.sid, "--force"]);
});
+7 -5
View File
@@ -685,8 +685,8 @@ test("the favicon is served as an SVG with a PNG fallback and the page points at
assert.deepEqual([...bytes.slice(0, 4)], [0x89, 0x50, 0x4e, 0x47]);
const html = await (await fetch(baseUrl + "/", { headers: { cookie: cookieFor(baseUrl, token) } })).text();
assert.ok(html.includes('href="/favicon.svg"'));
assert.ok(html.includes('href="/favicon.png"'));
assert.ok(html.includes('href="favicon.svg"'));
assert.ok(html.includes('href="favicon.png"'));
assert.doesNotMatch(html, /rel="icon"[^>]*href="data:/);
});
@@ -1006,7 +1006,7 @@ test("an upload is stored under a server-chosen name inside the session's upload
const uploads = path.join(fs.realpathSync.native(session), "uploads");
assert.equal(path.dirname(file).toLowerCase(), uploads.toLowerCase());
assert.equal(path.basename(file), id + ".jpg");
assert.equal(url, `/uploads/${id}.jpg`);
assert.equal(url, `uploads/${id}.jpg`);
assert.equal(name, "../../evil name.png", "the name comes back as a label");
assert.equal(res.json.kind, "image");
assert.equal(res.json.size, JPEG.length);
@@ -1035,7 +1035,8 @@ test("an upload that is not a JPEG, or is too large, is refused", async () => {
});
test("an upload is served back by its own url, and nothing else under /uploads/ is", async () => {
const { url } = (await uploadJpeg()).json;
// Page-relative: the page at / asks for it here.
const url = `/${(await uploadJpeg()).json.url}`;
const res = await raw("GET", url);
assert.equal(res.status, 200);
assert.equal(res.headers["content-type"], "image/jpeg");
@@ -1048,7 +1049,8 @@ test("an upload is served back by its own url, and nothing else under /uploads/
});
test("deleting an upload removes its file, once, and only from this origin", async () => {
const { url, path: file } = (await uploadJpeg()).json;
const { url: link, path: file } = (await uploadJpeg()).json;
const url = `/${link}`;
assert.equal((await raw("DELETE", url, undefined, { origin: "http://evil.example.com" })).status, 403);
assert.ok(fs.existsSync(file));
assert.equal((await raw("DELETE", url)).status, 204);
+1 -1
View File
@@ -516,7 +516,7 @@ test("prefs: the new modules are served and preloaded, and Preferences' styles l
"screens/agents/agents-form.js",
]) {
assert.ok(SERVABLE.has(m), `${m} is servable`);
assert.ok(html.includes(`rel="modulepreload" href="/${m}"`), `the page preloads ${m}`);
assert.ok(html.includes(`rel="modulepreload" href="${m}"`), `the page preloads ${m}`);
}
for (const sheet of ["styles/prefs.css", "styles/agents.css"]) {
const css = publicSource(sheet);
+3 -3
View File
@@ -497,7 +497,7 @@ test("music: a song plays from its file, fades in toward its level, says when it
withSongs(async () => {
const [name] = TRAILS_TRACKS;
assert.equal(music(name, 1, 1, { restart: true }), "playing");
const el = FakeAudio.made.find((a) => a.src === `/${trailsSfx.songs[name]}`);
const el = FakeAudio.made.find((a) => a.src === trailsSfx.songs[name]);
assert.ok(el, "an element for the song's file");
assert.ok(!el.paused && el.plays === 1, "it plays");
for (let i = 0; i < 20; i++) {
@@ -520,7 +520,7 @@ test("music: a song no longer asked for fades out and pauses where it was, and a
withSongs(async () => {
const [first, second] = TRAILS_TRACKS;
music(first, 1, 0.5);
const el = FakeAudio.made.findLast((a) => a.src === `/${trailsSfx.songs[first]}`);
const el = FakeAudio.made.findLast((a) => a.src === trailsSfx.songs[first]);
const loads = el.loads;
await sleep(800);
assert.ok(el.paused, "paused once it stops being asked for");
@@ -544,7 +544,7 @@ test("music: a song plays nothing while Play sounds is off, at a volume of 0, or
assert.equal(music(name, 1, 0), undefined);
globalThis.Audio = undefined;
assert.equal(music(name, 1, 1), undefined);
assert.ok(FakeAudio.made.filter((a) => a.src === `/${trailsSfx.songs[name]}`).every((a) => a.paused), "nothing plays");
assert.ok(FakeAudio.made.filter((a) => a.src === trailsSfx.songs[name]).every((a) => a.paused), "nothing plays");
}));
test("music: every Sunset Drive road has a song, and every song is a real track", () => {