Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

deploymentConfig.test.ts

44 lines1.5 KB

1import { describe, expect, it } from "vite-plus/test";
2​
3import {
4 managedEndpointHostname,
5 isManagedEndpointHostname,
6 relayOwnsManagedEndpointZone,
7 RELAY_WORKER_OBSERVABILITY,
8} from "./deploymentConfig.ts";
9​
10describe("relay Worker observability", () => {
11 it("records request URLs only through the relay's own redacting spans", () => {
12 expect(RELAY_WORKER_OBSERVABILITY.logs).toEqual({
13 enabled: true,
14 invocationLogs: false,
15 headSamplingRate: 0.01,
16 });
17 });
18});
19​
20describe("relayOwnsManagedEndpointZone", () => {
21 it("keeps the shared Cloudflare zone owned by production", () => {
22 expect(relayOwnsManagedEndpointZone("prod")).toBe(true);
23 expect(relayOwnsManagedEndpointZone("dev_julius")).toBe(false);
24 });
25});
26​
27describe("managed endpoint names", () => {
28 it("keeps the DNS label within the provider limit for long stage names", () => {
29 const hostname = managedEndpointHostname(
30 "dev_" + "x".repeat(100),
31 "example.com",
32 "a".repeat(64),
33 );
34​
35 expect(hostname.split(".")[0]?.length).toBeLessThanOrEqual(63);
36 expect(hostname).toMatch(/-a{16}\.example\.com$/);
37 });
38​
39 it("rejects hostnames outside the relay zone", () => {
40 expect(isManagedEndpointHostname("internal.example.net", "example.com")).toBe(false);
41 expect(isManagedEndpointHostname("example.com.attacker.test", "example.com")).toBe(false);
42 expect(isManagedEndpointHostname("dev-julius.example.com.", "example.com")).toBe(false);
43 });
44});