forked from cyfdecyf/cow
-
Notifications
You must be signed in to change notification settings - Fork 0
/
config_test.go
74 lines (64 loc) · 1.79 KB
/
config_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
package main
import (
"testing"
)
func TestParseListen(t *testing.T) {
parser := configParser{}
parser.ParseListen("http://127.0.0.1:8888")
hp, ok := listenProxy[0].(*httpProxy)
if !ok {
t.Error("listen http proxy type wrong")
}
if hp.addr != "127.0.0.1:8888" {
t.Error("listen http server address parse error")
}
parser.ParseListen("http://127.0.0.1:8888 1.2.3.4:5678")
hp, ok = listenProxy[1].(*httpProxy)
if hp.addrInPAC != "1.2.3.4:5678" {
t.Error("listen http addrInPAC parse error")
}
}
func TestParseProxy(t *testing.T) {
pool, ok := parentProxy.(*backupParentPool)
if !ok {
t.Fatal("parentPool by default should be backup pool")
}
cnt := -1
var parser configParser
parser.ParseProxy("http://127.0.0.1:8080")
cnt++
hp, ok := pool.parent[cnt].ParentProxy.(*httpParent)
if !ok {
t.Fatal("1st http proxy parsed not as httpParent")
}
if hp.server != "127.0.0.1:8080" {
t.Error("1st http proxy server address wrong, got:", hp.server)
}
parser.ParseProxy("http://user:[email protected]:9090")
cnt++
hp, ok = pool.parent[cnt].ParentProxy.(*httpParent)
if !ok {
t.Fatal("2nd http proxy parsed not as httpParent")
}
if hp.server != "127.0.0.2:9090" {
t.Error("2nd http proxy server address wrong, got:", hp.server)
}
if hp.authHeader == nil {
t.Error("2nd http proxy server user password not parsed")
}
parser.ParseProxy("socks5://127.0.0.1:1080")
cnt++
sp, ok := pool.parent[cnt].ParentProxy.(*socksParent)
if !ok {
t.Fatal("socks proxy parsed not as socksParent")
}
if sp.server != "127.0.0.1:1080" {
t.Error("socks server address wrong, got:", sp.server)
}
parser.ParseProxy("ss://aes-256-cfb:[email protected]:1080")
cnt++
_, ok = pool.parent[cnt].ParentProxy.(*shadowsocksParent)
if !ok {
t.Fatal("shadowsocks proxy parsed not as shadowsocksParent")
}
}