From 3bf5c03b4bc489ae33e692b8c8a25380fe7a5f76 Mon Sep 17 00:00:00 2001 From: Nikos Mavrogiannopoulos Date: Sat, 12 Apr 2014 21:01:49 +0200 Subject: [PATCH] Test whether the connect and disconnect scripts have been called. --- tests/Makefile.am | 2 +- tests/connect-script | 19 +++++++++++++++++++ tests/test-pass-script | 22 ++++++++++++++++++++++ tests/test-pass-script.config | 4 ++-- 4 files changed, 44 insertions(+), 3 deletions(-) create mode 100755 tests/connect-script diff --git a/tests/Makefile.am b/tests/Makefile.am index 8d427563..ff6b1d39 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -1,7 +1,7 @@ EXTRA_DIST = ca-key.pem ca.pem common.sh server-cert.pem server-key.pem test1.config \ test1.passwd test-user-cert.config user-cert.pem user-key.pem test3.config test-iroute.config \ user-config/test test-pass-script.config test-multi-cookie.config test-pam.config \ - test-stress.config user-cert-wrong.pem + test-stress.config user-cert-wrong.pem connect-script dist_check_SCRIPTS = test-pass test-pass-cert test-cert test-iroute test-pass-script \ test-multi-cookie test-pam test-stress diff --git a/tests/connect-script b/tests/connect-script new file mode 100755 index 00000000..24a448ef --- /dev/null +++ b/tests/connect-script @@ -0,0 +1,19 @@ +#!/bin/sh + +#echo $USERNAME : $REASON : $DEVICE + +case "$REASON" in + connect) + echo > connect.ok + ;; + disconnect) + if ! test -z "$DEVICE";then + ifconfig $DEVICE + if test "$?" = "0";then + echo > disconnect.ok + fi + fi + ;; +esac + +exit 0 diff --git a/tests/test-pass-script b/tests/test-pass-script index 80d591ec..b1a1c8f1 100755 --- a/tests/test-pass-script +++ b/tests/test-pass-script @@ -20,10 +20,14 @@ SERV="${SERV:-../src/ocserv}" srcdir=${srcdir:-.} +builddir=${builddir:-.} PORT=4448 . `dirname $0`/common.sh +rm -f ${builddir}/connect.ok +rm -f ${builddir}/disconnect.ok + echo "Testing local backend with username-password... " launch_server -d 1 -f -c test-pass-script.config & PID=$! @@ -33,13 +37,31 @@ echo "Connecting to obtain cookie with wrong username... " ( echo "tost" | openconnect -q localhost:$PORT -u tost --servercert=d66b507ae074d03b02eafca40d35f87dd81049d3 --cookieonly >/dev/null 2>&1 ) && fail $PID "Received cookie when we shouldn't" +rm -f ${builddir}/connect.ok +rm -f ${builddir}/disconnect.ok #test special characters echo "Connecting to obtain cookie... " ( echo "!@#$%^&*()<>" | openconnect -q localhost:$PORT -u special --servercert=d66b507ae074d03b02eafca40d35f87dd81049d3 --cookieonly >/dev/null 2>&1 ) || fail $PID "Could not receive cookie from server" + kill $PID wait +sleep 5 + +if ! test -f ${builddir}/connect.ok;then + echo "Connect script was not run" + exit 1 +fi + +if ! test -f ${builddir}/disconnect.ok;then + echo "Disconnect script was not run properly" + exit 1 +fi + +rm -f ${builddir}/connect.ok +rm -f ${builddir}/disconnect.ok + exit 0 diff --git a/tests/test-pass-script.config b/tests/test-pass-script.config index 220eb697..37aa6471 100644 --- a/tests/test-pass-script.config +++ b/tests/test-pass-script.config @@ -115,8 +115,8 @@ cookie-validity = 172800 # DEVICE, IP_REAL (the real IP of the client), IP_LOCAL (the local IP # in the P-t-P connection), IP_REMOTE (the VPN IP of the client). REASON # may be "connect" or "disconnect". -connect-script = /bin/true -disconnect-script = /bin/true +connect-script = ./connect-script +disconnect-script = ./connect-script # UTMP use-utmp = true