summaryrefslogtreecommitdiff
path: root/debian/tests/server-setup-with-static-key
diff options
context:
space:
mode:
authorLucas Kanashiro <lucas.kanashiro@canonical.com>2020-05-08 09:19:44 -0300
committerLucas Kanashiro <lucas.kanashiro@canonical.com>2020-05-08 09:19:44 -0300
commit59e1c963d0a557b5250b729f7150ed28e5584ae0 (patch)
tree6e93d84a84aa0f208d649c42d40bdbb89f75a642 /debian/tests/server-setup-with-static-key
parente385682719c2c6215022bcfa9ae0ddc6a593db5d (diff)
Add two DEP-8 test cases for the server side
Two scenarios are tested, server setup using: a static key and a CA.
Diffstat (limited to 'debian/tests/server-setup-with-static-key')
-rwxr-xr-xdebian/tests/server-setup-with-static-key63
1 files changed, 63 insertions, 0 deletions
diff --git a/debian/tests/server-setup-with-static-key b/debian/tests/server-setup-with-static-key
new file mode 100755
index 0000000..9ddaecd
--- /dev/null
+++ b/debian/tests/server-setup-with-static-key
@@ -0,0 +1,63 @@
+#!/bin/bash
+
+# ----------------------------------------------
+# Test an OpenVPN server setup with a static key
+# ----------------------------------------------
+
+set -e
+
+CONFIG_DIR=/etc/openvpn
+STATIC_KEY=static.key
+DEVICE=tun0
+IP_SERVER=10.9.8.1
+IP_CLIENT=10.9.8.2
+LOG_FILE=$AUTOPKGTEST_TMP/openvpn.log
+
+# Print information message to stdout
+info() {
+ echo "[I] $1"
+}
+
+info "Generate the static key inside the config directory"
+cd $CONFIG_DIR
+openvpn --genkey --secret $STATIC_KEY
+
+info "Create the config file"
+cat << EOF > $CONFIG_DIR/$DEVICE.conf
+dev $DEVICE
+ifconfig $IP_SERVER $IP_CLIENT
+secret $CONFIG_DIR/$STATIC_KEY
+EOF
+
+info "Start an OpenVPN process in background and redirect its output to a file"
+openvpn --config $CONFIG_DIR/$DEVICE.conf --verb 6 > $LOG_FILE &
+
+info "Give some time to start the process, check if the TUN device is opened"
+count=1
+until [ -f $LOG_FILE ] && cat $LOG_FILE | grep "TUN/TAP device $DEVICE opened"; do
+ [ $count -gt 9 ] && exit 5
+ count=$(expr $count + 1)
+ sleep 1
+done
+
+info "Check if the $DEVICE was created and if the state is UNKNOWN at this point"
+ip address show $DEVICE | grep 'state UNKNOWN'
+
+info "Check if OpenVPN is listening on port 1194 (default port)"
+ss -lnptu | grep -E '([0-9]{1,3}\.){3}[0-9]{1,3}:1194.*users:\(\(\"openvpn\"'
+
+info "Check if the $STATIC_KEY is used by OpenVPN"
+cat $LOG_FILE | grep "shared_secret_file = '$CONFIG_DIR/$STATIC_KEY'"
+
+info "Check if the $DEVICE is linked"
+cat $LOG_FILE | grep "/sbin/ip link set dev $DEVICE up"
+
+info "Check if the specified IP addresses were configured"
+cat $LOG_FILE | grep "/sbin/ip addr add dev tun0 local $IP_SERVER peer $IP_CLIENT"
+
+# Clean up: kill tha OpenVPN process, remove the $DEVICE created and $STATIC_KEY
+cleanup() {
+ pkill openvpn
+ rm $CONFIG_DIR/$STATIC_KEY
+}
+trap cleanup INT TERM EXIT