Repository navigation
Expand file tree
/
Copy pathproxies_spec.lua
More file actions
56 lines (55 loc) · 2.21 KB
/
Copy pathproxies_spec.lua
File metadata and controls
56 lines (55 loc) · 2.21 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
describe("http.proxies module", function()
local http_proxies = require "http.proxies"
it("works", function()
local proxies = http_proxies.new():update(function(k) return ({
http_proxy = "http://http.proxy";
https_proxy = "http://https.proxy";
all_proxy = "http://all.proxy";
no_proxy = nil;
})[k] end)
assert.same({
http_proxy = "http://http.proxy";
https_proxy = "http://https.proxy";
all_proxy = "http://all.proxy";
no_proxy = nil;
}, proxies)
assert.same("http://http.proxy", proxies:choose("http", "myhost"))
assert.same("http://https.proxy", proxies:choose("https", "myhost"))
assert.same("http://all.proxy", proxies:choose("other", "myhost"))
end)
it("isn't vulnerable to httpoxy", function()
assert.same({}, http_proxies.new():update(function(k) return ({
GATEWAY_INTERFACE = "CGI/1.1";
http_proxy = "vulnerable to httpoxy";
})[k] end))
end)
it("works with no_proxy set to *", function()
local proxies = http_proxies.new():update(function(k) return ({
http_proxy = "http://http.proxy";
https_proxy = "http://https.proxy";
all_proxy = "http://all.proxy";
no_proxy = "*";
})[k] end)
-- Should return nil due to no_proxy being *
assert.same(nil, proxies:choose("http", "myhost"))
assert.same(nil, proxies:choose("https", "myhost"))
assert.same(nil, proxies:choose("other", "myhost"))
end)
it("works with a no_proxy set", function()
local proxies = http_proxies.new():update(function(k) return ({
http_proxy = "http://http.proxy";
no_proxy = "foo,bar.com,.extra.dot.com";
})[k] end)
assert.same("http://http.proxy", proxies:choose("http", "myhost"))
assert.is.table(proxies.no_proxy)
assert.same(nil, proxies:choose("http", "foo"))
assert.same(nil, proxies:choose("http", "bar.com"))
assert.same(nil, proxies:choose("http", "subdomain.bar.com"))
assert.same(nil, proxies:choose("http", "sub.sub.subdomain.bar.com"))
assert.same(nil, proxies:choose("http", "someting.foo"))
assert.same("http://http.proxy", proxies:choose("http", "else.com"))
assert.same(nil, proxies:choose("http", "more.extra.dot.com"))
assert.same(nil, proxies:choose("http", "extra.dot.com"))
assert.same("http://http.proxy", proxies:choose("http", "dot.com"))
end)
end)