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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
var helpers = require('./helpers'),
should = require('should'),
sinon = require('sinon'),
utils = require('./../lib/utils');
describe('utils.should_proxy_to()', function() {
var should_proxy_to = utils.should_proxy_to;
var noProxy = ".ic1.mycorp,localhost,127.0.0.1,*.mycorp.org";
var noProxyWithPorts = " ,.mycorp.org:1234,.ic1.mycorp,localhost,127.0.0.1";
var uris = {
hostname: "http://registry.random.opr.mycorp.org",
with_port: "http://registry.random.opr.mycorp.org:9874",
with_another_port: "http://registry.random.opr.mycorp.org:1234",
localhost: "http://localhost",
ip: "http://127.0.0.1"
}
it("returns true if NO_PROXY is undefined", function(done) {
process.env.NO_PROXY = undefined;
should_proxy_to(uris.hostname).should.true()
delete process.env.NO_PROXY;
done();
});
it("returns true if NO_PROXY is empty", function(done) {
process.env.NO_PROXY = "";
should_proxy_to(uris.hostname).should.true()
delete process.env.NO_PROXY;
done();
});
it("returns false if NO_PROXY is a wildcard", function(done) {
process.env.NO_PROXY = "*";
should_proxy_to(uris.hostname).should.false()
delete process.env.NO_PROXY;
done();
});
it("returns true if the host matches and the ports don't (URI doesn't have port specified)", function(done) {
process.env.NO_PROXY = noProxyWithPorts;
should_proxy_to(uris.hostname).should.true()
delete process.env.NO_PROXY;
done();
});
it("returns true if the host matches and the ports don't (both have a port specified but just different values)", function(done) {
process.env.NO_PROXY = noProxyWithPorts;
should_proxy_to(uris.with_port).should.true()
delete process.env.NO_PROXY;
done();
});
it("returns false if the host matches and the ports don't (no_proxy pattern doesn't have a port)", function(done) {
process.env.NO_PROXY = noProxy;
should_proxy_to(uris.with_port).should.false()
delete process.env.NO_PROXY;
done();
});
it("returns false if host matches", function(done) {
process.env.NO_PROXY = noProxy;
should_proxy_to(uris.hostname).should.false()
delete process.env.NO_PROXY;
done();
});
it("returns false if the host and port matches", function(done) {
process.env.NO_PROXY = noProxyWithPorts;
should_proxy_to(uris.with_another_port).should.false()
delete process.env.NO_PROXY;
done();
});
it("returns false if the host matches (localhost)", function(done) {
process.env.NO_PROXY = noProxy;
should_proxy_to(uris.localhost).should.false()
delete process.env.NO_PROXY;
done();
});
it("returns false if the host matches (ip)", function(done) {
process.env.NO_PROXY = noProxy;
should_proxy_to(uris.ip).should.false()
delete process.env.NO_PROXY;
done();
});
it("returns false if the host matches (ip)", function(done) {
process.env.NO_PROXY = noProxy.replace(/,g/, " ");
should_proxy_to(uris.ip).should.false()
delete process.env.NO_PROXY;
done();
});
it("returns false if the host matches (ip)", function(done) {
process.env.NO_PROXY = noProxy.replace(/,g/, " ");
should_proxy_to(uris.ip).should.false()
delete process.env.NO_PROXY;
done();
});
})