forked from TuanKiri/socks5
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rules_test.go
51 lines (46 loc) · 897 Bytes
/
rules_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
package socks5
import (
"net"
"testing"
"github.com/stretchr/testify/assert"
)
func TestIPRules(t *testing.T) {
cases := map[string]struct {
allowIPs []net.IP
address net.Addr
allow bool
}{
"allow_connection": {
allowIPs: []net.IP{
net.ParseIP("192.168.0.100"),
},
address: &net.TCPAddr{
IP: net.ParseIP("192.168.0.100"),
},
allow: true,
},
"not_allow_connection": {
allowIPs: []net.IP{},
address: &net.TCPAddr{
IP: net.ParseIP("192.168.0.101"),
},
allow: false,
},
"incorrect_address_type": {
allowIPs: []net.IP{},
address: &net.UDPAddr{},
allow: false,
},
"without_slice_allow_IPs": {
allow: true,
},
}
for name, tc := range cases {
t.Run(name, func(t *testing.T) {
rules := &serverRules{
allowIPs: tc.allowIPs,
}
assert.Equal(t, rules.IsAllowConnection(tc.address), tc.allow)
})
}
}