Files
openclaw/src/proxy-capture/proxy-server.test.ts
2026-05-28 15:44:19 -04:00

25 lines
852 B
TypeScript

import { describe, expect, it } from "vitest";
import { parseConnectTarget } from "./proxy-server.js";
describe("parseConnectTarget", () => {
it("parses bracketed IPv6 CONNECT targets safely", () => {
expect(parseConnectTarget("[::1]:8443")).toEqual({
hostname: "::1",
port: 8443,
});
});
it("parses unbracketed host:port CONNECT targets", () => {
expect(parseConnectTarget("api.openai.com:443")).toEqual({
hostname: "api.openai.com",
port: 443,
});
});
it("rejects invalid CONNECT ports", () => {
expect(() => parseConnectTarget("[::1]:99999")).toThrow("Invalid CONNECT target port");
expect(() => parseConnectTarget("api.openai.com:1e3")).toThrow("Invalid CONNECT target port");
expect(() => parseConnectTarget("api.openai.com:0x50")).toThrow("Invalid CONNECT target port");
});
});