Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/src/vs/platform/agentHost/test/node/serverUrls.test.ts
13399 views
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 assert from 'assert';
7
import { ensureNoDisposablesAreLeakedInTestSuite } from '../../../../base/test/common/utils.js';
8
import { formatWebSocketUrl, resolveServerUrls } from '../../node/serverUrls.js';
9
10
suite('serverUrls', () => {
11
ensureNoDisposablesAreLeakedInTestSuite();
12
13
test('uses localhost for default local-only binding', () => {
14
assert.deepStrictEqual(resolveServerUrls(undefined, 8081), {
15
local: ['ws://localhost:8081'],
16
network: [],
17
});
18
});
19
20
test('formats IPv6 websocket URLs with brackets', () => {
21
assert.strictEqual(formatWebSocketUrl('::1', 8081), 'ws://[::1]:8081');
22
assert.deepStrictEqual(resolveServerUrls('::1', 8081), {
23
local: ['ws://[::1]:8081'],
24
network: [],
25
});
26
assert.deepStrictEqual(resolveServerUrls('0000:0000:0000:0000:0000:0000:0000:0001', 8081), {
27
local: ['ws://[0000:0000:0000:0000:0000:0000:0000:0001]:8081'],
28
network: [],
29
});
30
});
31
32
test('treats wildcard binding as localhost plus network urls', () => {
33
assert.deepStrictEqual(resolveServerUrls('0.0.0.0', 8081, {
34
lo0: [
35
{ address: '127.0.0.1', netmask: '255.0.0.0', family: 'IPv4', mac: '00:00:00:00:00:00', internal: true, cidr: '127.0.0.1/8' },
36
],
37
en0: [
38
{ address: '192.168.1.20', netmask: '255.255.255.0', family: 'IPv4', mac: '11:22:33:44:55:66', internal: false, cidr: '192.168.1.20/24' },
39
{ address: 'fe80::1', netmask: 'ffff:ffff:ffff:ffff::', family: 'IPv6', mac: '11:22:33:44:55:66', internal: false, cidr: 'fe80::1/64', scopeid: 0 },
40
],
41
}), {
42
local: ['ws://localhost:8081'],
43
network: ['ws://192.168.1.20:8081'],
44
});
45
46
assert.deepStrictEqual(resolveServerUrls('0000:0000:0000:0000:0000:0000:0000:0000', 8081, {
47
lo0: [
48
{ address: '127.0.0.1', netmask: '255.0.0.0', family: 'IPv4', mac: '00:00:00:00:00:00', internal: true, cidr: '127.0.0.1/8' },
49
],
50
en0: [
51
{ address: '192.168.1.20', netmask: '255.255.255.0', family: 'IPv4', mac: '11:22:33:44:55:66', internal: false, cidr: '192.168.1.20/24' },
52
],
53
}), {
54
local: ['ws://localhost:8081'],
55
network: ['ws://192.168.1.20:8081'],
56
});
57
});
58
59
test('treats explicit non-loopback host as a network url', () => {
60
assert.deepStrictEqual(resolveServerUrls('example.test', 8081), {
61
local: [],
62
network: ['ws://example.test:8081'],
63
});
64
});
65
});
66
67