- accept wildcard proxy host domains like *.example.com with validation and normalization - make exact hosts win over overlapping wildcards in generated routes and TLS policies - add unit coverage for host-pattern priority and wildcard domain handling - add a single test:all entry point and clean up lint/typecheck issues so the suite runs cleanly - run mobile layout Playwright checks under both chromium and mobile-iphone
40 lines
1.5 KiB
TypeScript
40 lines
1.5 KiB
TypeScript
import { describe, expect, it } from "vitest";
|
|
import { isValidProxyHostDomain, normalizeProxyHostDomains } from "@/src/lib/proxy-host-domains";
|
|
|
|
describe("isValidProxyHostDomain", () => {
|
|
it("accepts standard hostnames", () => {
|
|
expect(isValidProxyHostDomain("app.example.com")).toBe(true);
|
|
expect(isValidProxyHostDomain("localhost")).toBe(true);
|
|
});
|
|
|
|
it("accepts wildcard hostnames on the left-most label", () => {
|
|
expect(isValidProxyHostDomain("*.example.com")).toBe(true);
|
|
expect(isValidProxyHostDomain("*.local")).toBe(true);
|
|
});
|
|
|
|
it("rejects wildcard hostnames outside the left-most label", () => {
|
|
expect(isValidProxyHostDomain("api.*.example.com")).toBe(false);
|
|
expect(isValidProxyHostDomain("*.*.example.com")).toBe(false);
|
|
expect(isValidProxyHostDomain("example.*")).toBe(false);
|
|
});
|
|
|
|
it("accepts IP literals", () => {
|
|
expect(isValidProxyHostDomain("192.168.1.10")).toBe(true);
|
|
expect(isValidProxyHostDomain("2001:db8::1")).toBe(true);
|
|
});
|
|
});
|
|
|
|
describe("normalizeProxyHostDomains", () => {
|
|
it("normalizes case, strips trailing dots, and deduplicates domains", () => {
|
|
expect(
|
|
normalizeProxyHostDomains([" *.Example.com. ", "APP.EXAMPLE.COM", "*.example.com"])
|
|
).toEqual(["*.example.com", "app.example.com"]);
|
|
});
|
|
|
|
it("throws a helpful error for invalid wildcard placement", () => {
|
|
expect(() => normalizeProxyHostDomains(["api.*.example.com"])).toThrow(
|
|
'Invalid domain "api.*.example.com". Wildcards are supported only as the left-most label, for example "*.example.com".'
|
|
);
|
|
});
|
|
});
|