Skip to content

Commit 8a81fb9

Browse files
authored
Do not create a proxy agent if proxy url is empty string. (#8580)
2 parents fd38eee + 36c9478 commit 8a81fb9

File tree

2 files changed

+53
-1
lines changed

2 files changed

+53
-1
lines changed

src/packageManager/proxy.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ function getSystemProxyURL(requestURL: Url): string | undefined {
2121
export function getProxyAgent(requestURL: Url, proxy: string, strictSSL: boolean): Agent | undefined {
2222
const proxyURL = proxy.length > 0 ? proxy : getSystemProxyURL(requestURL);
2323

24-
if (proxyURL === undefined) {
24+
if (proxyURL === undefined || proxyURL.length === 0) {
2525
return undefined;
2626
}
2727

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/*---------------------------------------------------------------------------------------------
2+
* Copyright (c) Microsoft Corporation. All rights reserved.
3+
* Licensed under the MIT License. See License.txt in the project root for license information.
4+
*--------------------------------------------------------------------------------------------*/
5+
6+
import { describe, test, expect, beforeAll, afterAll, beforeEach } from '@jest/globals';
7+
import { getProxyAgent } from '../../../../src/packageManager/proxy';
8+
import url from 'url';
9+
10+
describe(`${getProxyAgent.name}`, () => {
11+
let originalHttpProxy: string | undefined;
12+
let originalHttpsProxy: string | undefined;
13+
14+
const requestUrl = url.parse('https://github.com');
15+
16+
beforeAll(() => {
17+
originalHttpProxy = process.env.HTTP_PROXY;
18+
originalHttpsProxy = process.env.HTTPS_PROXY;
19+
});
20+
21+
afterAll(() => {
22+
if (originalHttpProxy !== undefined) {
23+
process.env.HTTP_PROXY = originalHttpProxy;
24+
} else {
25+
delete process.env.HTTP_PROXY;
26+
}
27+
28+
if (originalHttpsProxy !== undefined) {
29+
process.env.HTTPS_PROXY = originalHttpsProxy;
30+
} else {
31+
delete process.env.HTTPS_PROXY;
32+
}
33+
});
34+
35+
beforeEach(() => {
36+
delete process.env.HTTP_PROXY;
37+
delete process.env.HTTPS_PROXY;
38+
});
39+
40+
test('Returns `undefined` for empty proxy url and `undefined` HTTP_PROXY env', async () => {
41+
const result = getProxyAgent(requestUrl, /* proxy */ '', /* strictSSL */ false);
42+
expect(result).toBe(undefined);
43+
});
44+
45+
test('Returns `undefined` for empty proxy url and empty HTTP_PROXY env', async () => {
46+
process.env.HTTP_PROXY = '';
47+
process.env.HTTPS_PROXY = '';
48+
49+
const result = getProxyAgent(requestUrl, /* proxy */ '', /* strictSSL */ false);
50+
expect(result).toBe(undefined);
51+
});
52+
});

0 commit comments

Comments
 (0)