ocserv/tests/test-config-per-group-url-cert
Marcin Ochab 3f966ae8ca Allow selecting group by URL or profile
This introduces the 'select-group-by-url' config option
that allows selecting an authgroup just by connecting to
a dedicated URI.

Signed-off-by: Marcin Ochab <marcin.ochab@gmail.com>
Signed-off-by: Nikos Mavrogiannopoulos <n.mavrogiannopoulos@gmail.com>
2024-04-23 21:35:00 +02:00

198 lines
5.4 KiB
Bash
Executable File

#!/bin/bash
#
# Copyright (C) 2018 Nikos Mavrogiannopoulos and Marcin Ochab
#
# 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 this program. If not, see <http://www.gnu.org/licenses/>.
#
# This tests whether connecting to the VPN via a group on the URL works
OCCTL="${OCCTL:-../src/occtl/occtl}"
SERV="${SERV:-../src/ocserv}"
srcdir=${srcdir:-.}
PIDFILE=ocserv-pid.$$.tmp
CLIPID=oc-pid.$$.tmp
PATH=${PATH}:/usr/sbin
IP=$(which ip)
OUTFILE=traffic.$$.tmp
. `dirname $0`/common.sh
eval "${GETPORT}"
if test -z "${IP}";then
echo "no IP tool is present"
exit 77
fi
if test "$(id -u)" != "0";then
echo "This test must be run as root"
exit 77
fi
echo "Testing ocserv connection via haproxy... "
function finish {
set +e
echo " * Cleaning up..."
test -n "${PIDFILE}" && kill $(cat ${PIDFILE}) && rm -f ${PIDFILE} >/dev/null 2>&1
test -n "${CLIPID}" && kill $(cat ${CLIPID}) >/dev/null 2>&1
test -n "${CLIPID}" && rm -f ${CLIPID} >/dev/null 2>&1
test -n "${CONFIG}" && rm -f ${CONFIG} >/dev/null 2>&1
rm -f ${OUTFILE} 2>&1
}
trap finish EXIT
# server address
ADDRESS=10.204.3.1
CLI_ADDRESS=10.204.4.1
VPNNET=192.168.14.0/24
VPNADDR=192.168.14.1
VPNNET6=fd91:6d87:7344:dc6a:dc15::/112
VPNADDR6=fd91:6d87:7344:dc6a:dc15::1
OCCTL_SOCKET=./occtl-cpg-$$.socket
ROUTE1=192.168.14.0/24
USERNAME=test
PASSWORD=test
. `dirname $0`/ns.sh
# Run servers
update_config config-per-group-url-cert.config
if test "$VERBOSE" = 1;then
DEBUG="-d 6"
fi
${CMDNS2} ${SERV} -p ${PIDFILE} -f -c ${CONFIG} ${DEBUG} &
sleep 4
echo " * Connecting with user selecting group1 by url..."
( ${CMDNS1} ${OPENCONNECT} ${ADDRESS}:${PORT}/group1 -u ${USERNAME} --sslkey ${srcdir}/certs/user-group-key.pem -c ${srcdir}/certs/user-group-cert.pem --servercert=pin-sha256:xp3scfzy3rOQsv9NcOve/8YVVv+pHr4qNCXEXrNl5s8= -s ${srcdir}/scripts/vpnc-script --pid-file=${CLIPID} -b )
if test $? != 0;then
echo "Could not connect to server"
exit 1
fi
echo " * Pinging remote address..."
set -e
${CMDNS1} ping -c 3 ${VPNADDR} >/dev/null 2>&1
echo " * Pinging remote IPV6 address..."
${CMDNS1} ping -6 -c 3 ${VPNADDR6} >/dev/null 2>&1
set +e
echo " * Checking connected user in occtl output..."
${OCCTL} -s ${OCCTL_SOCKET} show users|grep ${USERNAME}
if test $? != 0;then
${OCCTL} -s ${OCCTL_SOCKET} show users|grep ${USERNAME}
echo "occtl didn't find connected user!"
exit 1
fi
${OCCTL} -s ${OCCTL_SOCKET} show user ${USERNAME} >${OUTFILE}
if test $? != 0;then
${OCCTL} -s ${OCCTL_SOCKET} show user ${USERNAME}
echo "occtl didn't find connected user!"
exit 1
fi
cat $OUTFILE
echo " * Checking connected user settings in occtl output..."
grep "DNS: 1.1.1.1" ${OUTFILE} >/dev/null
if test $? = 0;then
cat $OUTFILE
${OCCTL} -s ${OCCTL_SOCKET} show user ${USERNAME}
echo "occtl show user didn't the right DNS address!"
exit 1
fi
grep "1.1.1.0/24" ${OUTFILE}|grep Routes >/dev/null
if test $? = 0;then
${OCCTL} -s ${OCCTL_SOCKET} show user ${USERNAME}
echo "occtl show user didn't the right routes!"
exit 1
fi
grep "No-routes: 192.168.98.0" ${OUTFILE} >/dev/null
if test $? != 0;then
cat $OUTFILE
${OCCTL} -s ${OCCTL_SOCKET} show user ${USERNAME}
echo "occtl show user didn't the right No-routes!"
exit 1
fi
test -n "${CLIPID}" && kill $(cat ${CLIPID}) >/dev/null 2>&1
sleep 2
echo " * Connecting with user selecting group2 by url..."
( ${CMDNS1} ${OPENCONNECT} ${ADDRESS}:${PORT}/group2 -u ${USERNAME} --sslkey ${srcdir}/certs/user-group-key.pem -c ${srcdir}/certs/user-group-cert.pem --servercert=pin-sha256:xp3scfzy3rOQsv9NcOve/8YVVv+pHr4qNCXEXrNl5s8= -s ${srcdir}/scripts/vpnc-script --pid-file=${CLIPID} -b )
if test $? != 0;then
echo "Could not connect to server"
exit 1
fi
echo " * Pinging remote address..."
set -e
${CMDNS1} ping -c 3 ${VPNADDR} >/dev/null 2>&1
echo " * Pinging remote IPV6 address..."
${CMDNS1} ping -6 -c 3 ${VPNADDR6} >/dev/null 2>&1
set +e
echo " * Checking connected user in occtl output..."
${OCCTL} -s ${OCCTL_SOCKET} show users|grep ${USERNAME}
if test $? != 0;then
echo "occtl didn't find connected user!"
exit 1
fi
echo " * Checking connected user in occtl output..."
${OCCTL} -s ${OCCTL_SOCKET} show user ${USERNAME} >${OUTFILE}
if test $? != 0;then
${OCCTL} -s ${OCCTL_SOCKET} show user ${USERNAME}
echo "occtl didn't find connected user!"
exit 1
fi
cat $OUTFILE
echo " * Checking connected user settings in occtl output..."
grep "DNS: 1\.1\.1\.1" ${OUTFILE} >/dev/null
if test $? != 0;then
${OCCTL} -s ${OCCTL_SOCKET} show user ${USERNAME}
echo "occtl show user didn't the right DNS address!"
exit 1
fi
grep "1\.1\.1\.0/255\.255\.255\.0" ${OUTFILE}|grep Routes >/dev/null
if test $? != 0;then
cat $OUTFILE
${OCCTL} -s ${OCCTL_SOCKET} show user ${USERNAME}
echo "occtl show user didn't the right routes!"
exit 1
fi
grep ${CLI_ADDRESS} ${OUTFILE}
if test $? != 0;then
${OCCTL} -s ${OCCTL_SOCKET} show user ${USERNAME}
echo "occtl show user didn't find client address!"
exit 1
fi
exit 0