Skip to content

Commit 2a9059a

Browse files
committed
tests: Clean-up client + conf_options
Clean-up the mess that was here. It's less error prone, shorter and easier to read.
1 parent 074a07e commit 2a9059a

File tree

2 files changed

+116
-211
lines changed

2 files changed

+116
-211
lines changed

test/tests/client/container.sh

Lines changed: 57 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,42 @@
11
#!/bin/bash
22

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+
37
# Function to fail
48
abort() { cat <<< "$@" 1>&2; exit 1; }
59

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+
636

737
#
838
# Generate openvpn.config file
939
#
10-
SERV_IP=$(ip -4 -o addr show scope global | awk '{print $4}' | sed -e 's:/.*::' | head -n1)
1140

1241
ovpn_genconfig \
1342
-u udp://$SERV_IP \
@@ -18,23 +47,38 @@ EASYRSA_BATCH=1 EASYRSA_REQ_CN="Travis-CI Test CA" ovpn_initpki nopass
1847

1948
easyrsa build-client-full test1 nopass 2>/dev/null
2049

21-
TEST1_OVPN="/etc/openvpn/test1.ovpn"
2250
ovpn_getclient test1 > "${TEST1_OVPN}"
2351

24-
# Check a config (haystack) for a given line (needle) exit with error if not found.
25-
test-client-config() {
2652

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"
2872

29-
busybox grep -q "${needle}" "${TEST1_OVPN}"
30-
if [ $? -ne 0 ]; then
31-
abort "==> Config match not found: ${needle}"
32-
fi
33-
}
3473

3574
#
36-
# Test cases
75+
# Test non-defroute config
3776
#
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}"
3882

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

Comments
 (0)