forked from pufferffish/wireproxy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
config_test.go
87 lines (75 loc) · 1.78 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
75
76
77
78
79
80
81
82
83
84
85
86
87
package wireproxy
import (
"github.com/go-ini/ini"
"testing"
)
func loadIniConfig(config string) (*ini.File, error) {
iniOpt := ini.LoadOptions{
Insensitive: true,
AllowShadows: true,
AllowNonUniqueSections: true,
}
return ini.LoadSources(iniOpt, []byte(config))
}
func TestWireguardConfWithoutSubnet(t *testing.T) {
const config = `
[Interface]
PrivateKey = LAr1aNSNF9d0MjwUgAVC4020T0N/E5NUtqVv5EnsSz0=
Address = 10.5.0.2
DNS = 1.1.1.1
[Peer]
PublicKey = e8LKAc+f9xEzq9Ar7+MfKRrs+gZ/4yzvpRJLRJ/VJ1w=
AllowedIPs = 0.0.0.0/0, ::/0
Endpoint = 94.140.11.15:51820
PersistentKeepalive = 25`
var cfg DeviceConfig
iniData, err := loadIniConfig(config)
if err != nil {
t.Fatal(err)
}
err = ParseInterface(iniData, &cfg)
if err != nil {
t.Fatal(err)
}
}
func TestWireguardConfWithSubnet(t *testing.T) {
const config = `
[Interface]
PrivateKey = LAr1aNSNF9d0MjwUgAVC4020T0N/E5NUtqVv5EnsSz0=
Address = 10.5.0.2/23
DNS = 1.1.1.1
[Peer]
PublicKey = e8LKAc+f9xEzq9Ar7+MfKRrs+gZ/4yzvpRJLRJ/VJ1w=
AllowedIPs = 0.0.0.0/0, ::/0
Endpoint = 94.140.11.15:51820
PersistentKeepalive = 25`
var cfg DeviceConfig
iniData, err := loadIniConfig(config)
if err != nil {
t.Fatal(err)
}
err = ParseInterface(iniData, &cfg)
if err != nil {
t.Fatal(err)
}
}
func TestWireguardConfWithManyAddress(t *testing.T) {
const config = `
[Interface]
PrivateKey = mBsVDahr1XIu9PPd17UmsDdB6E53nvmS47NbNqQCiFM=
Address = 100.96.0.190,2606:B300:FFFF:fe8a:2ac6:c7e8:b021:6f5f/128
DNS = 198.18.0.1,198.18.0.2
[Peer]
PublicKey = SHnh4C2aDXhp1gjIqceGhJrhOLSeNYcqWLKcYnzj00U=
AllowedIPs = 0.0.0.0/0,::/0
Endpoint = 192.200.144.22:51820`
var cfg DeviceConfig
iniData, err := loadIniConfig(config)
if err != nil {
t.Fatal(err)
}
err = ParseInterface(iniData, &cfg)
if err != nil {
t.Fatal(err)
}
}