mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-13 08:40:42 +00:00
test: tighten proxy schema rejection
This commit is contained in:
@@ -1,6 +1,15 @@
|
||||
import { describe, it, expect } from "vitest";
|
||||
import { ProxyConfigSchema } from "./zod-schema.proxy.js";
|
||||
|
||||
function expectProxyConfigFailure(value: unknown) {
|
||||
const result = ProxyConfigSchema.safeParse(value);
|
||||
expect(result.success).toBe(false);
|
||||
if (result.success) {
|
||||
throw new Error("Expected proxy config to fail schema validation.");
|
||||
}
|
||||
return result.error.issues;
|
||||
}
|
||||
|
||||
describe("ProxyConfigSchema", () => {
|
||||
it("accepts undefined (optional)", () => {
|
||||
expect(ProxyConfigSchema.parse(undefined)).toBeUndefined();
|
||||
@@ -32,7 +41,8 @@ describe("ProxyConfigSchema", () => {
|
||||
});
|
||||
|
||||
it("rejects unknown loopbackMode values", () => {
|
||||
expect(() => ProxyConfigSchema.parse({ loopbackMode: "bypass" })).toThrow();
|
||||
const issues = expectProxyConfigFailure({ loopbackMode: "bypass" });
|
||||
expect(issues.map((issue) => issue.path.join("."))).toContain("loopbackMode");
|
||||
});
|
||||
|
||||
it("rejects HTTPS proxy URLs because the node:http routing layer requires HTTP proxies", () => {
|
||||
@@ -53,14 +63,18 @@ describe("ProxyConfigSchema", () => {
|
||||
});
|
||||
|
||||
it("rejects proxyUrl values that are not HTTP forward proxies", () => {
|
||||
expect(() =>
|
||||
ProxyConfigSchema.parse({ enabled: true, proxyUrl: "socks5://127.0.0.1" }),
|
||||
).toThrow();
|
||||
expect(() => ProxyConfigSchema.parse({ enabled: true, proxyUrl: "not-a-url" })).toThrow();
|
||||
const socksIssues = expectProxyConfigFailure({
|
||||
enabled: true,
|
||||
proxyUrl: "socks5://127.0.0.1",
|
||||
});
|
||||
const invalidUrlIssues = expectProxyConfigFailure({ enabled: true, proxyUrl: "not-a-url" });
|
||||
expect(socksIssues.map((issue) => issue.path.join("."))).toContain("proxyUrl");
|
||||
expect(invalidUrlIssues.map((issue) => issue.path.join("."))).toContain("proxyUrl");
|
||||
});
|
||||
|
||||
it("rejects unknown keys (strict)", () => {
|
||||
expect(() => ProxyConfigSchema.parse({ unknownKey: true })).toThrow();
|
||||
const issues = expectProxyConfigFailure({ unknownKey: true });
|
||||
expect(issues[0]?.code).toBe("unrecognized_keys");
|
||||
});
|
||||
|
||||
it("accepts enabled: false to disable the proxy", () => {
|
||||
|
||||
Reference in New Issue
Block a user