mirror of
https://gitlab.com/openconnect/ocserv.git
synced 2026-02-10 08:46:58 +08:00
157 lines
3.4 KiB
Bash
Executable File
157 lines
3.4 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:-.}
|
|
|
|
#this test can only be run as root
|
|
id|grep root >/dev/null 2>&1
|
|
if [ $? != 0 ];then
|
|
exit 77
|
|
fi
|
|
|
|
UNIX=1
|
|
CONFIG="unix"
|
|
IMAGE=ocserv-test2
|
|
IMAGE_NAME=test_unix
|
|
TMP=$IMAGE_NAME.tmp
|
|
. ./docker-common.sh
|
|
|
|
$DOCKER run -P --privileged=true -p 6000:6000/udp -p 6001:6001/udp -p 22 -p 6551:6551/udp --tty=false -d --name test_unix $IMAGE
|
|
if test $? != 0;then
|
|
echo "Cannot run docker image"
|
|
exit 1
|
|
fi
|
|
|
|
#wait for ocserv to server
|
|
sleep 5
|
|
|
|
IP=`$DOCKER inspect test_unix | 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 "test\ntest\n" >pass$TMP
|
|
$OPENCONNECT $IP:6551 -u test --passwd-on-stdin --servercert=d66b507ae074d03b02eafca40d35f87dd81049d3 < pass$TMP &
|
|
PID=$!
|
|
|
|
rm -f pass$TMP
|
|
|
|
#wait for openconnect
|
|
sleep 5
|
|
|
|
# The client IP depends on the username so it shouldn't change.
|
|
ping -w 5 192.168.99.1
|
|
if test $? != 0;then
|
|
kill $PID
|
|
echo "Cannot ping ocserv"
|
|
stop
|
|
fi
|
|
|
|
ping -w 5 192.168.99.1 -s 1500
|
|
if test $? != 0;then
|
|
kill $PID
|
|
echo "Cannot ping 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.99.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.99.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.
|
|
|
|
#nuttcp -T 10 -t 192.168.99.1
|
|
#if test $? != 0;then
|
|
# kill $PID
|
|
# echo "Cannot send to ocserv"
|
|
# stop
|
|
#fi
|
|
|
|
#nuttcp -T 10 -r 192.168.99.1
|
|
#if test $? != 0;then
|
|
# kill $PID
|
|
# echo "Cannot recv from ocserv"
|
|
# stop
|
|
#fi
|
|
sleep 2
|
|
|
|
kill $PID
|
|
|
|
sleep 4
|
|
|
|
#check whether /tmp/disconnect/ok was created
|
|
rm -f ./not-ok
|
|
$DOCKER cp test_unix:/tmp/disconnect/not-ok ./
|
|
if test -f ./not-ok;then
|
|
echo "There was an issue getting stats"
|
|
stop
|
|
fi
|
|
rm -f ./not-ok
|
|
|
|
ret=0
|
|
|
|
rm -f ./tmp-unix/ok
|
|
$DOCKER cp test_unix:/tmp/disconnect/ok ./tmp-unix/
|
|
if ! test -f ./tmp-unix/ok;then
|
|
echo "Don't know if stats were received"
|
|
ret=77
|
|
else
|
|
echo -n "stats: "
|
|
echo `cat ./tmp-unix/ok`
|
|
rm -rf ./tmp-unix/
|
|
fi
|
|
|
|
$DOCKER stop test_unix
|
|
$DOCKER rm test_unix
|
|
|
|
exit $ret
|