Skip to content

Commit

Permalink
SNOW-1825719-Proxy port is lost using default proxy port on Windows (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
sfc-gh-pmotacki authored Dec 13, 2024
1 parent b66f1b7 commit 4f7708d
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 7 deletions.
11 changes: 10 additions & 1 deletion lib/proxy_util.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,14 @@ exports.validateEmptyString = function (value) {
};

exports.getProxyFromEnv = function (isHttps = true) {
const getDefaultPortIfNotSet = (proxyFromEnv) => {
const isProxyProtocolHttps = proxyFromEnv.protocol === 'https:';
if (!proxyFromEnv.port) {
return isProxyProtocolHttps ? 443 : 80;
} else {
return proxyFromEnv.port;
}
};
const protocol = isHttps ? 'https' : 'http';
let proxyFromEnv = Util.getEnvVar(`${protocol}_proxy`);
if (!proxyFromEnv){
Expand All @@ -141,9 +149,10 @@ exports.getProxyFromEnv = function (isHttps = true) {
proxyFromEnv = 'http' + '://' + proxyFromEnv;
}
proxyFromEnv = new URL(proxyFromEnv);
const port = getDefaultPortIfNotSet(proxyFromEnv);
const proxy = {
host: Util.validateEmptyString(proxyFromEnv.hostname),
port: Number(Util.validateEmptyString(proxyFromEnv.port)),
port: Number(port),
user: Util.validateEmptyString(proxyFromEnv.username),
password: Util.validateEmptyString(proxyFromEnv.password),
protocol: Util.validateEmptyString(proxyFromEnv.protocol),
Expand Down
48 changes: 42 additions & 6 deletions test/unit/proxy_util_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ describe('getProxyEnv function test ', function () {
{
name: 'HTTP PROXY with authentication',
isHttps: false,
httpProxy: 'http://hello:[email protected]:8080',
httpProxy: 'http://hello:[email protected]:8080', //# pragma: allowlist secret
httpsProxy: undefined,
noProxy: '*.amazonaws.com,*.my_company.com',
result: {
Expand All @@ -165,7 +165,7 @@ describe('getProxyEnv function test ', function () {
{
name: 'HTTPS PROXY with authentication without NO proxy',
isHttps: true,
httpsProxy: 'https://user:[email protected]:1234',
httpsProxy: 'https://user:[email protected]:1234', //# pragma: allowlist secret
result: {
host: 'myproxy.server.com',
user: 'user',
Expand All @@ -187,6 +187,42 @@ describe('getProxyEnv function test ', 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 }) => {
Expand Down Expand Up @@ -265,11 +301,11 @@ describe('Proxy Util for Azure', function () {
it('test hide and restore environment proxy', function () {
const testCases =
{
httpProxy: 'https://user:[email protected]:1234',
httpsProxy: 'https://user:[email protected]:1234',
httpProxy: 'https://user:[email protected]:1234', //# pragma: allowlist secret
httpsProxy: 'https://user:[email protected]:1234', //# pragma: allowlist secret
noProxy: '*.amazonaws.com,*.my_company.com',
HttpProxy: 'https://user:[email protected]:1234',
HttpsProxy: 'https://user:[email protected]:1234',
HttpProxy: 'https://user:[email protected]:1234', //# pragma: allowlist secret
HttpsProxy: 'https://user:[email protected]:1234', //# pragma: allowlist secret
NoProxy: '*.amazonaws2.com,*.my_company2.com',
};

Expand Down

0 comments on commit 4f7708d

Please sign in to comment.