mirror of
https://github.com/OpenVPN/openvpn.git
synced 2025-05-09 05:31:05 +08:00

- exit after a timeout if unable to kill servers - use sudo or equivalent only for server stop/start - use /bin/sh directly instead of through /usr/bin/env - simplify sudo call in the sample rc file - remove misleading and outdated documentation - make it work on OpenBSD 7.5 - make it work on NetBSD 10.0 - make server logs readable by normal users Change-Id: I2cce8ad4e0d262e1404ab1eb6ff673d8590b6b3a Signed-off-by: Samuli Seppänen <samuli.seppanen@gmail.com> Acked-by: Frank Lichtenheld <frank@lichtenheld.com> Message-Id: <20240704133337.26595-1-gert@greenie.muc.de> URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg28871.html Signed-off-by: Gert Doering <gert@greenie.muc.de>
141 lines
3.7 KiB
Bash
Executable File
141 lines
3.7 KiB
Bash
Executable File
#!/bin/sh
|
|
|
|
launch_client() {
|
|
test_name=$1
|
|
log="${test_name}.log"
|
|
pid="${test_name}.pid"
|
|
client_exec=$2
|
|
client_conf=$3
|
|
|
|
# Ensure that old log and pid files are gone
|
|
rm -f "${log}" "${pid}"
|
|
|
|
"${client_exec}" \
|
|
$client_conf \
|
|
--writepid "${pid}" \
|
|
--setenv pid $pid \
|
|
--log "${log}" &
|
|
}
|
|
|
|
wait_for_results() {
|
|
tests_running="yes"
|
|
|
|
# Wait a bit to allow an OpenVPN client process to create a pidfile to
|
|
# prevent exiting too early
|
|
sleep 1
|
|
|
|
while [ "${tests_running}" = "yes" ]; do
|
|
tests_running="no"
|
|
for t in $test_names; do
|
|
if [ -f "${t}.pid" ]; then
|
|
tests_running="yes"
|
|
fi
|
|
done
|
|
|
|
if [ "${tests_running}" = "yes" ]; then
|
|
echo "Clients still running"
|
|
sleep 1
|
|
fi
|
|
done
|
|
}
|
|
|
|
get_client_test_result() {
|
|
test_name=$1
|
|
should_pass=$2
|
|
log="${test_name}.log"
|
|
|
|
grep "Initialization Sequence Completed" "${log}" > /dev/null
|
|
exit_code=$?
|
|
|
|
if [ $exit_code -eq 0 ] && [ "${should_pass}" = "yes" ]; then
|
|
echo "PASS ${test_name}"
|
|
elif [ $exit_code -eq 1 ] && [ "${should_pass}" = "no" ]; then
|
|
echo "PASS ${test_name} (test failure)"
|
|
elif [ $exit_code -eq 0 ] && [ "${should_pass}" = "no" ]; then
|
|
echo "FAIL ${test_name} (test failure)"
|
|
cat "${log}"
|
|
retval=1
|
|
elif [ $exit_code -eq 1 ] && [ "${should_pass}" = "yes" ]; then
|
|
echo "FAIL ${test_name}"
|
|
cat "${log}"
|
|
retval=1
|
|
fi
|
|
}
|
|
|
|
# Load basic/default tests
|
|
. ${srcdir}/t_server_null_default.rc || exit 1
|
|
|
|
# Load additional local tests, if any
|
|
test -r ./t_server_null.rc && . ./t_server_null.rc
|
|
|
|
# Return value for the entire test suite. Gets set to 1 if any test fails.
|
|
export retval=0
|
|
|
|
# Wait until servers are up. This check is based on the presence of processes
|
|
# matching the PIDs in each servers PID files
|
|
count=0
|
|
server_max_wait=15
|
|
while [ $count -lt $server_max_wait ]; do
|
|
servers_up=0
|
|
server_count=$(echo $TEST_SERVER_LIST|wc -w)
|
|
|
|
# We need to trim single-quotes because some shells return quoted values
|
|
# and some don't. Using "set -o posix" which would resolve this problem is
|
|
# not supported in all shells.
|
|
#
|
|
# While inactive server configurations may get checked they won't increase
|
|
# the active server count as the processes won't be running.
|
|
for i in `set|grep 'SERVER_NAME_'|cut -d "=" -f 2|tr -d "[\']"`; do
|
|
server_pid=$(cat $i.pid 2> /dev/null)
|
|
if ps -p $server_pid > /dev/null 2>&1; then
|
|
servers_up=$(( $servers_up + 1 ))
|
|
fi
|
|
done
|
|
|
|
echo "OpenVPN test servers up: ${servers_up}/${server_count}"
|
|
|
|
if [ $servers_up -ge $server_count ]; then
|
|
retval=0
|
|
break
|
|
else
|
|
count=$(( count + 1))
|
|
sleep 1
|
|
fi
|
|
|
|
if [ $count -eq $server_max_wait ]; then
|
|
retval=1
|
|
exit $retval
|
|
fi
|
|
done
|
|
|
|
# Wait a while to let server processes to settle down
|
|
sleep 1
|
|
|
|
# Launch OpenVPN clients. While at it, construct a list of test names. The list
|
|
# is used later to determine when all OpenVPN clients have exited and it is
|
|
# safe to check the test results.
|
|
test_names=""
|
|
for SUF in $TEST_RUN_LIST
|
|
do
|
|
eval test_name=\"\$TEST_NAME_$SUF\"
|
|
eval client_exec=\"\$CLIENT_EXEC_$SUF\"
|
|
eval client_conf=\"\$CLIENT_CONF_$SUF\"
|
|
|
|
test_names="${test_names} ${test_name}"
|
|
(launch_client "${test_name}" "${client_exec}" "${client_conf}")
|
|
done
|
|
|
|
# Wait until all OpenVPN clients have exited
|
|
(wait_for_results)
|
|
|
|
# Check test results
|
|
for SUF in $TEST_RUN_LIST
|
|
do
|
|
eval test_name=\"\$TEST_NAME_$SUF\"
|
|
eval should_pass=\"\$SHOULD_PASS_$SUF\"
|
|
|
|
get_client_test_result "${test_name}" "${should_pass}"
|
|
done
|
|
|
|
exit $retval
|