UNPKG

@fiberplane/hono-otel

Version:

Hono middleware to forward OpenTelemetry traces to a local instance of @fiberplane/studio

57 lines (56 loc) 2.56 kB
import { describe, expect, it } from "vitest"; import { getSafeHeaderValue } from "./headers.js"; const baseConfig = { enabled: true, mode: "production", redactedHeaders: new Set(), redactedQueryParams: new Set(), otelEndpoint: "http://localhost:4318", otelToken: "", logLevel: "debug", serviceName: "test-service", libraryDebugMode: false, monitor: { fetch: true, logging: true, cfBindings: true, }, }; describe("request utils", () => { describe("getSafeHeaderValue", () => { it("should not redact headers when tracing everything", () => { const config = { ...baseConfig, mode: "local", redactedHeaders: new Set(["authorization", "x-api-key"]), }; expect(getSafeHeaderValue("authorization", "Bearer token123", config)).toBe("Bearer token123"); expect(getSafeHeaderValue("x-api-key", "secret-key", config)).toBe("secret-key"); expect(getSafeHeaderValue("content-type", "application/json", config)).toBe("application/json"); }); it("should redact sensitive headers when not tracing everything", () => { const config = { ...baseConfig, mode: "production", redactedHeaders: new Set(["authorization", "x-api-key"]), }; expect(getSafeHeaderValue("authorization", "Bearer token123", config)).toBe("REDACTED"); expect(getSafeHeaderValue("x-api-key", "secret-key", config)).toBe("REDACTED"); expect(getSafeHeaderValue("content-type", "application/json", config)).toBe("application/json"); }); it("should handle header names case-insensitively", () => { const config = { ...baseConfig, mode: "production", redactedHeaders: new Set(["authorization"]), }; expect(getSafeHeaderValue("Authorization", "Bearer token123", config)).toBe("REDACTED"); expect(getSafeHeaderValue("AUTHORIZATION", "Bearer token123", config)).toBe("REDACTED"); expect(getSafeHeaderValue("authorization", "Bearer token123", config)).toBe("REDACTED"); }); it("should handle undefined config by defaulting to REDACTED", () => { expect(getSafeHeaderValue("authorization", "Bearer token123")).toBe("REDACTED"); expect(getSafeHeaderValue("content-type", "application/json")).toBe("application/json"); }); }); });