From d5717974828251dfb8e0f8b6fceb4bf3705401c2 Mon Sep 17 00:00:00 2001 From: Ehab Younes Date: Tue, 27 Jan 2026 13:42:44 +0300 Subject: [PATCH 1/2] Fix proxy settings types when reading the configurations --- src/api/utils.ts | 6 +++--- test/unit/api/utils.test.ts | 22 ++++++++++++++++++++-- 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/src/api/utils.ts b/src/api/utils.ts index bc4a6f7a..2fa1abff 100644 --- a/src/api/utils.ts +++ b/src/api/utils.ts @@ -28,8 +28,8 @@ export async function createHttpAgent( ): Promise { const insecure = cfg.get("coder.insecure", false); const proxyStrictSSL = cfg.get("http.proxyStrictSSL", true); - const proxyAuthorization = cfg.get("http.proxyAuthorization"); - const httpNoProxy = cfg.get("http.noProxy"); + const proxyAuthorization = cfg.get("http.proxyAuthorization"); + const httpNoProxy = cfg.get("http.noProxy"); const certFile = expandPath( String(cfg.get("coder.tlsCertFile") ?? "").trim(), @@ -56,7 +56,7 @@ export async function createHttpAgent( url, cfg.get("http.proxy"), cfg.get("coder.proxyBypass"), - httpNoProxy, + httpNoProxy?.map((noProxy) => noProxy.trim())?.join(","), ); }, headers, diff --git a/test/unit/api/utils.test.ts b/test/unit/api/utils.test.ts index 1c46d122..1f0f5440 100644 --- a/test/unit/api/utils.test.ts +++ b/test/unit/api/utils.test.ts @@ -201,7 +201,7 @@ describe("createHttpAgent", () => { it("uses http.noProxy as fallback when coder.proxyBypass is not set", async () => { const cfg = new MockConfigurationProvider(); cfg.set("http.proxy", proxy); - cfg.set("http.noProxy", "internal.example.com"); + cfg.set("http.noProxy", ["internal.example.com"]); const agent = await createHttpAgent(cfg); @@ -214,7 +214,7 @@ describe("createHttpAgent", () => { const cfg = new MockConfigurationProvider(); cfg.set("http.proxy", proxy); cfg.set("coder.proxyBypass", "primary.example.com"); - cfg.set("http.noProxy", "fallback.example.com"); + cfg.set("http.noProxy", ["fallback.example.com"]); const agent = await createHttpAgent(cfg); @@ -225,5 +225,23 @@ describe("createHttpAgent", () => { await agent.getProxyForUrl("https://fallback.example.com", mockRequest), ).toBe(proxy); }); + + it("trims and joins multiple http.noProxy entries", async () => { + const cfg = new MockConfigurationProvider(); + cfg.set("http.proxy", proxy); + cfg.set("http.noProxy", [" first.example.com ", "second.example.com "]); + + const agent = await createHttpAgent(cfg); + + expect( + await agent.getProxyForUrl("https://first.example.com", mockRequest), + ).toBe(""); + expect( + await agent.getProxyForUrl("https://second.example.com", mockRequest), + ).toBe(""); + expect( + await agent.getProxyForUrl("https://other.example.com", mockRequest), + ).toBe(proxy); + }); }); }); From 6563632f0643901114a26b7826306aa40dee32eb Mon Sep 17 00:00:00 2001 From: Ehab Younes Date: Tue, 27 Jan 2026 17:12:29 +0300 Subject: [PATCH 2/2] Add one more test case --- test/unit/api/utils.test.ts | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/test/unit/api/utils.test.ts b/test/unit/api/utils.test.ts index 1f0f5440..f2c8f47d 100644 --- a/test/unit/api/utils.test.ts +++ b/test/unit/api/utils.test.ts @@ -243,5 +243,24 @@ describe("createHttpAgent", () => { await agent.getProxyForUrl("https://other.example.com", mockRequest), ).toBe(proxy); }); + + interface NoProxyTestCase { + name: string; + noProxy: string[] | undefined; + } + it.each([ + { name: "undefined", noProxy: undefined }, + { name: "empty array", noProxy: [] }, + ])("uses proxy when http.noProxy is $name", async ({ noProxy }) => { + const cfg = new MockConfigurationProvider(); + cfg.set("http.proxy", proxy); + cfg.set("http.noProxy", noProxy); + + const agent = await createHttpAgent(cfg); + + expect( + await agent.getProxyForUrl("https://example.com", mockRequest), + ).toBe(proxy); + }); }); });