-
Notifications
You must be signed in to change notification settings - Fork 254
Expand file tree
/
Copy pathproxy.test.ts
More file actions
67 lines (58 loc) · 2.26 KB
/
proxy.test.ts
File metadata and controls
67 lines (58 loc) · 2.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import * as vscode from 'vscode';
import { requestShouldBeProxied } from '../src/json-schema-content-provider';
import assert = require('assert');
class Getable {
constructor(obj: { [key: string]: unknown }) {
Object.assign(this, obj);
}
get<T>(key: string): T {
return this[key];
}
}
function workspaceConfiguration(obj: { [key: string]: unknown }): vscode.WorkspaceConfiguration {
return (new Getable(obj) as unknown) as vscode.WorkspaceConfiguration;
}
describe('#requestShouldBeProxied', () => {
describe('when http.proxy is empty', () => {
it('should return false', () => {
assert.equal(
requestShouldBeProxied(
'https://google.com',
workspaceConfiguration({
proxy: '',
})
),
false
);
});
});
describe(`when http.proxy is set`, () => {
describe('when http.noProxy is empty', () => {
const httpSettings = workspaceConfiguration({
proxy: 'https://localhost:8080',
noProxy: [],
});
it('should return true', () => {
assert.equal(requestShouldBeProxied('https://google.com', httpSettings), true);
assert.equal(requestShouldBeProxied('http://something.example.com', httpSettings), true);
assert.equal(requestShouldBeProxied('http://localhost/path', httpSettings), true);
assert.equal(requestShouldBeProxied('http://127.0.0.1/path', httpSettings), true);
});
});
describe('when http.noProxy has items', () => {
const httpSettings = workspaceConfiguration({
proxy: 'https://localhost:8080',
noProxy: ['*.example.com', 'localhost', '127.0.0.1'],
});
it('should return true when uri does not match noProxy', () => {
assert.equal(requestShouldBeProxied('http://google.com', httpSettings), true);
assert.equal(requestShouldBeProxied('http://example.com', httpSettings), true);
});
it('should return false when uri matches noProxy', () => {
assert.equal(requestShouldBeProxied('http://something.example.com/path', httpSettings), false);
assert.equal(requestShouldBeProxied('http://localhost/path', httpSettings), false);
assert.equal(requestShouldBeProxied('http://127.0.0.1/path', httpSettings), false);
});
});
});
});