Files
t3code/packages/shared/src/relayAuth.test.ts
T

27 lines
1.1 KiB
TypeScript

import { describe, expect, it } from "vitest";
import {
clerkFrontendApiHostnameFromPublishableKey,
isAllowedClerkFrontendApiHostname,
} from "./relayAuth.ts";
const clerkPublishableKey = (hostname: string): string => `pk_test_${btoa(`${hostname}$`)}`;
describe("Clerk relay auth", () => {
it("derives a custom Frontend API hostname from a Clerk publishable key", () => {
expect(clerkFrontendApiHostnameFromPublishableKey(clerkPublishableKey("clerk.t3.codes"))).toBe(
"clerk.t3.codes",
);
});
it("allows standard Clerk hosts and an exact configured custom hostname", () => {
expect(isAllowedClerkFrontendApiHostname("example.clerk.accounts.dev", null)).toBe(true);
expect(isAllowedClerkFrontendApiHostname("example.clerk.accounts.com", null)).toBe(true);
expect(isAllowedClerkFrontendApiHostname("clerk.t3.codes", "clerk.t3.codes")).toBe(true);
expect(isAllowedClerkFrontendApiHostname("attacker.example", "clerk.t3.codes")).toBe(false);
expect(isAllowedClerkFrontendApiHostname("nested.clerk.t3.codes", "clerk.t3.codes")).toBe(
false,
);
});
});