import { describe, expect, test } from "bun:test"; import { editorOriginProblem } from "./origin-check"; const FORGE = "gitfor.dev"; const DOMAINS = { sites: "gitforstatic.dev" }; const check = (raw: string) => editorOriginProblem(raw, FORGE, DOMAINS); describe("editorOriginProblem", () => { test("accepts a dedicated editor host on the forge's domain", () => { expect(check("https://editor.gitfor.dev")).toBeNull(); }); test("rejects the forge host itself", () => { expect(check("https://gitfor.dev")).toContain("forge host"); expect(check("https://GITFOR.dev")).toContain("forge host"); }); test("rejects SITES_DOMAIN and its subdomains", () => { expect(check("https://gitforstatic.dev")).toContain("SITES_DOMAIN"); expect(check("https://editor.gitforstatic.dev")).toContain("SITES_DOMAIN"); }); test("does not confuse look-alike suffixes with the user-content domains", () => { expect(check("https://notgitforstatic.dev")).toBeNull(); }); test("requires https outside localhost", () => { expect(check("http://editor.gitfor.dev")).toContain("https"); }); test("allows plain http on localhost for dev", () => { expect(editorOriginProblem("http://editor.localhost:3000", "localhost", DOMAINS)).toBeNull(); }); test("rejects malformed URLs", () => { expect(check("editor.gitfor.dev")).toContain("not a valid URL"); expect(check("https://")).toContain("not a valid URL"); }); test("ignores unset user-content domains", () => { expect(editorOriginProblem("https://editor.gitfor.dev", FORGE, {})).toBeNull(); }); });