import { describe, expect, it } from "vitest"; import { HOST_WORDS } from "@/worker/auth/host-wordlist"; import { classifyHost } from "@/worker/routes/host"; const env = { CONTROL_PLANE_HOST: "dav.example.com", SUBJECT_HOST_SUFFIX: ".dav.example.com", } as Env; const blockedHostWords = [ "abbot", "acne", "acolyte", "allergy", "alleluia", "altar", "anal", "anatomy", "anarchic", "anarchy", "anathema", "anatomic", "aneurysm", "angel", "angelic", "apostle", "artery", "baptist", "baptize", "bladder", "bone", "bonehead", "boner", "bondage", "brothel", "cardiac", "chapel", "chaplain", "chaplet", "cholera", "choir", "clinic", "coke", "coital", "cough", "crania", "cranium", "crazy", "crucifix", "crozier", "deify", "deism", "deity", "diocese", "dioxin", "divine", "divinely", "divinity", "dumb", "erotica", "fart", "fat", "fatter", "fattest", "fascism", "fascist", "genital", "genetic", "genome", "gonad", "hiccough", "hormone", "hormonal", "horniest", "jeep", "lama", "lavatory", "lunatic", "lust", "lustful", "lustily", "messiah", "monk", "moron", "morphine", "nipple", "opioid", "organ", "organist", "papal", "pastor", "pepsin", "plague", "pope", "prayer", "psalmist", "religion", "saintly", "semen", "senator", "shaman", "soviet", "tendon", "therapy", "vicar", "wishbone", "wimp", "wound", ] as const; describe("host classification", () => { it("classifies the control-plane host", () => { const request = new Request("https://dav.example.com/healthz", { headers: { host: "dav.example.com" } }); expect(classifyHost(request, env)).toMatchObject({ kind: "control", normalizedHost: "dav.example.com" }); }); it("accepts valid five-word subject labels", () => { const request = new Request("https://river-copper-lantern-velvet-maple.dav.example.com/files/", { headers: { host: "river-copper-lantern-velvet-maple.dav.example.com" }, }); expect(classifyHost(request, env)).toMatchObject({ kind: "subject", hostLabel: "river-copper-lantern-velvet-maple", }); }); it("rejects malformed subject labels", () => { const request = new Request("https://not-enough-words.dav.example.com/files/", { headers: { host: "not-enough-words.dav.example.com" }, }); expect(classifyHost(request, env)).toMatchObject({ kind: "unknown" }); }); it("keeps the host wordlist at the required size without blocked terms", () => { expect(HOST_WORDS).toHaveLength(8192); expect(new Set(HOST_WORDS).size).toBe(HOST_WORDS.length); expect(HOST_WORDS).not.toEqual(expect.arrayContaining([...blockedHostWords])); }); });