Files
ocserv/tests/radius-test
Nikos Mavrogiannopoulos 2ceb0ffb47 radius-test: check whether the special IP values are handled
In particular we check whether 255.255.255.254 is correctly
and the expected IP is assigned to client.
2017-01-18 15:26:31 +01:00

271 lines
6.3 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_OCSERV=443
#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
TMPFILE=$IMAGE_NAME-tmp.tmp
. ./docker-common.sh
$DOCKER run -e OCCTL_PAGER=cat -P --privileged=true --tty=false -d --name $IMAGE_NAME $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
get_ip
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
echo ""
$ECHO_E "testuser" >pass-radius$TMP
$OPENCONNECT $IP:$PORT_OCSERV -u test --passwd-on-stdin --servercert=d66b507ae074d03b02eafca40d35f87dd81049d3 --cookieonly < pass-radius$TMP
if test $? = 0;then
echo "Authentication with wrong password succeeded!"
stop
fi
echo ""
$ECHO_E "test" >pass-radius$TMP
$OPENCONNECT $IP:$PORT_OCSERV -u testuser --passwd-on-stdin --servercert=d66b507ae074d03b02eafca40d35f87dd81049d3 --cookieonly < pass-radius$TMP
if test $? = 0;then
echo "Authentication with wrong username succeeded!"
stop
fi
echo ""
echo "Trying with correct password and special IP"
$ECHO_E "test-arb" >pass-radius$TMP
$OPENCONNECT $IP:$PORT_OCSERV -v -u test-arb --passwd-on-stdin --servercert=d66b507ae074d03b02eafca40d35f87dd81049d3 < pass-radius$TMP >$TMPFILE &
PID=$!
sleep 5
grep 'X-CSTP-Address: 192.168.55.' $TMPFILE
if test $? != 0;then
kill -INT $PID
echo "Unexpected address was assigned"
stop
fi
ping -w 3 192.168.55.1
if test $? != 0;then
kill -INT $PID
echo "Cannot ping ocserv"
stop
fi
kill -INT $PID
sleep 3
echo "Trying with correct password and normal IP"
$ECHO_E "test" >pass-radius$TMP
$OPENCONNECT $IP:$PORT_OCSERV -u test --passwd-on-stdin -v --servercert=d66b507ae074d03b02eafca40d35f87dd81049d3 < pass-radius$TMP &
PID=$!
#wait for openconnect
sleep 5
rm -f pass-radius$TMP
# The client IP depends on the username so it shouldn't change.
ping -w 5 192.168.55.1
if test $? != 0;then
kill -INT $PID
echo "Cannot ping ocserv"
stop
fi
ping -w 5 192.168.55.1 -s 1500
if test $? != 0;then
kill -INT $PID
echo "Cannot ping ocserv"
stop
fi
ping6 -w 5 fc13:71:ea31:4b4e::1
if test $? != 0;then
kill -INT $PID
echo "Cannot ping the IPv6 of ocserv"
stop
fi
retrieve_user_info test
# 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 -INT $PID
echo "Cannot send to ocserv"
stop
fi
nuttcp -T 10 -r 192.168.55.1
if test $? != 0;then
kill -INT $PID
echo "Cannot recv from ocserv"
stop
fi
fi
echo "Waiting for accounting report"
sleep 70
kill -INT $PID
sleep 4
check_for_file /tmp/disconnect/not-ok
if test $? = 0;then
echo "There was an issue"
stop
fi
DIR=`$DOCKER exec $IMAGE_NAME ls '/var/log/radius/radacct/'|tail -1`
FILE=`$DOCKER exec $IMAGE_NAME ls '/var/log/radius/radacct/'"$DIR"|tail -1`
OCTETS=`$DOCKER exec $IMAGE_NAME cat "/var/log/radius/radacct/$DIR/$FILE"|grep Acct-Input-Octets|tail -1|sed 's/Acct-Input-Octets = //g'`
if test -z "$OCTETS" || test "$OCTETS" = 0;then
$DOCKER exec $IMAGE_NAME cat "/var/log/radius/radacct/$DIR/$FILE"
echo "Interim update showed no data!"
stop
fi
check_for_file /tmp/disconnect/ok
if test $? != 0;then
$DOCKER exec $IMAGE_NAME cat "/var/log/radius/radacct/$DIR/$FILE"
echo "There was an issue getting stats"
stop
fi
ret=0
#wait until sec-mod has cleaned up its entries
echo "Waiting for disconnection report"
sleep 10
DISC=`$DOCKER exec $IMAGE_NAME cat "/var/log/radius/radacct/$DIR/$FILE"|grep "Acct-Terminate-Cause = User-Request"|tail -1`
if test -z "$DISC";then
$DOCKER exec $IMAGE_NAME cat "/var/log/radius/radacct/$DIR/$FILE"
echo "No disconnect was detected!"
stop
fi
PIDFILE=out$TMP.pid.tmp
# do the same with a certificate - test radius accounting with certificate auth
echo "Trying with certificate"
rm -f "$PIDFILE"
$DOCKER exec $IMAGE_NAME truncate --size=0 /var/log/radius/radacct/$DIR/$FILE
$OPENCONNECT $IP:$PORT_OCSERV -b --sslkey ./certs/user-key.pem -c ./certs/user-cert.pem --servercert=d66b507ae074d03b02eafca40d35f87dd81049d3 --pid-file="$PIDFILE"
sleep 10
if test -f "$PIDFILE";then
PID=`cat "$PIDFILE"`
else
echo "Cannot determine PID of client"
stop
fi
ping -w 5 192.168.55.1
if test $? != 0;then
kill -INT $PID
echo "Cannot ping ocserv"
stop
fi
sleep 4
echo "Waiting for accounting report"
sleep 70
kill -INT $PID
sleep 10
DIR=`$DOCKER exec $IMAGE_NAME ls '/var/log/radius/radacct/'|tail -1`
FILE=`$DOCKER exec $IMAGE_NAME ls '/var/log/radius/radacct/'"$DIR"|tail -1`
$DOCKER exec $IMAGE_NAME cat "/var/log/radius/radacct/$DIR/$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
echo "No connect status was detected!"
stop
fi
DISC=`cat out$TMP|grep Connect-Info`
if test -z "$DISC";then
cat out$TMP
echo "Accounting information had no Connect-Info!"
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 $IMAGE_NAME
$DOCKER rm $IMAGE_NAME
rm -f out$TMP $TMPFILE
exit $ret