-
Notifications
You must be signed in to change notification settings - Fork 6
/
parse_test.go
92 lines (90 loc) · 1.75 KB
/
parse_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
package prox5
import "testing"
func Test_filter(t *testing.T) {
type args struct {
in string
}
type test struct {
name string
args args
wantFiltered string
wantOk bool
}
var tests = []test{
{
name: "simple",
args: args{
in: "127.0.0.1:1080",
},
wantFiltered: "127.0.0.1:1080",
wantOk: true,
},
{
name: "withAuth",
args: args{
in: "127.0.0.1:1080:user:pass",
},
wantFiltered: "user:pass@127.0.0.1:1080",
wantOk: true,
},
{
name: "withAuthAlt",
args: args{
in: "user:pass@127.0.0.1:1080",
},
wantFiltered: "user:pass@127.0.0.1:1080",
wantOk: true,
},
{
name: "simpleDomain",
args: args{
in: "yeet.com:1080",
},
wantFiltered: "yeet.com:1080",
wantOk: true,
},
{
name: "domainWithAuth",
args: args{
in: "yeet.com:1080:user:pass",
},
wantFiltered: "user:pass@yeet.com:1080",
wantOk: true,
},
{
name: "ipv6",
args: args{
in: "[fe80::2ef0:5dff:fe7f:c299]:1080",
},
wantFiltered: "[fe80::2ef0:5dff:fe7f:c299]:1080",
wantOk: true,
},
{
name: "ipv6WithAuth",
args: args{
in: "[fe80::2ef0:5dff:fe7f:c299]:1080:user:pass",
},
wantFiltered: "user:pass@[fe80::2ef0:5dff:fe7f:c299]:1080",
wantOk: true,
},
{
name: "invalid",
args: args{
in: "yeet",
},
wantFiltered: "",
wantOk: false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
gotFiltered, gotOk := filter(tt.args.in)
if gotFiltered != tt.wantFiltered {
t.Errorf("filter() gotFiltered = %v, want %v", gotFiltered, tt.wantFiltered)
}
if gotOk != tt.wantOk {
t.Errorf("filter() gotOk = %v, want %v", gotOk, tt.wantOk)
}
})
}
}