e7a1290246
Next.js 16 + Auth.js v5 skeleton: host→slug middleware, tenant-context layout, OIDC sign-in flow against breakpilot-dev realm. 100% coverage on src/lib. Bumps next to 16.2.6 to clear trivy CVEs in 15.0.3.
47 lines
1.9 KiB
TypeScript
47 lines
1.9 KiB
TypeScript
import { describe, expect, test } from "vitest";
|
|
import { parseHost } from "./host";
|
|
|
|
describe("parseHost", () => {
|
|
test("null host → unknown", () => {
|
|
expect(parseHost(null)).toEqual({ kind: "unknown" });
|
|
expect(parseHost(undefined)).toEqual({ kind: "unknown" });
|
|
expect(parseHost("")).toEqual({ kind: "unknown" });
|
|
});
|
|
|
|
test("apex hosts return apex", () => {
|
|
expect(parseHost("localhost")).toEqual({ kind: "apex" });
|
|
expect(parseHost("localhost:3000")).toEqual({ kind: "apex" });
|
|
expect(parseHost("breakpilot.com")).toEqual({ kind: "apex" });
|
|
expect(parseHost("stage.breakpilot.com")).toEqual({ kind: "apex" });
|
|
});
|
|
|
|
test("tenant subdomain returns slug", () => {
|
|
expect(parseHost("acme.localhost:3000")).toEqual({ kind: "tenant", slug: "acme" });
|
|
expect(parseHost("acme.breakpilot.com")).toEqual({ kind: "tenant", slug: "acme" });
|
|
expect(parseHost("acme.stage.breakpilot.com")).toEqual({ kind: "tenant", slug: "acme" });
|
|
});
|
|
|
|
test("backstage subdomain is reserved", () => {
|
|
expect(parseHost("backstage.localhost:3000")).toEqual({ kind: "backstage" });
|
|
expect(parseHost("backstage.breakpilot.com")).toEqual({ kind: "backstage" });
|
|
});
|
|
|
|
test("invalid slugs return unknown", () => {
|
|
expect(parseHost("a.localhost")).toEqual({ kind: "unknown" }); // too short (1 char)
|
|
expect(parseHost("foo_bar.localhost")).toEqual({ kind: "unknown" }); // underscore not allowed
|
|
expect(parseHost("FOO!.localhost")).toEqual({ kind: "unknown" }); // exclamation invalid
|
|
});
|
|
|
|
test("empty subdomain falls back to apex", () => {
|
|
expect(parseHost(".localhost")).toEqual({ kind: "apex" });
|
|
});
|
|
|
|
test("uppercase host is lowercased", () => {
|
|
expect(parseHost("ACME.LOCALHOST")).toEqual({ kind: "tenant", slug: "acme" });
|
|
});
|
|
|
|
test("unknown apex returns unknown", () => {
|
|
expect(parseHost("acme.example.com")).toEqual({ kind: "unknown" });
|
|
});
|
|
});
|