1#!/bin/bash
2#
3# Copyright (C) 2015 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# Test whether append-routes behaves as expected.
25
26. `dirname $0`/common.sh
27
28eval "${GETPORT}"
29
30echo "Testing ocserv and user append-route application... "
31
32TMPFILE1=${srcdir}/test-append-routes.tmp
33
34rm -f ${TMPFILE1}
35
36update_config test-user-config.config
37echo "append-routes = true" >> ${CONFIG}
38
39launch_server -d 1 -f -c ${CONFIG} & PID=$!
40wait_server $PID
41
42echo "Checking if routes are appended... "
43
44timeout 15s $OPENCONNECT localhost:$PORT -v --sslkey ${srcdir}/certs/user-key.pem -c ${srcdir}/certs/user-cert-testuser.pem --servercert=d66b507ae074d03b02eafca40d35f87dd81049d3 -s /bin/true </dev/null >${TMPFILE1} 2>&1
45
46echo "cat"
47cat ${TMPFILE1}
48
49echo -n "Checking if routes have been sent... "
50
51CONTENTS=`cat ${TMPFILE1}|grep X-CSTP-Split-Include|grep "192.168.5.0/255.255.255.0"`
52if test -z "$CONTENTS";then
53	cat ${TMPFILE1}
54	fail $PID "Temporary file contents are not correct; route was not found"
55fi
56
57echo ok
58
59echo -n "Checking if no-routes have been sent... "
60
61CONTENTS=`cat ${TMPFILE1}|grep X-CSTP-Split-Exclude|grep "192.168.98.0/255.255.255.0"`
62if test -z "$CONTENTS";then
63	cat ${TMPFILE1}
64	fail $PID "Temporary file contents are not correct; no-route was not found"
65fi
66
67echo ok
68
69rm -f ${TMPFILE1}
70rm -f ${CONFIG}
71
72kill $PID
73wait
74
75exit 0
76