// This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. // The release's screenshots (docs/release.md): every shot's screen is drawn from the demo control // plane alone (each click and wait selector found, no call unanswered), and nothing the demo // serves or the page shows names a real host, address or person. import { cleanup, render, waitFor } from "@testing-library/svelte"; import { afterEach, describe, expect, it } from "vitest"; import App from "../src/App.svelte"; import { app } from "../src/lib/app.svelte"; import { SHOTS, demoApi } from "./demo"; const ALLOWED_TLDS = new Set(["test", "example", "invalid"]); const DOC_NETS = ["192.0.2.", "198.51.100.", "203.0.113."]; const FORBIDDEN = ["mark", "marek", "novak", "flowers", "esp32", "hyperv"]; /** What in a text could be real: addresses outside the documentation ranges, names outside .test. */ function realLooking(text: string): string[] { const found: string[] = []; for (const m of text.matchAll(/(? m[0].startsWith(n))) found.push(m[0]); } for (const m of text.matchAll(/(? { const url = typeof input === "string" ? input : input instanceof URL ? input.pathname + input.search : input.url; const path = url.replace(/^.*\/api\/v1/, ""); const a = api(init?.method ?? "GET", path, init?.body ? JSON.parse(String(init.body)) : {}); served.push({ status: a.status, path, text: a.text }); return new Response(a.text, { status: a.status, headers: { "Content-Type": "application/json" } }); }) as typeof fetch; render(App); } function pageText(): string[] { const out: string[] = []; const walk = document.createTreeWalker(document.body, NodeFilter.SHOW_TEXT); for (let n = walk.nextNode(); n; n = walk.nextNode()) if (n.textContent?.trim()) out.push(n.textContent); document.querySelectorAll("input, textarea").forEach((i) => out.push(i.value)); document.querySelectorAll("[href]").forEach((a) => out.push(a.getAttribute("href") ?? "")); return out; } afterEach(() => cleanup()); describe("realLooking", () => { it("passes invented names and refuses real-looking ones", () => { expect(realLooking("wiki.home.test http://192.0.2.10:3000 on 127.0.0.1 for ada")).toEqual([]); expect(realLooking("http://10.0.0.2:3000")).toEqual(["10.0.0.2"]); expect(realLooking("gitea.example.cz and Mark's phone")).toEqual(["gitea.example.cz", "mark"]); expect(realLooking("flowers.stage")).toEqual(["flowers.stage", "flowers"]); }); }); describe("the release's screenshots from the demo control plane", () => { for (const shot of SHOTS) { it(`${shot.name}: drawn from invented data only`, async () => { start(shot.path); for (const sel of shot.click ?? []) { const el = await waitFor(() => { const e = document.querySelector(sel); expect(e, `click ${sel}`).not.toBeNull(); return e as HTMLElement; }, { timeout: 5000 }); el.click(); } await waitFor(() => expect(document.querySelector(shot.wait), `wait ${shot.wait}`).not.toBeNull(), { timeout: 5000 }); expect(served.filter((s) => s.status === 404).map((s) => s.path)).toEqual([]); // Control's codes (apply.kept, pki.renew_due) are dotted words, not names. const json = served.map((s) => (s.text ?? "").replace(/"(?:code|message_code|error_code)":"[^"]*"/g, "")); const seen = [...json, ...pageText()]; expect(seen.flatMap(realLooking)).toEqual([]); }); } });