From 4e3de3574f4b4cf3a959944080179ea54df1bd42 Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Sat, 9 May 2026 01:22:45 +0100 Subject: [PATCH] test: tighten proxy schema rejection --- src/config/zod-schema.proxy.test.ts | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/src/config/zod-schema.proxy.test.ts b/src/config/zod-schema.proxy.test.ts index 6cb4f403ee9..3dbfef2b631 100644 --- a/src/config/zod-schema.proxy.test.ts +++ b/src/config/zod-schema.proxy.test.ts @@ -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", () => {