1#!/bin/sh
2#
3# Copyright (C) 2015 Red Hat
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 whether cookies will remain valid during the session time... "
29rm -f ${srcdir}/pid.$$
30
31update_config test-cookie-timeout-2.config
32launch_server -d 1 -f -c ${CONFIG} & PID=$!
33wait_server $PID
34
35echo "Connecting to obtain cookie... "
36eval `echo "test" | $OPENCONNECT -q localhost:$PORT -u test --authenticate --servercert=d66b507ae074d03b02eafca40d35f87dd81049d3`
37
38if [ -z "$COOKIE" ];then
39	fail $PID "Could not obtain cookie"
40fi
41
42#echo "Cookie: $COOKIE"
43sleep 10
44echo ""
45echo "Connecting with cookie... "
46echo "test" | $OPENCONNECT -q -b localhost:$PORT -u test -C "$COOKIE" --servercert=d66b507ae074d03b02eafca40d35f87dd81049d3 --script=/bin/true --verbose --pid-file ${srcdir}/pid.$$ --background
47
48sleep 4
49
50if [ ! -f ${srcdir}/pid.$$ ];then
51	fail $PID "It was not possible to establish session!"
52fi
53
54CPID=`cat ${srcdir}/pid.$$`
55rm -f "${srcdir}/pid.$$"
56rm -f "${srcdir}/pid2.$$"
57
58sleep 30
59echo ""
60echo "Connecting again with cookie (overriding first session)... "
61echo "test" | $OPENCONNECT -b -q localhost:$PORT -u test -C "$COOKIE" --servercert=d66b507ae074d03b02eafca40d35f87dd81049d3 --script=/bin/true --verbose --pid-file ${srcdir}/pid2.$$ --background
62
63sleep 6
64
65kill $CPID
66if [ ! -f ${srcdir}/pid2.$$ ];then
67	fail $PID "It was not possible to establish second session!"
68else
69	CPID=`cat ${srcdir}/pid2.$$`
70	kill $CPID
71	rm -f "${srcdir}/pid2.$$"
72fi
73
74kill $PID
75wait
76
77rm -f ${srcdir}/pid.$$
78rm -f ${srcdir}/pid2.$$ ${CONFIG}
79
80exit 0
81