Files
ocserv/tests/radius-test
Nikos Mavrogiannopoulos 3cc5223842 tests: updated IPv6 addresses
2015-05-11 16:14:38 +02:00

273 lines
6.7 KiB
Bash
Executable File

#!/bin/sh
#
# Copyright (C) 2014 Red Hat
#
# This file is part of ocserv.
#
# ocserv is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by the
# Free Software Foundation; either version 2 of the License, or (at
# your option) any later version.
#
# ocserv is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with ocserv; if not, write to the Free Software Foundation,
# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
srcdir=${srcdir:-.}
PORT=10500
PORT2=10501
PORT_OCSERV=10522
#this test can only be run as root
id|grep root >/dev/null 2>&1
if [ $? != 0 ];then
exit 77
fi
CONFIG="radius"
IMAGE=ocserv-radius-test
IMAGE_NAME=test_ocserv_radius
TMP=$IMAGE_NAME.tmp
. ./docker-common.sh
$DOCKER run -P --privileged=true -p $PORT:$PORT/udp -p $PORT2:$PORT2/udp -p 22 -p $PORT_OCSERV:$PORT_OCSERV/udp --tty=false -d --name test_ocserv_radius $IMAGE
if test $? != 0;then
echo "Cannot run docker image"
exit 1
fi
echo "ocserv image was run"
#wait for ocserv to server
sleep 5
IP=`$DOCKER inspect test_ocserv_radius | grep IPAddress | cut -d '"' -f 4`
if test -z "$IP";then
echo "Detected IP is null!"
stop
fi
echo "Detected IP: $IP"
if test ! -z "$QUIT_ON_INIT";then
exit 0
fi
printf "testuser\n" >pass-radius$TMP
$OPENCONNECT $IP:$PORT_OCSERV -u test --passwd-on-stdin -v --servercert=d66b507ae074d03b02eafca40d35f87dd81049d3 --cookieonly < pass-radius$TMP
if test $? = 0;then
echo "Authentication with wrong password succeeded!"
stop
fi
printf "test\n" >pass-radius$TMP
$OPENCONNECT $IP:$PORT_OCSERV -u testuser --passwd-on-stdin -v --servercert=d66b507ae074d03b02eafca40d35f87dd81049d3 --cookieonly < pass-radius$TMP
if test $? = 0;then
echo "Authentication with wrong username succeeded!"
stop
fi
echo "Trying with correct password"
printf "test\n" >pass-radius$TMP
$OPENCONNECT $IP:$PORT_OCSERV -u test --passwd-on-stdin -v --servercert=d66b507ae074d03b02eafca40d35f87dd81049d3 < pass-radius$TMP &
PID=$!
rm -f pass-radius$TMP
#wait for openconnect
sleep 5
# The client IP depends on the username so it shouldn't change.
ping -w 5 192.168.55.1
if test $? != 0;then
kill $PID
echo "Cannot ping ocserv"
stop
fi
ping -w 5 192.168.55.1 -s 1500
if test $? != 0;then
kill $PID
echo "Cannot ping ocserv"
stop
fi
ping6 -w 5 fd91:6d87:7341:dd6b:0:52:190c:be01
if test $? != 0;then
kill $PID
echo "Cannot ping the IPv6 of ocserv"
stop
fi
echo "UserKnownHostsFile ./known-hosts$TMP" >config$TMP
printf "#\!/bin/sh\n" >echo-admin$TMP
printf "echo yes" >>echo-admin$TMP
printf "echo root" >>echo-admin$TMP
printf "\n" >>echo-admin$TMP
chmod 755 echo-admin$TMP
export SSH_ASKPASS="./echo-admin$TMP"
setsid ssh -T -F config$TMP root@192.168.55.1 occtl show user test >out$TMP 2>&1
cat out$TMP
printf "#\!/bin/sh\n" >echo-admin$TMP
printf "echo root" >>echo-admin$TMP
printf "\n" >>echo-admin$TMP
chmod 755 echo-admin$TMP
setsid ssh -T -F config$TMP root@192.168.55.1 occtl show user test >out$TMP 2>&1
cat out$TMP
rm -f echo-admin$TMP
rm -f config$TMP
rm -f known-hosts$TMP
grep "Username" out$TMP
if test $? != 0;then
kill $PID
echo "could not find user information"
stop
fi
rm -f out$TMP
# There is an issue in nuttcp that makes it crash under docker if
# /proc/sys/net/ipv4/tcp_adv_win_scale does not exist.
if test "$FEDORA" = 1;then
nuttcp -T 10 -t 192.168.55.1
if test $? != 0;then
kill $PID
echo "Cannot send to ocserv"
stop
fi
nuttcp -T 10 -r 192.168.55.1
if test $? != 0;then
kill $PID
echo "Cannot recv from ocserv"
stop
fi
fi
echo "Waiting for accounting report"
sleep 60
kill -INT $PID
sleep 4
TMPDIR=radius-$TMP
mkdir -p $TMPDIR
#check whether /tmp/disconnect/ok was created
rm -f $TMPDIR/not-ok
$DOCKER cp test_ocserv_radius:/tmp/disconnect/not-ok $TMPDIR/
if test -f $TMPDIR/not-ok;then
echo "There was an issue getting stats"
stop
fi
rm -f $TMPDIR/not-ok
rm -f $TMPDIR/stats
FILE=`$DOCKER exec test_ocserv_radius ls /var/log/radius/radacct/127.0.0.1/`
echo $DOCKER exec test_ocserv_radius cat "/var/log/radius/radacct/127.0.0.1/$FILE"
$DOCKER exec test_ocserv_radius cat "/var/log/radius/radacct/127.0.0.1/$FILE"
OCTETS=`$DOCKER exec test_ocserv_radius cat "/var/log/radius/radacct/127.0.0.1/$FILE"|grep Acct-Input-Octets|tail -1|sed 's/Acct-Input-Octets = //g'`
if test -z "$OCTETS" || test "$OCTETS" = 0;then
echo "Interim update showed no data!"
stop
fi
rm -f $TMPDIR/ok
$DOCKER cp test_ocserv_radius:/tmp/disconnect/ok $TMPDIR/
if ! test -f $TMPDIR/ok;then
echo "Don't know if stats were received"
ret=77
else
echo -n "stats: "
echo `cat $TMPDIR/ok`
rm -rf $TMPDIR/
fi
ret=0
#wait until sec-mod has cleaned up its entries
echo "Waiting for disconnection report"
sleep 10
DISC=`$DOCKER exec test_ocserv_radius cat "/var/log/radius/radacct/127.0.0.1/$FILE"|grep "Acct-Terminate-Cause = User-Request"|tail -1`
if test -z "$DISC";then
$DOCKER exec test_ocserv_radius cat "/var/log/radius/radacct/127.0.0.1/$FILE"
echo "No disconnect was detected!"
stop
fi
# do the same with a certificate - test radius accounting with certificate auth
echo "Trying with certificate"
rm -f out$TMP.pid
$DOCKER exec test_ocserv_radius truncate --size=0 /var/log/radius/radacct/127.0.0.1/$FILE
$OPENCONNECT $IP:$PORT_OCSERV -b --sslkey ./user-key.pem -c ./user-cert.pem --servercert=d66b507ae074d03b02eafca40d35f87dd81049d3 --pid-file=out$TMP.pid
sleep 10
if test -f out$TMP.pid;then
PID=`cat out$TMP.pid`
else
echo "Cannot determine PID of client"
stop
fi
ping -w 5 192.168.55.1
if test $? != 0;then
kill $PID
echo "Cannot ping ocserv"
stop
fi
sleep 4
echo "Waiting for accounting report"
sleep 60
kill -INT $PID
sleep 10
FILE=`$DOCKER exec test_ocserv_radius ls /var/log/radius/radacct/127.0.0.1/|tail -1`
$DOCKER exec test_ocserv_radius cat "/var/log/radius/radacct/127.0.0.1/$FILE" >out$TMP
cat out$TMP
OCTETS=`cat out$TMP|grep Acct-Input-Octets|tail -1|sed 's/Acct-Input-Octets = //g'`
if test -z "$OCTETS" || test "$OCTETS" = 0;then
echo "Interim update showed no data!"
stop
fi
DISC=`cat out$TMP|grep "Acct-Status-Type = Start"|tail -1`
if test -z "$DISC";then
cat out$TMP
echo "No connect status was detected!"
stop
fi
DISC=`cat out$TMP|grep "Acct-Terminate-Cause = User-Request"|tail -1`
if test -z "$DISC";then
cat out$TMP
echo "No disconnect was detected!"
stop
fi
DISC=`cat out$TMP|grep "NAS-IP-Address = 127.0.0.1"|tail -1`
if test -n "$DISC";then
cat out$TMP
echo "NAS-IP-Address has invalid value!"
stop
fi
$DOCKER stop test_ocserv_radius
$DOCKER rm test_ocserv_radius
rm -f out$TMP
exit $ret