Skip to content

Commit dfadc3e

Browse files
authored
Fix proxy settings types when reading the configurations (#759)
1 parent 1133a0f commit dfadc3e

File tree

2 files changed

+42
-5
lines changed

2 files changed

+42
-5
lines changed

src/api/utils.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ export async function createHttpAgent(
2828
): Promise<ProxyAgent> {
2929
const insecure = cfg.get<boolean>("coder.insecure", false);
3030
const proxyStrictSSL = cfg.get<boolean>("http.proxyStrictSSL", true);
31-
const proxyAuthorization = cfg.get<string>("http.proxyAuthorization");
32-
const httpNoProxy = cfg.get<string>("http.noProxy");
31+
const proxyAuthorization = cfg.get<string | null>("http.proxyAuthorization");
32+
const httpNoProxy = cfg.get<string[]>("http.noProxy");
3333

3434
const certFile = expandPath(
3535
String(cfg.get("coder.tlsCertFile") ?? "").trim(),
@@ -56,7 +56,7 @@ export async function createHttpAgent(
5656
url,
5757
cfg.get("http.proxy"),
5858
cfg.get("coder.proxyBypass"),
59-
httpNoProxy,
59+
httpNoProxy?.map((noProxy) => noProxy.trim())?.join(","),
6060
);
6161
},
6262
headers,

test/unit/api/utils.test.ts

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ describe("createHttpAgent", () => {
201201
it("uses http.noProxy as fallback when coder.proxyBypass is not set", async () => {
202202
const cfg = new MockConfigurationProvider();
203203
cfg.set("http.proxy", proxy);
204-
cfg.set("http.noProxy", "internal.example.com");
204+
cfg.set("http.noProxy", ["internal.example.com"]);
205205

206206
const agent = await createHttpAgent(cfg);
207207

@@ -214,7 +214,7 @@ describe("createHttpAgent", () => {
214214
const cfg = new MockConfigurationProvider();
215215
cfg.set("http.proxy", proxy);
216216
cfg.set("coder.proxyBypass", "primary.example.com");
217-
cfg.set("http.noProxy", "fallback.example.com");
217+
cfg.set("http.noProxy", ["fallback.example.com"]);
218218

219219
const agent = await createHttpAgent(cfg);
220220

@@ -225,5 +225,42 @@ describe("createHttpAgent", () => {
225225
await agent.getProxyForUrl("https://fallback.example.com", mockRequest),
226226
).toBe(proxy);
227227
});
228+
229+
it("trims and joins multiple http.noProxy entries", async () => {
230+
const cfg = new MockConfigurationProvider();
231+
cfg.set("http.proxy", proxy);
232+
cfg.set("http.noProxy", [" first.example.com ", "second.example.com "]);
233+
234+
const agent = await createHttpAgent(cfg);
235+
236+
expect(
237+
await agent.getProxyForUrl("https://first.example.com", mockRequest),
238+
).toBe("");
239+
expect(
240+
await agent.getProxyForUrl("https://second.example.com", mockRequest),
241+
).toBe("");
242+
expect(
243+
await agent.getProxyForUrl("https://other.example.com", mockRequest),
244+
).toBe(proxy);
245+
});
246+
247+
interface NoProxyTestCase {
248+
name: string;
249+
noProxy: string[] | undefined;
250+
}
251+
it.each<NoProxyTestCase>([
252+
{ name: "undefined", noProxy: undefined },
253+
{ name: "empty array", noProxy: [] },
254+
])("uses proxy when http.noProxy is $name", async ({ noProxy }) => {
255+
const cfg = new MockConfigurationProvider();
256+
cfg.set("http.proxy", proxy);
257+
cfg.set("http.noProxy", noProxy);
258+
259+
const agent = await createHttpAgent(cfg);
260+
261+
expect(
262+
await agent.getProxyForUrl("https://example.com", mockRequest),
263+
).toBe(proxy);
264+
});
228265
});
229266
});

0 commit comments

Comments
 (0)