From 7616054cabdb7f14ccbc382828ba4492ffb0514f Mon Sep 17 00:00:00 2001 From: Przemyslaw Motacki Date: Mon, 25 Nov 2024 17:50:06 +0100 Subject: [PATCH 1/6] SNOW-1825719 - setting proxy port if default was skipped during parsing --- lib/util.js | 11 ++++++++++- test/unit/util_test.js | 40 ++++++++++++++++++++++++++++++++++++++-- 2 files changed, 48 insertions(+), 3 deletions(-) diff --git a/lib/util.js b/lib/util.js index dd1a3be07..a837e7040 100644 --- a/lib/util.js +++ b/lib/util.js @@ -862,6 +862,13 @@ exports.validateEmptyString = function (value) { }; exports.getProxyFromEnv = function (isHttps = true) { + const getDeafaultPortIfNotSet = (proxyFromEnv, isHttps) => { + if (!proxyFromEnv.port) { + return isHttps ? 443 : 80; + } else { + return proxyFromEnv.port; + } + }; const protocol = isHttps ? 'https' : 'http'; let proxyFromEnv = this.getEnvVar(`${protocol}_proxy`); if (!proxyFromEnv){ @@ -872,11 +879,13 @@ exports.getProxyFromEnv = function (isHttps = true) { if (proxyFromEnv.indexOf('://') === -1) { Logger.getInstance().info('Util.getProxyEnv: the protocol was missing from the environment proxy. Use the HTTP protocol.'); proxyFromEnv = 'http' + '://' + proxyFromEnv; + isHttps = false; } proxyFromEnv = new URL(proxyFromEnv); + const port = getDeafaultPortIfNotSet(proxyFromEnv, isHttps); const proxy = { host: this.validateEmptyString(proxyFromEnv.hostname), - port: Number(this.validateEmptyString(proxyFromEnv.port)), + port: Number(this.validateEmptyString(port)), user: this.validateEmptyString(proxyFromEnv.username), password: this.validateEmptyString(proxyFromEnv.password), protocol: this.validateEmptyString(proxyFromEnv.protocol), diff --git a/test/unit/util_test.js b/test/unit/util_test.js index feaa48541..e48e8f400 100644 --- a/test/unit/util_test.js +++ b/test/unit/util_test.js @@ -1357,7 +1357,7 @@ describe('Util', function () { { name: 'HTTP PROXY with authentication', isHttps: false, - httpProxy: 'http://hello:world@proxy.example.com:8080', + httpProxy: 'http://hello:world@proxy.example.com:8080', //# pragma: allowlist secret httpsProxy: undefined, noProxy: '*.amazonaws.com,*.my_company.com', result: { @@ -1372,7 +1372,7 @@ describe('Util', function () { { name: 'HTTPS PROXY with authentication without NO proxy', isHttps: true, - httpsProxy: 'https://user:pass@myproxy.server.com:1234', + httpsProxy: 'https://user:pass@myproxy.server.com:1234', //# pragma: allowlist secret result: { host: 'myproxy.server.com', user: 'user', @@ -1394,6 +1394,42 @@ describe('Util', function () { noProxy: '*.amazonaws.com|*.my_company.com|*.test.com', }, }, + { + name: 'HTTPS PROXY with authentication without port and protocol', + isHttps: true, + noProxy: '*.amazonaws.com,*.my_company.com,*.test.com', + httpsProxy: 'myproxy.server.com', + result: { + host: 'myproxy.server.com', + port: 80, + protocol: 'http:', + noProxy: '*.amazonaws.com|*.my_company.com|*.test.com', + }, + }, + { + name: 'HTTP PROXY with authentication without port and protocol', + isHttps: false, + noProxy: '*.amazonaws.com,*.my_company.com,*.test.com', + httpProxy: 'myproxy.server.com', + result: { + host: 'myproxy.server.com', + port: 80, + protocol: 'http:', + noProxy: '*.amazonaws.com|*.my_company.com|*.test.com', + }, + }, + { + name: 'HTTPS PROXY with authentication without port', + isHttps: true, + noProxy: '*.amazonaws.com,*.my_company.com,*.test.com', + httpsProxy: 'https://myproxy.server.com', + result: { + host: 'myproxy.server.com', + port: 443, + protocol: 'https:', + noProxy: '*.amazonaws.com|*.my_company.com|*.test.com', + }, + }, ]; testCases.forEach(({ name, isHttps, httpsProxy, httpProxy, noProxy, result }) => { From 19f53427773c706732c72e77a9d480759cbe922f Mon Sep 17 00:00:00 2001 From: Przemyslaw Motacki Date: Mon, 25 Nov 2024 20:51:14 +0100 Subject: [PATCH 2/6] SNOW-1825719 - setting proxy port if default was skipped during parsing --- lib/util.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/util.js b/lib/util.js index a837e7040..4879b136e 100644 --- a/lib/util.js +++ b/lib/util.js @@ -862,7 +862,7 @@ exports.validateEmptyString = function (value) { }; exports.getProxyFromEnv = function (isHttps = true) { - const getDeafaultPortIfNotSet = (proxyFromEnv, isHttps) => { + const getDefaultPortIfNotSet = (proxyFromEnv, isHttps) => { if (!proxyFromEnv.port) { return isHttps ? 443 : 80; } else { @@ -882,7 +882,7 @@ exports.getProxyFromEnv = function (isHttps = true) { isHttps = false; } proxyFromEnv = new URL(proxyFromEnv); - const port = getDeafaultPortIfNotSet(proxyFromEnv, isHttps); + const port = getDefaultPortIfNotSet(proxyFromEnv, isHttps); const proxy = { host: this.validateEmptyString(proxyFromEnv.hostname), port: Number(this.validateEmptyString(port)), From f42c5416268558e797c551621127298b4d955764 Mon Sep 17 00:00:00 2001 From: Przemyslaw Motacki Date: Tue, 26 Nov 2024 09:42:33 +0100 Subject: [PATCH 3/6] SNOW-1825719 - setting proxy port if default was skipped during parsing --- lib/util.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/util.js b/lib/util.js index 4879b136e..3147ef848 100644 --- a/lib/util.js +++ b/lib/util.js @@ -885,7 +885,7 @@ exports.getProxyFromEnv = function (isHttps = true) { const port = getDefaultPortIfNotSet(proxyFromEnv, isHttps); const proxy = { host: this.validateEmptyString(proxyFromEnv.hostname), - port: Number(this.validateEmptyString(port)), + port: Number(port), user: this.validateEmptyString(proxyFromEnv.username), password: this.validateEmptyString(proxyFromEnv.password), protocol: this.validateEmptyString(proxyFromEnv.protocol), From 7e5d605bd76dec9245475a2e90676e09191e43c8 Mon Sep 17 00:00:00 2001 From: Przemyslaw Motacki Date: Tue, 26 Nov 2024 10:13:33 +0100 Subject: [PATCH 4/6] SNOW-1825719 - setting proxy port if default was skipped during parsing --- lib/util.js | 3 +-- test/unit/util_test.js | 6 +++--- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/lib/util.js b/lib/util.js index 3147ef848..5c25d7698 100644 --- a/lib/util.js +++ b/lib/util.js @@ -878,8 +878,7 @@ exports.getProxyFromEnv = function (isHttps = true) { Logger.getInstance().debug(`Util.getProxyEnv: Using ${protocol.toUpperCase()}_PROXY from the environment variable`); if (proxyFromEnv.indexOf('://') === -1) { Logger.getInstance().info('Util.getProxyEnv: the protocol was missing from the environment proxy. Use the HTTP protocol.'); - proxyFromEnv = 'http' + '://' + proxyFromEnv; - isHttps = false; + proxyFromEnv = protocol + '://' + proxyFromEnv; } proxyFromEnv = new URL(proxyFromEnv); const port = getDefaultPortIfNotSet(proxyFromEnv, isHttps); diff --git a/test/unit/util_test.js b/test/unit/util_test.js index e48e8f400..52795c45c 100644 --- a/test/unit/util_test.js +++ b/test/unit/util_test.js @@ -1390,7 +1390,7 @@ describe('Util', function () { result: { host: 'myproxy.server.com', port: 1234, - protocol: 'http:', + protocol: 'https:', noProxy: '*.amazonaws.com|*.my_company.com|*.test.com', }, }, @@ -1401,8 +1401,8 @@ describe('Util', function () { httpsProxy: 'myproxy.server.com', result: { host: 'myproxy.server.com', - port: 80, - protocol: 'http:', + port: 443, + protocol: 'https:', noProxy: '*.amazonaws.com|*.my_company.com|*.test.com', }, }, From 8f8fc47f1f636e2f165b37228e0db7bb6f993447 Mon Sep 17 00:00:00 2001 From: Przemyslaw Motacki Date: Tue, 26 Nov 2024 13:54:27 +0100 Subject: [PATCH 5/6] Revert "SNOW-1825719 - setting proxy port if default was skipped during parsing" This reverts commit c32d13c27f9eaf4336f73a7e49bdcb60e58b72b3. --- lib/util.js | 3 ++- test/unit/util_test.js | 6 +++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/lib/util.js b/lib/util.js index 5c25d7698..3147ef848 100644 --- a/lib/util.js +++ b/lib/util.js @@ -878,7 +878,8 @@ exports.getProxyFromEnv = function (isHttps = true) { Logger.getInstance().debug(`Util.getProxyEnv: Using ${protocol.toUpperCase()}_PROXY from the environment variable`); if (proxyFromEnv.indexOf('://') === -1) { Logger.getInstance().info('Util.getProxyEnv: the protocol was missing from the environment proxy. Use the HTTP protocol.'); - proxyFromEnv = protocol + '://' + proxyFromEnv; + proxyFromEnv = 'http' + '://' + proxyFromEnv; + isHttps = false; } proxyFromEnv = new URL(proxyFromEnv); const port = getDefaultPortIfNotSet(proxyFromEnv, isHttps); diff --git a/test/unit/util_test.js b/test/unit/util_test.js index 52795c45c..e48e8f400 100644 --- a/test/unit/util_test.js +++ b/test/unit/util_test.js @@ -1390,7 +1390,7 @@ describe('Util', function () { result: { host: 'myproxy.server.com', port: 1234, - protocol: 'https:', + protocol: 'http:', noProxy: '*.amazonaws.com|*.my_company.com|*.test.com', }, }, @@ -1401,8 +1401,8 @@ describe('Util', function () { httpsProxy: 'myproxy.server.com', result: { host: 'myproxy.server.com', - port: 443, - protocol: 'https:', + port: 80, + protocol: 'http:', noProxy: '*.amazonaws.com|*.my_company.com|*.test.com', }, }, From dbad20bae03455860f391a56a278b4e0881920e0 Mon Sep 17 00:00:00 2001 From: Przemyslaw Motacki Date: Tue, 26 Nov 2024 14:45:21 +0100 Subject: [PATCH 6/6] SNOW-1825719 - setting proxy port if default was skipped during parsing --- lib/util.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/util.js b/lib/util.js index 3147ef848..90db5d079 100644 --- a/lib/util.js +++ b/lib/util.js @@ -862,9 +862,10 @@ exports.validateEmptyString = function (value) { }; exports.getProxyFromEnv = function (isHttps = true) { - const getDefaultPortIfNotSet = (proxyFromEnv, isHttps) => { + const getDefaultPortIfNotSet = (proxyFromEnv) => { + const isProxyProtocolHttps = proxyFromEnv.protocol === 'https:'; if (!proxyFromEnv.port) { - return isHttps ? 443 : 80; + return isProxyProtocolHttps ? 443 : 80; } else { return proxyFromEnv.port; } @@ -879,10 +880,9 @@ exports.getProxyFromEnv = function (isHttps = true) { if (proxyFromEnv.indexOf('://') === -1) { Logger.getInstance().info('Util.getProxyEnv: the protocol was missing from the environment proxy. Use the HTTP protocol.'); proxyFromEnv = 'http' + '://' + proxyFromEnv; - isHttps = false; } proxyFromEnv = new URL(proxyFromEnv); - const port = getDefaultPortIfNotSet(proxyFromEnv, isHttps); + const port = getDefaultPortIfNotSet(proxyFromEnv); const proxy = { host: this.validateEmptyString(proxyFromEnv.hostname), port: Number(port),