-
Notifications
You must be signed in to change notification settings - Fork 0
/
generate_vpn_test.go
87 lines (80 loc) · 1.41 KB
/
generate_vpn_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 ezovpn
import (
"strings"
"testing"
"github.com/stretchr/testify/require"
)
const (
vpnRendered = `client
dev tun
proto udp
remote vpn.server.here 1144
nobind
persist-key
persist-tun
comp-lzo
<ca>
CERT FILE
DATA
</ca>
<cert>
CRT FILE
DATA
</cert>
<key>
KEYS
XXXX
</key>
key-direction 1
<tls-auth>
TLS AUTH
DATA
KEY
</tls-auth>`
vpnRenderedPK12 = `client
dev tun
proto udp
remote vpn.server.here 1144
nobind
persist-key
persist-tun
comp-lzo
<pkcs12>
/deSj5Uh3JfIX2bhP0f+TNTIw1OZJgwK4aXTjOmuIjcz9YVmiRR1ZwWI59VWaGKxci/4er8ZN3YS
OIce8ddQqQ8Ub/CPeBCXrt04DhjTzB3x+4MZ+ZBGHHevySGWe9oHKcavfBZM1+kpg+qz8BbZDbYY
SRs=
</pkcs12>
key-direction 1
<tls-auth>
TLS AUTH
DATA
KEY
</tls-auth>`
)
func TestVPNGeneration(t *testing.T) {
var buf strings.Builder
require.Nil(t, GenerateVPNConfig("testdir", &FileSpec{
CAFile: "ca.crt",
CertFile: "ovpn.crt",
KeyFile: "ovpn.key",
TAFile: "tlsauth.key",
}, &VpnSpec{
Server: "vpn.server.here",
Port: 1144,
}, &buf, DefaultCertFetcher))
require.Equal(t, vpnRendered, buf.String())
}
func TestVPNGenerationPKCS12(t *testing.T) {
var buf strings.Builder
require.Nil(t, GenerateVPNConfig("testdir", &FileSpec{
CAFile: "ca.crt",
CertFile: "ovpn.crt",
KeyFile: "ovpn.key",
TAFile: "tlsauth.key",
PKCS12: "pkcs12.p12",
}, &VpnSpec{
Server: "vpn.server.here",
Port: 1144,
}, &buf, DefaultCertFetcher))
require.Equal(t, vpnRenderedPK12, buf.String())
}