1#!/bin/bash
2#
3# Copyright (C) 2013-2020 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:-.}
23builddir=${builddir:-.}
24VPNNET=172.23.115.0/24
25TMPFILE=ios.$$.tmp
26VERBOSE=1
27
28. `dirname $0`/common.sh
29
30eval "${GETPORT}"
31
32echo "Testing environment under apple ios client"
33
34function finish {
35  echo " * Cleaning up..."
36  rm -f ${builddir}/connect.ios.ok
37  rm -f ${builddir}/disconnect.ios.ok
38  test -n "${PID}" && kill ${PID} >/dev/null 2>&1
39  rm -f ${TMPFILE}
40}
41trap finish EXIT
42
43rm -f ${builddir}/connect.ios.ok
44rm -f ${builddir}/disconnect.ios.ok
45
46OPENCONNECT="$OPENCONNECT --os=apple-ios"
47
48echo " * Testing connection with username-password... "
49
50update_config apple-ios.config
51launch_server -d 1 -f -c "${CONFIG}" & PID=$!
52wait_server $PID
53
54sleep 2
55
56echo " * Connecting to obtain cookie... "
57( echo "!@#$%^&*()<>" | $OPENCONNECT localhost:$PORT -u "sp@c/al" --servercert=d66b507ae074d03b02eafca40d35f87dd81049d3 --cookieonly >/dev/null ) ||
58	fail $PID "Could not receive cookie from server"
59
60echo " * Re-connect to force script run with platform... "
61echo "!@#$%^&*()<>" | timeout 7 $OPENCONNECT --verbose localhost:$PORT -u "sp@c/al" --servercert=d66b507ae074d03b02eafca40d35f87dd81049d3 -s /bin/true >${TMPFILE} 2>&1
62
63sleep 5
64
65if ! test -f ${builddir}/connect.ios.ok;then
66	cat ${TMPFILE}
67	echo "Connect script was not run (1)"
68	exit 1
69fi
70
71if ! test -f ${builddir}/disconnect.ios.ok;then
72	cat ${TMPFILE}
73	echo "Disconnect script was not run properly (1)"
74	exit 1
75fi
76
77rm -f ${builddir}/connect.ios.ok
78rm -f ${builddir}/disconnect.ios.ok
79
80grep 'X-CSTP-Split-Include-IP6: 2000::/3' ${TMPFILE} >/dev/null
81if test $? != 0;then
82	cat ${TMPFILE}
83	echo "Did not find the expected route"
84	exit 1
85fi
86
87rm -f ${TMPFILE}
88
89echo " * Re-connecting to force script run with user agent... "
90echo "!@#$%^&*()<>" | timeout 7 $OPENCONNECT --verbose --useragent="Cisco AnyConnect VPN Agent for Apple" localhost:$PORT -u "sp@c/al" --servercert=d66b507ae074d03b02eafca40d35f87dd81049d3 -s /bin/true >${TMPFILE} 2>&1
91
92sleep 5
93
94if ! test -f ${builddir}/connect.ios.ok;then
95	echo "Connect script was not run (2)"
96	exit 1
97fi
98
99if ! test -f ${builddir}/disconnect.ios.ok;then
100	echo "Disconnect script was not run properly (2)"
101	exit 1
102fi
103
104rm -f ${builddir}/connect.ios.ok
105rm -f ${builddir}/disconnect.ios.ok
106
107grep 'X-CSTP-Split-Include-IP6: 2000::/3' ${TMPFILE} >/dev/null
108if test $? != 0;then
109	cat ${TMPFILE}
110	echo "Did not find the expected route"
111	exit 1
112fi
113
114sleep 5
115echo " - Check server status"
116
117( echo "!@#$%^&*()<>" | $OPENCONNECT localhost:$PORT -u "sp@c/al" --servercert=d66b507ae074d03b02eafca40d35f87dd81049d3 --cookieonly >/dev/null 2>&1 ) ||
118	fail $PID "Could not receive cookie from server"
119
120echo " - Killing server"
121kill $PID
122PID=""
123wait
124
125echo "Script tests were successful"
126
127exit 0
128