mirror of
https://github.com/openclaw/openclaw.git
synced 2026-06-04 09:44:06 +00:00
25 lines
852 B
TypeScript
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");
|
|
});
|
|
});
|