// LV-2: homograph detector tests. import { describe, expect, it } from "vitest"; import { detectHomograph, getSecurityOriginDisplay } from "./domain"; describe("detectHomograph", () => { it("flags a hostname with non-ASCII (Cyrillic homograph) characters", () => { // "аpple.com" — leading а is Cyrillic U+0430, not Latin a. expect(detectHomograph("https://аpple.com")).toBe(true); }); it("flags a punycode (xn--) label", () => { expect(detectHomograph("https://xn--pple-43d.com")).toBe(true); }); it("accepts a bare hostname without a scheme", () => { expect(detectHomograph("xn--pple-43d.com")).toBe(true); }); it("returns false for a plain ASCII domain", () => { expect(detectHomograph("https://apple.com")).toBe(false); }); it("returns false for malformed input", () => { expect(detectHomograph("")).toBe(false); expect(detectHomograph("http://")).toBe(false); }); }); describe("getSecurityOriginDisplay", () => { it("PB-26-707/PB-26-710 preserves scheme, full hostname, and non-default port", () => { expect(getSecurityOriginDisplay("https://login.accounts.example.com:8443/sign-in?next=/vault")) .toBe("https://login.accounts.example.com:8443"); }); it("keeps invalid input visible instead of inventing a trusted origin", () => { expect(getSecurityOriginDisplay("not a URL")).toBe("not a URL"); }); });