mirror of
https://gitlab.com/openconnect/ocserv.git
synced 2026-02-10 08:46:58 +08:00
tests: check whether the firewall rules have been applied with restrict-user-to-routes
This commit is contained in:
142
tests/firewall-test
Executable file
142
tests/firewall-test
Executable file
@@ -0,0 +1,142 @@
|
||||
#!/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:-.}
|
||||
|
||||
#this test can only be run as root
|
||||
id|grep root >/dev/null 2>&1
|
||||
if [ $? != 0 ];then
|
||||
exit 77
|
||||
fi
|
||||
|
||||
PORT_OCSERV=443
|
||||
CONFIG="fw"
|
||||
IMAGE=ocserv-fw-test
|
||||
IMAGE_NAME=test_fw_ocserv
|
||||
TMP=$IMAGE_NAME.tmp
|
||||
. ./docker-common.sh
|
||||
|
||||
$DOCKER run -e OCCTL_PAGER=cat -P --privileged=true -p 22 --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
|
||||
|
||||
IP=`$DOCKER inspect $IMAGE_NAME | 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
|
||||
|
||||
$ECHO_E "testuser" >pass-full$TMP
|
||||
$OPENCONNECT $IP:$PORT_OCSERV -u test --passwd-on-stdin -v --servercert=d66b507ae074d03b02eafca40d35f87dd81049d3 --cookieonly < pass-full$TMP
|
||||
if test $? = 0;then
|
||||
echo "Authentication with wrong password succeeded!"
|
||||
stop
|
||||
fi
|
||||
|
||||
$ECHO_E "test" >pass-full$TMP
|
||||
$OPENCONNECT $IP:$PORT_OCSERV -u testuser --passwd-on-stdin -v --servercert=d66b507ae074d03b02eafca40d35f87dd81049d3 --cookieonly < pass-full$TMP
|
||||
if test $? = 0;then
|
||||
echo "Authentication with wrong username succeeded!"
|
||||
stop
|
||||
fi
|
||||
|
||||
echo ""
|
||||
echo "Connecting with correct username"
|
||||
$ECHO_E "test" >pass-full$TMP
|
||||
$OPENCONNECT $IP:$PORT_OCSERV -b --pid-file ${srcdir}/pid1.$$ -u test --passwd-on-stdin -v --servercert=d66b507ae074d03b02eafca40d35f87dd81049d3 < pass-full$TMP
|
||||
if test $? != 0;then
|
||||
echo "Cannot connect to server"
|
||||
stop
|
||||
fi
|
||||
|
||||
#wait for openconnect
|
||||
sleep 5
|
||||
|
||||
rm -f pass-full$TMP
|
||||
if [ ! -f ${srcdir}/pid1.$$ ];then
|
||||
echo "It was not possible to establish session!"
|
||||
stop
|
||||
fi
|
||||
|
||||
PID=`cat ${srcdir}/pid1.$$`
|
||||
|
||||
ping -w 5 192.168.84.1 -s 400
|
||||
if test $? != 0;then
|
||||
kill -INT $PID
|
||||
echo "Cannot ping ocserv"
|
||||
stop
|
||||
fi
|
||||
|
||||
ping6 -w 5 fd91:6d87:7441:dc6a::1
|
||||
if test $? != 0;then
|
||||
kill -INT $PID
|
||||
echo "Cannot ping the IPv6 of ocserv"
|
||||
stop
|
||||
fi
|
||||
|
||||
retrieve_user_info test "Restricted to routes: True"
|
||||
|
||||
# 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.84.1
|
||||
if test $? != 0;then
|
||||
echo "Cannot send to ocserv"
|
||||
exit 77
|
||||
kill -INT $PID
|
||||
stop
|
||||
fi
|
||||
|
||||
nuttcp -T 10 -r 192.168.84.1
|
||||
if test $? != 0;then
|
||||
echo "Cannot recv from ocserv"
|
||||
exit 77
|
||||
kill -INT $PID
|
||||
stop
|
||||
fi
|
||||
fi
|
||||
|
||||
sleep 2
|
||||
|
||||
kill -INT $PID
|
||||
|
||||
sleep 4
|
||||
|
||||
check_for_file /tmp/follow-up-script-was-run
|
||||
if test $? != 0;then
|
||||
echo "There was an issue; followup script was not run"
|
||||
stop
|
||||
fi
|
||||
|
||||
$DOCKER stop $IMAGE_NAME
|
||||
$DOCKER rm $IMAGE_NAME
|
||||
|
||||
exit $ret
|
||||
Reference in New Issue
Block a user