-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathmain_test.go
More file actions
71 lines (65 loc) · 1.78 KB
/
main_test.go
File metadata and controls
71 lines (65 loc) · 1.78 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
68
69
70
71
package main
import (
"testing"
"github.com/stretchr/testify/assert"
)
func Test_isTCPNetworkAddress(t *testing.T) {
t.Run("given valid/allowed host arg then true is returned", func(t *testing.T) {
tcs := []string{
"https://test.com:443",
"http://test.com:80",
"ssh://test.com:22",
"test.com:443",
"test.com:80",
"test.com:22",
"https://test.com",
"http://test.com",
"ssh://test.com",
}
for _, tc := range tcs {
assert.True(t, isTCPNetworkAddress(tc), tc)
}
})
t.Run("given not valid host arg then false is returned", func(t *testing.T) {
tcs := []string{
"ftp://test.com",
"test.com",
"/tmp/certs.pem",
}
for _, tc := range tcs {
assert.False(t, isTCPNetworkAddress(tc), tc)
}
})
}
func Test_toTCPNetworkAddress(t *testing.T) {
t.Run("given valid/allowed host arg then scheme is stripped and port added", func(t *testing.T) {
tcs := map[string]string{
"https://test.com:443": "test.com:443",
"http://test.com:80": "test.com:80",
"ssh://test.com:22": "test.com:22",
// override port map
"https://test.com:5443": "test.com:5443",
"http://test.com:8080": "test.com:8080",
"ssh://test.com:2222": "test.com:2222",
"test.com:443": "test.com:443",
"test.com:80": "test.com:80",
"test.com:22": "test.com:22",
"https://test.com": "test.com:443",
"http://test.com": "test.com:80",
"ssh://test.com": "test.com:22",
}
for in, expected := range tcs {
assert.Equal(t, expected, toTCPNetworkAddress(in))
}
})
t.Run("given not valid host arg then the input is returned", func(t *testing.T) {
tcs := []string{
"ftp://test.com",
"test.com",
"/tmp/certs.pem",
}
for _, tc := range tcs {
assert.Equal(t, tc, toTCPNetworkAddress(tc))
}
})
}