1
1
#! /bin/bash
2
2
3
+ SERV_IP=$( ip -4 -o addr show scope global | awk ' {print $4}' | sed -e ' s:/.*::' | head -n1)
4
+ SERVER_CONF=" /etc/openvpn/openvpn.conf"
5
+ TEST1_OVPN=" /etc/openvpn/test1.ovpn"
6
+
3
7
# Function to fail
4
8
abort () { cat <<< " $@" 1>&2 ; exit 1; }
5
9
10
+ # Check a config (haystack) for a given line (needle) exit with error if not
11
+ # found.
12
+ test_config () {
13
+
14
+ local needle=" ${2} "
15
+ local file=" ${1} "
16
+
17
+ busybox grep -q " ${needle} " " ${file} "
18
+ if [ $? -ne 0 ]; then
19
+ abort " ==> Config match not found: ${needle} "
20
+ fi
21
+ }
22
+
23
+ # Check a config (haystack) for absence of given line (needle) exit with error
24
+ # if found.
25
+ test_not_config () {
26
+
27
+ local needle=" ${2} "
28
+ local file=" ${1} "
29
+
30
+ busybox grep -vq " ${needle} " " ${file} "
31
+ if [ $? -ne 0 ]; then
32
+ abort " ==> Config match found: ${needle} "
33
+ fi
34
+ }
35
+
6
36
7
37
#
8
38
# Generate openvpn.config file
9
39
#
10
- SERV_IP=$( ip -4 -o addr show scope global | awk ' {print $4}' | sed -e ' s:/.*::' | head -n1)
11
40
12
41
ovpn_genconfig \
13
42
-u udp://$SERV_IP \
@@ -18,23 +47,38 @@ EASYRSA_BATCH=1 EASYRSA_REQ_CN="Travis-CI Test CA" ovpn_initpki nopass
18
47
19
48
easyrsa build-client-full test1 nopass 2> /dev/null
20
49
21
- TEST1_OVPN=" /etc/openvpn/test1.ovpn"
22
50
ovpn_getclient test1 > " ${TEST1_OVPN} "
23
51
24
- # Check a config (haystack) for a given line (needle) exit with error if not found.
25
- test-client-config () {
26
52
27
- local needle=" ${1} "
53
+ #
54
+ # Simple test cases
55
+ #
56
+
57
+ # 1. client MTU
58
+ test_config " ${TEST1_OVPN} " " ^tun-mtu\s\+1337"
59
+
60
+
61
+ #
62
+ # Test udp client with tcp fallback
63
+ #
64
+ ovpn_genconfig -u udp://$SERV_IP -E " remote $SERV_IP 443 tcp" -E " remote vpn.example.com 443 tcp"
65
+ # nopass is insecure
66
+ EASYRSA_BATCH=1 EASYRSA_REQ_CN=" Travis-CI Test CA" ovpn_initpki nopass
67
+ easyrsa build-client-full client-fallback nopass
68
+ ovpn_getclient client-fallback > " ${TEST1_OVPN} "
69
+
70
+ test_config " ${TEST1_OVPN} " " ^remote\s\+$SERV_IP \s\+443\s\+tcp"
71
+ test_config " ${TEST1_OVPN} " " ^remote\s\+vpn.example.com\s\+443\s\+tcp"
28
72
29
- busybox grep -q " ${needle} " " ${TEST1_OVPN} "
30
- if [ $? -ne 0 ]; then
31
- abort " ==> Config match not found: ${needle} "
32
- fi
33
- }
34
73
35
74
#
36
- # Test cases
75
+ # Test non-defroute config
37
76
#
77
+ ovpn_genconfig -d -u udp://$SERV_IP -r " 172.33.33.0/24" -r " 172.34.34.0/24"
78
+ # nopass is insecure
79
+ EASYRSA_BATCH=1 EASYRSA_REQ_CN=" Travis-CI Test CA" ovpn_initpki nopass
80
+ easyrsa build-client-full non-defroute nopass
81
+ ovpn_getclient non-defroute > " ${TEST1_OVPN} "
38
82
39
- # Test 1: Check MTU
40
- test-client-config " ^tun-mtu\s+1337 "
83
+ # The '!' inverts the match to test that the string isn't present
84
+ test_not_config " ${TEST1_OVPN} " " ^redirect-gateway\s\+def1 "
0 commit comments