1#!/bin/bash 2# 3# Copyright (C) 2019 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 whether max-same-clients=1 allows cookie re-use... " 29 30PIDFILE1="${srcdir}/ci$$-1.pid.tmp" 31PIDFILE2="${srcdir}/ci$$-2.pid.tmp" 32rm -f "${PIDFILE1}" "${PIDFILE2}" 33 34function finish { 35 set +e 36 echo " * Cleaning up..." 37 test -n "${PID}" && kill ${PID} >/dev/null 2>&1 38 test -f "${PIDFILE1}" && kill $(cat ${PIDFILE1}) >/dev/null 2>&1 39 test -f "${PIDFILE2}" && kill $(cat ${PIDFILE2}) >/dev/null 2>&1 40 test -n "${CONFIG}" && rm -f ${CONFIG} >/dev/null 2>&1 41 rm -f "${PIDFILE1}" "${PIDFILE2}" 2>&1 42} 43trap finish EXIT 44 45update_config test-max-same-1.config 46launch_server -d 1 -f -c ${CONFIG} & PID=$! 47wait_server $PID 48 49echo "Connecting to obtain cookie... " 50eval `echo "test" | $OPENCONNECT -q localhost:$PORT -u test --authenticate --servercert=d66b507ae074d03b02eafca40d35f87dd81049d3` 51 52if [ -z "$COOKIE" ];then 53 echo "Could not obtain cookie" 54 exit 1 55fi 56 57#echo "Cookie: $COOKIE" 58 59echo "Connecting with cookie... " 60echo "test" | $OPENCONNECT -q localhost:$PORT -u test -C "$COOKIE" --servercert=d66b507ae074d03b02eafca40d35f87dd81049d3 --script=/bin/true --verbose --pid-file "${PIDFILE1}" --background 61 62sleep 4 63 64echo "Connecting again with same cookie... " 65echo "test" | $OPENCONNECT -q localhost:$PORT -b -u test -C "$COOKIE" --servercert=d66b507ae074d03b02eafca40d35f87dd81049d3 --script=/bin/true --verbose --pid-file "${PIDFILE2}" --background 66 67sleep 4 68 69if [ ! -f "${PIDFILE2}" ];then 70 echo "It was not possible to establish session!" 71 exit 1 72fi 73 74# checking whether server has already terminated $CPID 75sleep 1 76 77if [ -f "${PIDFILE1}" ];then 78 echo "Initial connection was still running!" 79 exit 1 80fi 81 82exit 0 83