telemetry.test.ts 663 B

123456789101112131415161718
  1. import { describe, expect, it } from "vitest";
  2. import { resolveSafeTelemetryHostname } from "../src/telemetry.js";
  3. describe("resolveSafeTelemetryHostname", () => {
  4. it("只从 HTTP(S) URL 提取小写 hostname", () => {
  5. expect(
  6. resolveSafeTelemetryHostname("https://user:secret@API.Example.COM:8443/private?q=jwt"),
  7. ).toBe("api.example.com");
  8. expect(resolveSafeTelemetryHostname("http://127.0.0.1:64411")).toBe("127.0.0.1");
  9. });
  10. it.each(["", "api.example.com", "file:///private/path", "not a url"])(
  11. "拒绝非 URL 或非 HTTP(S) 值:%s",
  12. (value) => {
  13. expect(resolveSafeTelemetryHostname(value)).toBe("");
  14. },
  15. );
  16. });