From cce2462cc9fa0478734411410948ea6c6d1a6477 Mon Sep 17 00:00:00 2001 From: Aneesh Relan Date: Thu, 30 Sep 2021 14:38:01 +0530 Subject: [PATCH] fix: handle empty string for PROXY_HOST and PROXY_PORT (#4) --- src/index.ts | 2 +- tests/praxios.test.ts | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/index.ts b/src/index.ts index d88285e..97bc8c4 100644 --- a/src/index.ts +++ b/src/index.ts @@ -4,7 +4,7 @@ import * as tunnel from "tunnel"; const { PROXY_HOST, PROXY_PORT, PROXY_USERNAME, PROXY_PASSWORD } = process.env; const isProxyDefined = (): boolean => { - return PROXY_HOST !== undefined && PROXY_PORT !== undefined; + return !!PROXY_HOST && !!PROXY_PORT; }; const getProxyAuth = (): string | undefined => { diff --git a/tests/praxios.test.ts b/tests/praxios.test.ts index 3fdcf32..8bb5cfd 100644 --- a/tests/praxios.test.ts +++ b/tests/praxios.test.ts @@ -62,4 +62,14 @@ describe("praxios", () => { expect(praxios.defaults.httpsAgent.proxyOptions.localAddress).toBeUndefined(); }); + + test("empty string for proxy host options are assumed as proxy not being set", async () => { + process.env.PROXY_HOST = ""; + process.env.PROXY_PORT = ""; + + const praxios = (await import("../src/index")).default; + + expect(praxios.defaults.httpsAgent).toBeUndefined(); + expect(praxios.defaults.proxy).toBeUndefined(); + }); });