|
| 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 * as assert from 'assert'; |
| 7 | +import { parse as parseUrl, Url } from 'url'; |
| 8 | +import { shouldProxyUrl, urlMatchDenyList } from 'vs/platform/request/node/proxy'; |
| 9 | +import { ensureNoDisposablesAreLeakedInTestSuite } from 'vs/base/test/common/utils'; |
| 10 | + |
| 11 | + |
| 12 | +suite("proxy support", () => { |
| 13 | + const urlWithDomain = parseUrl("https://example.com/some/path"); |
| 14 | + const urlWithSubdomain = parseUrl("https://internal.example.com/some/path"); |
| 15 | + const urlWithIPv4 = parseUrl("https://127.0.0.1/some/path"); |
| 16 | + const urlWithIPv6 = parseUrl("https://[::1]/some/path"); |
| 17 | + |
| 18 | + test("returns true if no denylists are provided", () => { |
| 19 | + assert.strictEqual(shouldProxyUrl(urlWithDomain, [], {}), true); |
| 20 | + }); |
| 21 | + |
| 22 | + test("gives precedence to direct config value rather than environment", () => { |
| 23 | + assert.strictEqual(shouldProxyUrl(urlWithDomain, ["otherexample.com"], { no_proxy: "example.com" }), true); |
| 24 | + assert.strictEqual(shouldProxyUrl(urlWithDomain, ["example.com"], { no_proxy: "otherexample.com" }), false); |
| 25 | + }); |
| 26 | + |
| 27 | + test("match wildcard", () => { |
| 28 | + assert.strictEqual(urlMatchDenyList(urlWithDomain, ['*']), true); |
| 29 | + assert.strictEqual(urlMatchDenyList(urlWithSubdomain, ['*']), true); |
| 30 | + assert.strictEqual(urlMatchDenyList(urlWithIPv4, ['*']), true); |
| 31 | + assert.strictEqual(urlMatchDenyList(urlWithIPv6, ['*']), true); |
| 32 | + }); |
| 33 | + |
| 34 | + test("match direct hostname", () => { |
| 35 | + assert.strictEqual(urlMatchDenyList(urlWithDomain, ['example.com']), true); |
| 36 | + assert.strictEqual(urlMatchDenyList(urlWithDomain, ['otherexample.com']), false); |
| 37 | + // Technically the following are a suffix match but it's a known behavior in the ecosystem |
| 38 | + assert.strictEqual(urlMatchDenyList(urlWithDomain, ['.example.com']), true); |
| 39 | + assert.strictEqual(urlMatchDenyList(urlWithDomain, ['.otherexample.com']), false); |
| 40 | + }); |
| 41 | + |
| 42 | + test("match hostname suffixes", () => { |
| 43 | + assert.strictEqual(urlMatchDenyList(urlWithSubdomain, ['example.com']), true); |
| 44 | + assert.strictEqual(urlMatchDenyList(urlWithSubdomain, ['.example.com']), true); |
| 45 | + assert.strictEqual(urlMatchDenyList(urlWithSubdomain, ['otherexample.com']), false); |
| 46 | + assert.strictEqual(urlMatchDenyList(urlWithSubdomain, ['.otherexample.com']), false); |
| 47 | + }); |
| 48 | + |
| 49 | + test("match IP addresses", () => { |
| 50 | + assert.strictEqual(urlMatchDenyList(urlWithIPv4, ['example.com']), false); |
| 51 | + assert.strictEqual(urlMatchDenyList(urlWithIPv6, ['example.com']), false); |
| 52 | + assert.strictEqual(urlMatchDenyList(urlWithIPv4, ['127.0.0.1']), true); |
| 53 | + assert.strictEqual(urlMatchDenyList(urlWithIPv6, ['::1']), true); |
| 54 | + }); |
| 55 | + |
| 56 | + test("match IP addresses with range deny list", () => { |
| 57 | + assert.strictEqual(urlMatchDenyList(urlWithIPv4, ['127.0.0.0/8']), true); |
| 58 | + assert.strictEqual(urlMatchDenyList(urlWithIPv4, ['10.0.0.0/8']), false); |
| 59 | + assert.strictEqual(urlMatchDenyList(urlWithIPv6, ['::0/64']), true); |
| 60 | + assert.strictEqual(urlMatchDenyList(urlWithIPv6, ['100::0/64']), false); |
| 61 | + }); |
| 62 | + |
| 63 | + ensureNoDisposablesAreLeakedInTestSuite(); |
| 64 | +}); |
0 commit comments