-
Notifications
You must be signed in to change notification settings - Fork 2
/
proxy_test.go
95 lines (68 loc) · 2.54 KB
/
proxy_test.go
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
package simpleresty
import (
"github.com/stretchr/testify/assert"
"os"
"testing"
)
func TestParseProxyForServer_Creds(t *testing.T) {
testURL := "http://BOB.BUILDER:[email protected]:8080"
expected := "company.com"
assert.Equal(t, expected, parseProxyURLForDomain(testURL))
}
func TestParseProxyForServer_NoCreds(t *testing.T) {
testURL := "http://company.com:8080"
expected := "company.com"
assert.Equal(t, expected, parseProxyURLForDomain(testURL))
}
func TestParseProxyForServer_NoCredsHTTPS(t *testing.T) {
testURL := "https://company.com:8080"
expected := "company.com"
assert.Equal(t, expected, parseProxyURLForDomain(testURL))
}
func TestGetNoProxyDomains_NoneSet(t *testing.T) {
domains, isPresent := getNoProxyDomains()
assert.Equal(t, 0, len(domains))
assert.Equal(t, false, isPresent)
}
func TestGetNoProxyDomains_SingleSet_NO_PROXY(t *testing.T) {
_ = os.Setenv("NO_PROXY", "somedomain.com")
defer os.Unsetenv("NO_PROXY")
domains, isPresent := getNoProxyDomains()
assert.Equal(t, []string{"somedomain.com"}, domains)
assert.Equal(t, true, isPresent)
}
func TestGetNoProxyDomains_SingleSet_no_proxy(t *testing.T) {
_ = os.Setenv("no_proxy", "somedomain.com")
defer os.Unsetenv("no_proxy")
domains, isPresent := getNoProxyDomains()
assert.Equal(t, []string{"somedomain.com"}, domains)
assert.Equal(t, true, isPresent)
}
func TestGetNoProxyDomains_MultipleSet(t *testing.T) {
_ = os.Setenv("NO_PROXY", "somedomain.com, somedomain2.com")
defer os.Unsetenv("NO_PROXY")
domains, isPresent := getNoProxyDomains()
assert.Equal(t, []string{"somedomain.com", "somedomain2.com"}, domains)
assert.Equal(t, true, isPresent)
}
func TestGetNoProxyDomains_WildcardMultipleSet(t *testing.T) {
_ = os.Setenv("NO_PROXY", "*.somedomain.com, somedomain2.com")
defer os.Unsetenv("NO_PROXY")
domains, isPresent := getNoProxyDomains()
assert.Equal(t, []string{"somedomain.com", "somedomain2.com"}, domains)
assert.Equal(t, true, isPresent)
}
func TestGetNoProxyDomains_WildcardMultipleSet2(t *testing.T) {
_ = os.Setenv("NO_PROXY", "*.somedomain.*, somedomain2.com")
defer os.Unsetenv("NO_PROXY")
domains, isPresent := getNoProxyDomains()
assert.Equal(t, []string{"somedomain2.com"}, domains)
assert.Equal(t, true, isPresent)
}
func TestGetNoProxyDomains_MultipleSetWithOneInvalid(t *testing.T) {
_ = os.Setenv("NO_PROXY", "somedomain, test.somedomain2.com")
defer os.Unsetenv("NO_PROXY")
domains, isPresent := getNoProxyDomains()
assert.Equal(t, []string{"test.somedomain2.com"}, domains)
assert.Equal(t, true, isPresent)
}