domain.homograph.test.ts

906 B · raw

1// LV-2: homograph detector tests.2import { describe, expect, it } from "vitest";3import { detectHomograph } from "./domain";45describe("detectHomograph", () => {6  it("flags a hostname with non-ASCII (Cyrillic homograph) characters", () => {7    // "аpple.com" — leading а is Cyrillic U+0430, not Latin a.8    expect(detectHomograph("https://аpple.com")).toBe(true);9  });1011  it("flags a punycode (xn--) label", () => {12    expect(detectHomograph("https://xn--pple-43d.com")).toBe(true);13  });1415  it("accepts a bare hostname without a scheme", () => {16    expect(detectHomograph("xn--pple-43d.com")).toBe(true);17  });1819  it("returns false for a plain ASCII domain", () => {20    expect(detectHomograph("https://apple.com")).toBe(false);21  });2223  it("returns false for malformed input", () => {24    expect(detectHomograph("")).toBe(false);25    expect(detectHomograph("http://")).toBe(false);26  });27});