1#!/bin/bash
2#
3# Copyright (C) 2013 Nikos Mavrogiannopoulos
4#
5# This file is part of ocserv.
6#
7# ocserv is free software; you can redistribute it and/or modify it
8# under the terms of the GNU General Public License as published by the
9# Free Software Foundation; either version 2 of the License, or (at
10# your option) any later version.
11#
12# ocserv is distributed in the hope that it will be useful, but
13# WITHOUT ANY WARRANTY; without even the implied warranty of
14# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15# General Public License for more details.
16#
17# You should have received a copy of the GNU General Public License
18# along with GnuTLS; if not, write to the Free Software Foundation,
19# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20
21SERV="${SERV:-../src/ocserv}"
22srcdir=${srcdir:-.}
23
24. `dirname $0`/common.sh
25
26eval "${GETPORT}"
27
28echo "Testing ocserv and user route application... "
29
30rm -f ${srcdir}/test-iroute.tmp
31
32update_config test-iroute.config
33launch_server -d 1 -f -c "${CONFIG}" & PID=$!
34wait_server $PID
35
36echo -n "Connecting to obtain cookie (with certificate)... "
37( $OPENCONNECT -q localhost:$PORT --sslkey ${srcdir}/certs/user-key.pem -c ${srcdir}/certs/user-cert.pem --servercert=d66b507ae074d03b02eafca40d35f87dd81049d3 --cookieonly </dev/null ) ||
38	fail $PID "Could not connect with certificate!"
39
40echo ok
41
42echo -n "Re-connecting to force script run... "
43$OPENCONNECT -q localhost:$PORT --sslkey ${srcdir}/certs/user-key.pem -c ${srcdir}/certs/user-cert.pem --servercert=d66b507ae074d03b02eafca40d35f87dd81049d3 -s /bin/true </dev/null &
44kpid=$!
45echo ok
46
47sleep 2
48kill $kpid
49
50sleep 1
51echo -n "Checking if routes have been applied... "
52
53if [ ! -f ${srcdir}/test-iroute.tmp ];then
54	fail $PID "Temporary file cannot be found"
55fi
56
57CONTENTS=`cat ${srcdir}/test-iroute.tmp`
58if [[ "$CONTENTS" =~ "192.168.1.0/255.255.255.0 192.168.1.0/24 [vpns|tun]$" ]];then
59	cat ${srcdir}/test-iroute.tmp
60	fail $PID "Temporary file contents are not correct"
61fi
62
63echo ok
64
65rm -f ${srcdir}/test-iroute.tmp ${CONFIG}
66
67kill $PID
68wait
69
70exit 0
71