From: "mattock (Code Review)" Date: Tue, 11 Jun 2024 10:49:32 +0000 In-Reply-To: References: Reply-To: samuli@...515..., arne-openvpn@...1227..., openvpn-devel@lists.sourceforge.net, frank@...2641... Message-ID: <386837f63e9692e24f6935d3ab0b3334454437ba-EmailReplacePatchSet-HTML@...2715...> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Disposition: inline Content-Type: multipart/alternative; boundary="ErG8nJVqCTQ="; charset=UTF-8 Subject: [Openvpn-devel] [L] Change in openvpn[master]: Add t_server_null test suite List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: plaisthos , flichtenheld Cc: openvpn-devel --ErG8nJVqCTQ= Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Attention is currently required from: mattock, plaisthos. Hello flichtenheld, plaisthos, I'd like you to reexamine a change. Please visit http://gerrit.openvpn.net/c/openvpn/+/663?usp=3Demail to look at the new patch set (#2). Change subject: Add t_server_null test suite ...................................................................... Add t_server_null test suite Change-Id: I1b54da258c7d15551b6c3de7522a0d19afdb66de Signed-off-by: Samuli Sepp=C3=A4nen --- M .gitignore A doc/t_server_null.rst M tests/Makefile.am A tests/null_client_up.sh A tests/t_server_null.rc-sample A tests/t_server_null.sh A tests/t_server_null_client.sh A tests/t_server_null_default.rc A tests/t_server_null_server.sh A tests/t_server_null_stress.sh 10 files changed, 568 insertions(+), 2 deletions(-) git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/63/663/2 diff --git a/.gitignore b/.gitignore index 92d65bf..db8bb73 100644 --- a/.gitignore +++ b/.gitignore @@ -55,6 +55,7 @@ tests/t_client.sh tests/t_client-*-20??????-??????/ +tests/t_server_null.rc t_client.rc t_client_ips.rc tests/unit_tests/**/*_testdriver diff --git a/doc/t_server_null.rst b/doc/t_server_null.rst new file mode 100644 index 0000000..e3a098a --- /dev/null +++ b/doc/t_server_null.rst @@ -0,0 +1,147 @@ +Notes for the --dev null test suite +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D + +Introduction +------------ + +The *--dev null test suite* is primary targeted at testing client connecti= ons +to the "just compiled" version of OpenVPN. The name is derived from "null" +device type in OpenVPN. In particular, when *--dev null --ifconfig-noexec*= is +used in OpenVPN client configuration one does not need to run OpenVPN with= root +privileges because interface, routing, etc. configuration is not done at a= ll. +This is still enough to ensure that the OpenVPN client can connect to a se= rver +instance. + +The main features of the test suite: + +* Parallelized for fairly high performance +* Mostly operating-system agnostic +* Tested on Fedora Linux 38/39/40 and FreeBSD 14 +* POSIX-compliant +* Tested and known to work with Bash, Dash, Ksh, Yash and FreeBSD's defaul= t /bin/sh +* Uses the sample certificates and keys +* Supports running multiple servers and clients +* Supports running servers directly as root and with sudo +* Supports using different OpenVPN client versions + + * The "current" (just compiled) version + * Any other OpenVPN versions that is present on the filesystem + +* Support testing for success as well as failure +* Test cases (client configurations) and server setups (server configurati= ons) are stored in a configuration file, i.e. data and code have been separ= ated +* Configuration file format is nearly identical to t_client.rc configurati= on +* Supports a set of default tests, overriding default test settings and ad= ding local tests + +Prerequisites +------------- + +Running the test suite requires the following: + +* *bash* for running the tests +* root-level privileges for launching the servers + + * run as root + * a privilege escalation tool (sudo, doas, su) and the permission to bec= ome root + +Technical implementation +------------------------ + +The test suite is completely parallelized to allow running a large number = of +server and client combinations quickly. + +A normal test run looks like this: + +#. Server instances start +#. Brief wait +#. Client instances start +#. Tests run +#. Client instances stop +#. Brief wait +#. Server instances stop + +The tests suite is launched via "make check": + +* make check + + * t_server_null.sh + + * t_server_null_server.sh + + * Launches the compiled OpenVPN server instances as root (if necessa= ry with sudo or su) in the background. The servers are killed using their m= anagement interface once all clients have exited. + + * t_server_null_client.sh + + * Waits until servers have launched. Then launch all clients, wait f= or them to exit and then check test results by parsing the client log files= . Each client kills itself after some delay using an "--up" script. + +Note that "make check" moves on once *t_server_null_client.sh* has exited.= At +that point *t_server_null_server.sh* is still running, because it exists o= nly +after waiting a few seconds for more client connections to potentially app= ear. +This is a feature and not a bug, but means that launching "make check" run= s too +quickly might cause test failures or unexpected behavior such as leftover +OpenVPN server processes. + +Configuration +------------- + +The test suite reads its configuration from two files: + +* *tests/t_server_null_defaults.rc:* default test configuration that shoul= d work on any system +* *tests/t_server_null.rc:* a local configuration file; can be used to add= additional tests or override settings from the default test configuration.= Must be present or tests will be skipped, but can be an empty file. + +The configuration syntax is very similar to *t_client.rc*. New server inst= ances can be +defined like this:: + + SERVER_NAME_5=3D"t_server_null_server-11195_udp" + SERVER_MGMT_PORT_5=3D"11195" + SERVER_EXEC_5=3D"${SERVER_EXEC}" + SERVER_CONF_5=3D"${SERVER_CONF_BASE} --lport 11195 --proto udp --managem= ent 127.0.0.1 ${SERVER_MGMT_PORT_5}" + +In this case the server instance identifier is **5**. Variables such as +*SERVER_EXEC* and *SERVER_CONF_BASE* are defined in +*t_server_null_defaults.rc*. To enable this server instance add it to the +server list:: + + TEST_SERVER_LIST=3D"1 2 5" + +The client instances are added similarly:: + + TEST_NAME_9=3D"t_server_null_client.sh-openvpn_current_udp_custom" + SHOULD_PASS_9=3D"yes" + CLIENT_EXEC_9=3D"${CLIENT_EXEC}" + CLIENT_CONF_9=3D"${CLIENT_CONF_BASE} --remote 127.0.0.1 1194 udp --proto= udp" + +In this case the test identifier is **9**. *CLIENT_EXEC* and *CLIENT_CONF_= BASE* +are defined in *t_server_null_defaults.rc*. The variable *SHOULD_PASS* +determines that this particular test is supposed to succeed and not fail. = To +enable this client instance add it to the test list:: + + TEST_RUN_LIST=3D"1 2 5 9" + +Stress-testing the --dev null test suite +---------------------------------------- + +It is very easy to introduce subtle, difficult to debug issues to the --dev +null tests when you make changes to it. These issues can be difficult to s= pot: +based on practical experience a bad change can make the test failure rate = go +from 0% (normal) to anywhere between 1% and 20%. You can spot these issues= with +the provided stress-test script, *t_server_null_stress.sh*. It calls *make= check* +over and over again in a loop and when failures occur it saves the output = under +*tests/make-check*. + +To follow the test flow on Linux you can run this while stress-testing:: + + watch -n 0.5 "ps aux|grep -E '(openvpn|t_server_null_server.sh)'|grep = -vE '(suppress|grep|tail)'" + +Regarding privilege escalation +------------------------------ + +The --dev null test servers need to be launched as root. Either run the te= sts +as root directly, or configure a privilege escalation tool of your choice = in +*t_server_null.rc*. For example, to use sudo:: + + SUDO_EXEC=3D`which sudo` + RUN_SUDO=3D"${SUDO_EXEC} -E" + +If you do stress-testing with *t_server_null_stress.sh* make sure your +privilege escalation authorization does not time out: if it does, then a +reauthorization prompt will interrupt your tests. diff --git a/tests/Makefile.am b/tests/Makefile.am index 5e9ad0a..f26b3b8 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -15,10 +15,10 @@ SUBDIRS =3D unit_tests AM_TESTSUITE_SUMMARY_HEADER =3D ' for $(PACKAGE_STRING) System Tests' -LOG_DRIVER =3D $(SHELL) $(top_srcdir)/forked-test-driver +SH_LOG_DRIVER =3D $(SHELL) $(top_srcdir)/forked-test-driver if !WIN32 -test_scripts =3D t_client.sh t_lpback.sh t_cltsrv.sh +test_scripts =3D t_client.sh t_lpback.sh t_cltsrv.sh t_server_null.sh check_PROGRAMS =3D ntlm_support if HAVE_SITNL @@ -27,6 +27,7 @@ endif TESTS_ENVIRONMENT =3D top_srcdir=3D"$(top_srcdir)" +TEST_EXTENSIONS =3D .sh TESTS =3D $(test_scripts) dist_noinst_SCRIPTS =3D \ @@ -34,8 +35,14 @@ t_cltsrv-down.sh \ t_lpback.sh \ t_net.sh \ + t_server_null.sh \ + t_server_null_client.sh \ + t_server_null_server.sh \ + t_server_null_default.rc \ update_t_client_ips.sh +t_client.log: t_server_null.log + dist_noinst_DATA =3D \ t_client.rc-sample diff --git a/tests/null_client_up.sh b/tests/null_client_up.sh new file mode 100755 index 0000000..d4df0c6 --- /dev/null +++ b/tests/null_client_up.sh @@ -0,0 +1,11 @@ +#!/bin/sh +# +# Stop the parent process (openvpn) gracefully after a small delay + +# Determine the OpenVPN PID from its pid file. This works reliably even wh= en +# the OpenVPN process is backgrounded for parallel tests. +MY_PPID=3D`cat $pid` + +# Allow OpenVPN to finish initializing while waiting in the background and= then +# killing the process gracefully. +(sleep 5 ; kill -15 $MY_PPID) & diff --git a/tests/t_server_null.rc-sample b/tests/t_server_null.rc-sample new file mode 100644 index 0000000..28c3773 --- /dev/null +++ b/tests/t_server_null.rc-sample @@ -0,0 +1,15 @@ +# Uncomment to run tests with sudo +#SUDO_EXEC=3D`which sudo` +#RUN_SUDO=3D"${SUDO_EXEC} -E" + +TEST_RUN_LIST=3D"1 2 3 10 11" + +TEST_NAME_10=3D"t_server_null_client.sh-openvpn_2_6_8_udp" +SHOULD_PASS_10=3D"yes" +CLIENT_EXEC_10=3D"/usr/sbin/openvpn" +CLIENT_CONF_10=3D"${CLIENT_CONF_BASE} --remote 127.0.0.1 1194 udp --proto = udp" + +TEST_NAME_11=3D"t_server_null_client.sh-openvpn_2_6_8_tcp" +SHOULD_PASS_11=3D"yes" +CLIENT_EXEC_11=3D"/usr/sbin/openvpn" +CLIENT_CONF_11=3D"${CLIENT_CONF_BASE} --remote 127.0.0.1 1195 tcp --proto = tcp" diff --git a/tests/t_server_null.sh b/tests/t_server_null.sh new file mode 100755 index 0000000..cfca5ee --- /dev/null +++ b/tests/t_server_null.sh @@ -0,0 +1,72 @@ +#!/usr/bin/env sh +# +TSERVER_NULL_SKIP_RC=3D"${TSERVER_NULL_SKIP_RC:-77}" + +if ! [ -r "./t_server_null.rc" ] ; then + echo "${0}: cannot find './t_server_null.rc. SKIPPING TEST.'" >&2 + exit "${TSERVER_NULL_SKIP_RC}" +fi + +. ./t_server_null.rc + +if KILL_EXEC=3D$(which kill); then + export KILL_EXEC +else + echo "${0}: kill not found in \$PATH" >&2 + exit "${TSERVER_NULL_SKIP_RC}" +fi + +# Ensure PREFER_KSU is in a known state +PREFER_KSU=3D"${PREFER_KSU:-0}" + +# make sure we have permissions to run ifconfig/route from OpenVPN +# can't use "id -u" here - doesn't work on Solaris +ID=3D$(id) +if expr "$ID" : "uid=3D0" >/dev/null +then : +else + if [ "${PREFER_KSU}" -eq 1 ]; + then + # Check if we have a valid kerberos ticket + if klist -l 1>/dev/null 2>/dev/null; then + RUN_SUDO=3D"ksu -q -e" + else + # No kerberos ticket found, skip ksu and fallback to RUN_SUDO + PREFER_KSU=3D0 + echo "${0}: No Kerberos ticket available. Will not use ksu." + fi + fi + + if [ -z "$RUN_SUDO" ] + then + echo "${0}: this test must run be as root, or RUN_SUDO=3D... " >&2 + echo " must be set correctly in 't_server_null.rc'. SKIP." >&2 + exit "${TSERVER_NULL_SKIP_RC}" + else + # Run a no-op command with privilege escalation (e.g. sudo) so that + # we (hopefully) do not have to ask the users password during the test. + if $RUN_SUDO "${KILL_EXEC}" -0 $$ + then + echo "${0}: $RUN_SUDO $KILL_EXEC -0 succeeded, good." + else + echo "${0}: $RUN_SUDO $KILL_EXEC -0 failed, cannot go on. SKIP." >&2 + exit "${TSERVER_NULL_SKIP_RC}" + fi + fi +fi + +srcdir=3D"${srcdir:-.}" + +if [ -z "${RUN_SUDO}" ]; then + "${srcdir}/t_server_null_server.sh" & +else + $RUN_SUDO "${srcdir}/t_server_null_server.sh" & +fi + +"${srcdir}/t_server_null_client.sh" + +# When running make jobs in parallel ("make -j check") we need to ensure +# that this script does not exit before all --dev null servers are dead and +# their network interfaces are gone. Otherwise t_client.sh will fail becau= se +# pre and post ifconfig output does not match. +wait diff --git a/tests/t_server_null_client.sh b/tests/t_server_null_client.sh new file mode 100755 index 0000000..5d5542b --- /dev/null +++ b/tests/t_server_null_client.sh @@ -0,0 +1,136 @@ +#!/usr/bin/env sh + +launch_client() { + test_name=3D$1 + log=3D"${test_name}.log" + pid=3D"${test_name}.pid" + client_exec=3D$2 + client_conf=3D$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=3D"yes" + + # Wait a bit to allow an OpenVPN client process to create a pidfile to + # prevent exiting too early + sleep 1 + + while [ "${tests_running}" =3D "yes" ]; do + tests_running=3D"no" + for t in $test_names; do + if [ -f "${t}.pid" ]; then + tests_running=3D"yes" + fi + done + + if [ "${tests_running}" =3D "yes" ]; then + echo "Clients still running" + sleep 1 + fi + done +} + +get_client_test_result() { + test_name=3D$1 + should_pass=3D$2 + log=3D"${test_name}.log" + + grep "Initialization Sequence Completed" "${log}" > /dev/null + exit_code=3D$? + + if [ $exit_code -eq 0 ] && [ "${should_pass}" =3D "yes" ]; then + echo "PASS ${test_name}" + elif [ $exit_code -eq 1 ] && [ "${should_pass}" =3D "no" ]; then + echo "PASS ${test_name} (test failure)" + elif [ $exit_code -eq 0 ] && [ "${should_pass}" =3D "no" ]; then + echo "FAIL ${test_name} (test failure)" + cat "${log}" + retval=3D1 + elif [ $exit_code -eq 1 ] && [ "${should_pass}" =3D "yes" ]; then + echo "FAIL ${test_name}" + cat "${log}" + retval=3D1 + 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=3D0 + +# Wait until servers are up. This check is based on the presence of proces= ses +# matching the PIDs in each servers PID files +count=3D0 +server_max_wait=3D15 +while [ $count -lt $server_max_wait ]; do + server_pids=3D"" + server_count=3D$(set|grep 'SERVER_NAME_'|wc -l) + + # We need to trim single-quotes because some shells return quoted valu= es + # and some don't. Using "set -o posix" which would resolve this proble= m is + # not supported in all shells. + for i in `set|grep 'SERVER_NAME_'|cut -d "=3D" -f 2|tr -d "[\']"`; do + server_pid=3D$(cat $i.pid 2> /dev/null) + server_pids=3D"${server_pids} ${server_pid}" + done + + servers_up=3D$(ps -p $server_pids 2>/dev/null|sed '1d'|wc -l) + + echo "OpenVPN test servers up: ${servers_up}/${server_count}" + + if [ $servers_up -ge $server_count ]; then + retval=3D0 + break + else + count=3D$(( count + 1)) + sleep 1 + fi + + if [ $count -eq $server_max_wait ]; then + retval=3D1 + 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=3D"" +for SUF in $TEST_RUN_LIST +do + eval test_name=3D\"\$TEST_NAME_$SUF\" + eval client_exec=3D\"\$CLIENT_EXEC_$SUF\" + eval client_conf=3D\"\$CLIENT_CONF_$SUF\" + + test_names=3D"${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=3D\"\$TEST_NAME_$SUF\" + eval should_pass=3D\"\$SHOULD_PASS_$SUF\" + + (get_client_test_result "${test_name}" "${should_pass}") +done + +exit $retval diff --git a/tests/t_server_null_default.rc b/tests/t_server_null_default.rc new file mode 100755 index 0000000..63b6bcd --- /dev/null +++ b/tests/t_server_null_default.rc @@ -0,0 +1,66 @@ +# Notes regarding --dev null server and client configurations: +# +# The t_server_null_server.sh exits when all client pid files have gone +# missing. That is the most reliable and fastest way to detect client +# disconnections in the "everything runs on localhost" context. Checking s= erver +# status files for client connections works, but introduces long delays as +# --explicit-exit-notify does not seem to work on all client configuration= s. +# This means that, by default, there is about 1 minute delay before the se= rver +# purges clients that have already exited and have not reported back. +# +srcdir=3D"${srcdir:-.}" +top_builddir=3D"${top_builddir:-..}" +sample_keys=3D"${srcdir}/../sample/sample-keys" + +DH=3D"${sample_keys}/dh2048.pem" +CA=3D"${sample_keys}/ca.crt" +CLIENT_CERT=3D"${sample_keys}/client.crt" +CLIENT_KEY=3D"${sample_keys}/client.key" +SERVER_CERT=3D"${sample_keys}/server.crt" +SERVER_KEY=3D"${sample_keys}/server.key" +TA=3D"${sample_keys}/ta.key" + +# Test server configurations +MAX_CLIENTS=3D"10" +CLIENT_MATCH=3D"Test-Client" +SERVER_EXEC=3D"${top_builddir}/src/openvpn/openvpn" +SERVER_BASE_OPTS=3D"--daemon --local 127.0.0.1 --dev tun --topology subnet= --server 10.29.41.0 255.255.255.0 --max-clients $MAX_CLIENTS --persist-tun= --verb 3" +SERVER_CIPHER_OPTS=3D"" +SERVER_CERT_OPTS=3D"--ca ${CA} --dh ${DH} --cert ${SERVER_CERT} --key ${SE= RVER_KEY} --tls-auth ${TA} 0" +SERVER_CONF_BASE=3D"${SERVER_BASE_OPTS} ${SERVER_CIPHER_OPTS} ${SERVER_CER= T_OPTS}" + +TEST_SERVER_LIST=3D"1 2" + +SERVER_NAME_1=3D"t_server_null_server-1194_udp" +SERVER_MGMT_PORT_1=3D"11194" +SERVER_EXEC_1=3D"${SERVER_EXEC}" +SERVER_CONF_1=3D"${SERVER_CONF_BASE} --lport 1194 --proto udp --management= 127.0.0.1 ${SERVER_MGMT_PORT_1}" + +SERVER_NAME_2=3D"t_server_null_server-1195_tcp" +SERVER_MGMT_PORT_2=3D"11195" +SERVER_EXEC_2=3D"${SERVER_EXEC}" +SERVER_CONF_2=3D"${SERVER_CONF_BASE} --lport 1195 --proto tcp --management= 127.0.0.1 ${SERVER_MGMT_PORT_2}" + +# Test client configurations +CLIENT_EXEC=3D"${top_builddir}/src/openvpn/openvpn" +CLIENT_BASE_OPTS=3D"--client --dev null --ifconfig-noexec --nobind --remot= e-cert-tls server --persist-tun --verb 3 --resolv-retry infinite --connect-= retry-max 3 --server-poll-timeout 5 --explicit-exit-notify 3 --script-secur= ity 2 --up ${srcdir}/null_client_up.sh" +CLIENT_CIPHER_OPTS=3D"" +CLIENT_CERT_OPTS=3D"--ca ${CA} --cert ${CLIENT_CERT} --key ${CLIENT_KEY} -= -tls-auth ${TA} 1" + +TEST_RUN_LIST=3D"1 2 3" +CLIENT_CONF_BASE=3D"${CLIENT_BASE_OPTS} ${CLIENT_CIPHER_OPTS} ${CLIENT_CER= T_OPTS}" + +TEST_NAME_1=3D"t_server_null_client.sh-openvpn_current_udp" +SHOULD_PASS_1=3D"yes" +CLIENT_EXEC_1=3D"${CLIENT_EXEC}" +CLIENT_CONF_1=3D"${CLIENT_CONF_BASE} --remote 127.0.0.1 1194 udp --proto u= dp" + +TEST_NAME_2=3D"t_server_null_client.sh-openvpn_current_tcp" +SHOULD_PASS_2=3D"yes" +CLIENT_EXEC_2=3D"${CLIENT_EXEC}" +CLIENT_CONF_2=3D"${CLIENT_CONF_BASE} --remote 127.0.0.1 1195 tcp --proto t= cp" + +TEST_NAME_3=3D"t_server_null_client.sh-openvpn_current_udp_fail" +SHOULD_PASS_3=3D"no" +CLIENT_EXEC_3=3D"${CLIENT_EXEC}" +CLIENT_CONF_3=3D"${CLIENT_CONF_BASE} --remote 127.0.0.1 11194 udp --proto = udp" diff --git a/tests/t_server_null_server.sh b/tests/t_server_null_server.sh new file mode 100755 index 0000000..9bc0c88 --- /dev/null +++ b/tests/t_server_null_server.sh @@ -0,0 +1,78 @@ +#!/usr/bin/env sh + +launch_server() { + server_name=3D$1 + server_exec=3D$2 + server_conf=3D$3 + log=3D"${server_name}.log" + status=3D"${server_name}.status" + pid=3D"${server_name}.pid" + + # Ensure that old status, log and pid files are gone + rm -f "${status}" "${log}" "${pid}" + + "${server_exec}" \ + $server_conf \ + --status "${status}" 1 \ + --log "${log}" \ + --writepid "${pid}" \ + --explicit-exit-notify 3 + +} + +# Load base/default configuration +. "${srcdir}/t_server_null_default.rc" || exit 1 + +# Load local configuration, if any +test -r ./t_server_null.rc && . ./t_server_null.rc + +# Launch test servers +for SUF in $TEST_SERVER_LIST +do + eval server_name=3D\"\$SERVER_NAME_$SUF\" + eval server_exec=3D\"\$SERVER_EXEC_$SUF\" + eval server_conf=3D\"\$SERVER_CONF_$SUF\" + + (launch_server "${server_name}" "${server_exec}" "${server_conf}") +done + +# Create a list of server pid files so that servers can be killed at the e= nd of +# the test run. +# +export server_pid_files=3D"" +for SUF in $TEST_SERVER_LIST +do + eval server_name=3D\"\$SERVER_NAME_$SUF\" + server_pid_files=3D"${server_pid_files} ./${server_name}.pid" +done + +# Wait until clients are no more, based on the presence of their pid files. +# Based on practical testing we have to wait at least four seconds to avoid +# accidentally exiting too early. +count=3D0 +maxcount=3D4 +while [ $count -le $maxcount ]; do + if ls t_server_null_client.sh*.pid > /dev/null 2>&1 + then + count=3D0 + sleep 1 + else + count=3D$(( count + 1)) + sleep 1 + fi +done + +echo "All clients have disconnected from all servers" + +for PID_FILE in $server_pid_files +do + SERVER_PID=3D$(cat "${PID_FILE}") + $KILL_EXEC "${SERVER_PID}" + + # Make sure that the server processes are truly dead before exiting + while : + do + ps -p "${SERVER_PID}" > /dev/null || break + sleep 0.2 + done +done diff --git a/tests/t_server_null_stress.sh b/tests/t_server_null_stress.sh new file mode 100755 index 0000000..1281397 --- /dev/null +++ b/tests/t_server_null_stress.sh @@ -0,0 +1,33 @@ +#!/usr/bin/env sh +# +# Run this stress test as root to avoid sudo authorization from timing out. + +ITERATIONS=3D"${1:-100}" + +. ./t_server_null_default.rc + +export pid_files=3D"" +for SUF in $TEST_SERVER_LIST +do + eval server_name=3D\"\$SERVER_NAME_$SUF\" + pid_files=3D"${pid_files} ./${server_name}.pid" +done + +LOG_BASEDIR=3D"make-check" +mkdir -p "${LOG_BASEDIR}" + +count=3D0 +while [ $count -lt $ITERATIONS ]; do + count=3D$(( count + 1 )) + make check TESTS=3Dt_server_null.sh SUBDIRS=3D > /dev/null 2>&1 + retval=3D$? + + echo "Iteration ${count}: return value ${retval}" >> "${LOG_BASEDIR}/m= ake-check.log" + if [ $retval -ne 0 ]; then + DIR=3D"${LOG_BASEDIR}/make-check-${count}" + mkdir -p "${DIR}" + cp t_server_null*.log "${DIR}/" + cp test-suite.log "${DIR}/" + ps aux|grep openvpn|grep -vE '(suppress|grep)' > "${DIR}/psaux" + fi +done -- To view, visit http://gerrit.openvpn.net/c/openvpn/+/663?usp=3Demail To unsubscribe, or for help writing mail filters, visit http://gerrit.openv= pn.net/settings Gerrit-Project: openvpn Gerrit-Branch: master Gerrit-Change-Id: I1b54da258c7d15551b6c3de7522a0d19afdb66de Gerrit-Change-Number: 663 Gerrit-PatchSet: 2 Gerrit-Owner: mattock Gerrit-Reviewer: flichtenheld Gerrit-Reviewer: plaisthos Gerrit-CC: openvpn-devel Gerrit-Attention: plaisthos Gerrit-Attention: mattock Gerrit-MessageType: newpatchset --ErG8nJVqCTQ= Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable

Attention is currently required from: mattock, plaisthos.

mattock uploaded patch set #2 to this change.

View Change<= /a>

Add t_server_null test suite

Change-Id: I1b54da258c7d15551b6c3de= 7522a0d19afdb66de
Signed-off-by: Samuli Sepp=C3=A4nen <samuli.seppane= n@...277...>
---
M .gitignore
A doc/t_server_null.rst
M test= s/Makefile.am
A tests/null_client_up.sh
A tests/t_server_null.rc-samp= le
A tests/t_server_null.sh
A tests/t_server_null_client.sh
A test= s/t_server_null_default.rc
A tests/t_server_null_server.sh
A tests/t_= server_null_stress.sh
10 files changed, 568 insertions(+), 2 deletions(-= )

git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/63=
/663/2
diff --git a/.gitignore b/.gitignore
index 9= 2d65bf..db8bb73 100644
--- a/.gitignore
+++= b/.gitignore
@@ -55,6 +55,7 @@
tests/t_client.sh
tests/t_client-*-20??????-??????= /
+tests/t_server_nul= l.rc
t_client.rc
t_client_ips.rc tests/unit_tests/**/*_testdriver
diff --git a/doc/= t_server_null.rst b/doc/t_server_null.rst
new file mode 100= 644
index 0000000..e3a098a
--- /dev/null
+++ b/doc/t_server_null.rst
@@ -0,0 +1,147 @@=
+Notes for the --dev= null test suite
+=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D
+
+Introductio= n
+------------
+
+The *--dev null test suite* is primary targe= ted at testing client connections
+to the "just compiled" version of OpenVPN. The name= is derived from "null"
+device type in OpenVPN. In particular, when *--dev null --ifc= onfig-noexec* is
+use= d in OpenVPN client configuration one does not need to run OpenVPN with roo= t
+privileges because= interface, routing, etc. configuration is not done at all.
+This is still enough to ensure that= the OpenVPN client can connect to a server

+instance.
+
+The m= ain features of the test suite:
+
+* Paral= lelized for fairly high performance
+* Mostly operating-system agnostic
+* Tested on Fedora Linux 38/39/40 and FreeBS= D 14
+* POSIX-complia= nt
+* Tested and know= n to work with Bash, Dash, Ksh, Yash and FreeBSD's default /bin/sh
+* Uses the sample certif= icates and keys
+* Su= pports running multiple servers and clients
+* Supports running servers directly as root and wit= h sudo
+* Supports us= ing different OpenVPN client versions
+
+ = * The "current" (just compiled) version
+ * Any other OpenVPN versions that is prese= nt on the filesystem
= +
+* Support testing = for success as well as failure
+* Test cases (client configurations) and server setups (server c= onfigurations) are stored in a configuration file, i.e. data and code have = been separated
+* Con= figuration file format is nearly identical to t_client.rc configuration
+* Supports a set of def= ault tests, overriding default test settings and adding local tests<= br>+
+Prerequisites
+-------------
+
+Ru= nning the test suite requires the following:
+
+* *bash* for running the tests
+* root-level privileges for launching the servers+
+ * run as root
+ * a privilege escalation tool (sudo, doas, su) an= d the permission to become root
+
+Technic= al implementation
+--= ----------------------
+The test suite i= s completely parallelized to allow running a large number of
+server and client combinations qui= ckly.

+
+A normal test run looks like this= :

+
+#. Server instances start
<= span style=3D"color: hsl(120, 100%, 40%);">+#. Brief wait

+#. Client instances start
<= span style=3D"color: hsl(120, 100%, 40%);">+#. Tests run
+#. Client instances stop
+#. Brief wait
+#. Server instances stop
+
+The tests suite is launched via "make check"= ;:
+
+* make check
+
+ * t_server_null.sh
+
+ = * t_server_null_server.sh
+
+ * Laun= ches the compiled OpenVPN server instances as root (if necessary with sudo = or su) in the background. The servers are killed using their management int= erface once all clients have exited.
+
+ = * t_server_null_client.sh
+
+ * Wai= ts until servers have launched. Then launch all clients, wait for them to e= xit and then check test results by parsing the client log files. Each clien= t kills itself after some delay using an "--up" script.+
+Note that "make check" moves on once *= t_server_null_client.sh* has exited. At
+that point *t_server_null_server.sh* is still running, = because it exists only
+This is a fea= ture and not a bug, but means that launching "make check" runs to= o
+quickly might caus= e test failures or unexpected behavior such as leftover
+OpenVPN server processes.
+
+Configuration
+-------------
+
+The test= suite reads its configuration from two files:
+
+* *tests/t_server_null_defaults.rc:* default test configuration tha= t should work on any system
+* *tests/t_server_null.rc:* a local configuration file; can be used= to add additional tests or override settings from the default test configu= ration. Must be present or tests will be skipped, but can be an empty file.=
+
+The configuration syntax is very simil= ar to *t_client.rc*. New server instances can be
+defined like this::
+
+ SERVER_NAME_5=3D"t_server_null_server-11195_udp"

+ SERVER_MGMT_PORT_5=3D&= quot;11195"
+ S= ERVER_EXEC_5=3D"${SERVER_EXEC}"
+ SERVER_CONF_5=3D"${SERVER_CONF_BASE} --lport 1= 1195 --proto udp --management 127.0.0.1 ${SERVER_MGMT_PORT_5}"<= br>+
+In this case the server instance identifier is= **5**. Variables such as
+*SERVER_EXEC* and *SERVER_CONF_BASE* are defined in
+*t_server_null_defaults.rc*. To enabl= e this server instance add it to the
+server list::
+
+ TEST_S= ERVER_LIST=3D"1 2 5"
+
+The clie= nt instances are added similarly::
+
+ TE= ST_NAME_9=3D"t_server_null_client.sh-openvpn_current_udp_custom"<= /span>
+ SHOULD_PASS_9=3D&q= uot;yes"
+ CLIE= NT_EXEC_9=3D"${CLIENT_EXEC}"
+ CLIENT_CONF_9=3D"${CLIENT_CONF_BASE} --remote 127= .0.0.1 1194 udp --proto udp"
+
+In th= is case the test identifier is **9**. *CLIENT_EXEC* and *CLIENT_CONF_BASE*<= /span>
+are defined in *t_se= rver_null_defaults.rc*. The variable *SHOULD_PASS*
+determines that this particular test is supp= osed to succeed and not fail. To
+enable this client instance add it to the test list::<= br>+
+ TEST_RUN_LIST=3D"1 2 5 9"+
+Stress-testing the --dev null test suite=
+--------------------------= --------------
+
+It is very easy to intro= duce subtle, difficult to debug issues to the --dev
+null tests when you make changes to it. T= hese issues can be difficult to spot:
+based on practical experience a bad change can make the t= est failure rate go
+= from 0% (normal) to anywhere between 1% and 20%. You can spot these issues = with
+the provided st= ress-test script, *t_server_null_stress.sh*. It calls *make check*+over and over again in a loo= p and when failures occur it saves the output under
+*tests/make-check*.
+
+To follow the test flow on Linux you can run this while stre= ss-testing::
+=
+ watch -n 0.5 "ps = aux|grep -E '(openvpn|t_server_null_server.sh)'|grep -vE '(supp= ress|grep|tail)'"
+
+Regarding pr= ivilege escalation
+-= -----------------------------
+
+The --dev= null test servers need to be launched as root. Either run the tests=
+as root directly, or confi= gure a privilege escalation tool of your choice in
+*t_server_null.rc*. For example, to use sudo= ::
+
+ SUDO_EXEC=3D`which sudo`<= br>+ RUN_SUDO=3D"${SUDO= _EXEC} -E"
+

+If you do stress-testin= g with *t_server_null_stress.sh* make sure your
+privilege escalation authorization does not tim= e out: if it does, then a
+reauthorization prompt will interrupt your tests.
dif= f --git a/tests/Makefile.am b/tests/Makefile.am
index 5e9ad= 0a..f26b3b8 100644
--- a/tests/Makefile.am
= +++ b/tests/Makefile.am
@@ -15,10 +15,10 @@
SUBDIRS =3D unit_tests

AM_TESTSUITE_SU= MMARY_HEADER =3D ' for $(PACKAGE_STRING) System Tests'
-LOG_DRIVER =3D $(SHELL) $(top_srcd= ir)/forked-test-driver
-test_scripts =3D t_client.sh t_lpback.sh t_cltsrv.sh
<= span style=3D"color: hsl(120, 100%, 40%);">+test_scripts =3D t_client.sh t_= lpback.sh t_cltsrv.sh t_server_null.sh

c= heck_PROGRAMS =3D ntlm_support
if HAVE_SITNL
@@ -27,6 +27,7 @@
endif

TESTS_ENVIRONMENT =3D top_srcdir=3D"$(top_srcdir)"
= +TEST_EXTENSIONS =3D .sh=
TESTS =3D $(test_scripts)

dis= t_noinst_SCRIPTS =3D \
@@ -34,8 +35,14 @@
= t_cltsrv-down.sh \
t_lpback.sh \
t_net= .sh \
+ t_server_null= .sh \
+ t_server_null= _client.sh \
+ t_serv= er_null_server.sh \
+= t_server_null_default.rc \
update_t_client_ips.sh=

+t_client= .log: t_server_null.log
+
dist_noinst_DATA =3D \
t_client.rc-= sample

diff --git a/tests/null_client_up.= sh b/tests/null_client_up.sh
new file mode 100755index 0000000..d4df0c6
--- /dev/null
+++ b/tests/null_client_up.sh
@@ -0,0 +1,11 @@
<= span style=3D"color: hsl(120, 100%, 40%);">+#!/bin/sh
+#
+# Stop the parent process (openvpn) gracefully after a smal= l delay
+
<= span style=3D"color: hsl(120, 100%, 40%);">+# Determine the OpenVPN PID fro= m its pid file. This works reliably even when
+# the OpenVPN process is backgrounded for paralle= l tests.
+MY_PPID=3D`= cat $pid`
++# Allow OpenVPN to finish ini= tializing while waiting in the background and then
+# killing the process gracefully.
= +(sleep 5 ; kill -15 $MY_PPID) = &
diff --git a/tests/t_server_null.rc-sample b/tests/t_= server_null.rc-sample
new file mode 100644
= index 0000000..28c3773
--- /dev/null
+++ b/= tests/t_server_null.rc-sample
@@ -0,0 +1,15 @@
+# Uncomment to run tests with su= do
+#SUDO_EXEC=3D`whi= ch sudo`
+#RUN_SUDO= =3D"${SUDO_EXEC} -E"
+
+TEST_RUN= _LIST=3D"1 2 3 10 11"
+
+TEST_NA= ME_10=3D"t_server_null_client.sh-openvpn_2_6_8_udp"
+SHOULD_PASS_10=3D"yes"<= /span>
+CLIENT_EXEC_10=3D&qu= ot;/usr/sbin/openvpn"
+CLIENT_CONF_10=3D"${CLIENT_CONF_BASE} --remote 127.0.0.1 1194 u= dp --proto udp"
= +
+TEST_NAME_11=3D&qu= ot;t_server_null_client.sh-openvpn_2_6_8_tcp"
+SHOULD_PASS_11=3D"yes"
<= span style=3D"color: hsl(120, 100%, 40%);">+CLIENT_EXEC_11=3D"/usr/sbi= n/openvpn"
+CLIE= NT_CONF_11=3D"${CLIENT_CONF_BASE} --remote 127.0.0.1 1195 tcp --proto = tcp"
diff --git a/tests/t_server_null.sh b/tests/t_ser= ver_null.sh
new file mode 100755
index 0000= 000..cfca5ee
--- /dev/null
+++ b/tests/t_se= rver_null.sh
@@ -0,0 +1,72 @@
+#!/usr/bin/env sh
+#
+TSERVER_NULL_SKIP_RC=3D"${TSERVER_NULL_SKIP_RC:-77}"=
+
+if ! [ -r "./t_server_null.rc" ] ; = then
+ echo "= ${0}: cannot find './t_server_null.rc. SKIPPING TEST.'" >&a= mp;2
+ exit "= ${TSERVER_NULL_SKIP_RC}"
+fi
+=
+. ./t_server_null.rc

+
+if KILL_EXEC=3D$(which kill); then+ export KILL_EXEC+else
+ echo "${0}: kill not found in \$= PATH" >&2
+ exit "${TSERVER_NULL_SKIP_RC}"
+fi
+
+# Ensure = PREFER_KSU is in a known state
+PREFER_KSU=3D"${PREFER_KSU:-0}"
+
+# make sure we have permissions to run ifconfig/route from O= penVPN
+# can't u= se "id -u" here - doesn't work on Solaris
+ID=3D$(id)
+if expr "$ID" : "uid=3D0" &g= t;/dev/null
+then :
+else
+ if [ "${PREFER_KSU}" -= eq 1 ];
+ then

+ # Check if we h= ave a valid kerberos ticket
+ if klist -l 1>/dev/null 2>/dev/null; then
<= span style=3D"color: hsl(120, 100%, 40%);">+ RUN_SUDO=3D"ks= u -q -e"
+ = else
+ #= No kerberos ticket found, skip ksu and fallback to RUN_SUDO
+ PREFER_KSU=3D0<= br>+ echo "${0}= : No Kerberos ticket available. Will not use ksu."
+ fi
+ fi
+
+ = if [ -z "$RUN_SUDO" ]
+ then
= + echo "${0}: this test must run be as root, or RUN_SUDO=3D... = " >&2
+ = echo " must be set correctly in 't_server_null.rc'.= SKIP." >&2
+ exit "${TSERVER_NULL_SKIP_RC}"
+ else
+ # Run a no-op command with privilege escalation (e.= g. sudo) so that
+ # = we (hopefully) do not have to ask the users password during the test.

+ if $RUN_SUDO "${KIL= L_EXEC}" -0 $$
+= then
+ echo &quo= t;${0}: $RUN_SUDO $KILL_EXEC -0 succeeded, good."
+ else
+ echo "${0}: $RUN_SUDO $KILL_EXEC -0 failed, = cannot go on. SKIP." >&2
+ exit "${TSERVER_NULL_SKIP_RC}"
+ fi
+ fi
+fi
+

+srcdir=3D"${srcdi= r:-.}"
+<= br>+if [ -z "${RUN_SUDO}&q= uot; ]; then
+ &qu= ot;${srcdir}/t_server_null_server.sh" &
+else
+ $RUN_SUDO "${srcdir}/t_server_null_server.sh" &= amp;
+fi
+
+"${srcdir}/t_server_null_client.sh"
+
+# When running make jobs in parallel ("= make -j<x> check") we need to ensure
+# that this script does not exit before all --d= ev null servers are dead and
+# their network interfaces are gone. Otherwise t_client.sh will fa= il because
+# pre and= post ifconfig output does not match.
+wait
diff --git a/tests/t_server_null_cli= ent.sh b/tests/t_server_null_client.sh
new file mode 100755=
index 0000000..5d5542b
--- /dev/null
+++ b/tests/t_server_null_client.sh
@@ -0,0 +1,1= 36 @@
+#!/usr/bin/env= sh
+
+launch_client() {

+ test_name=3D$1
+ log=3D"${test_name}.log"=
+ pid=3D"${t= est_name}.pid"
+= client_exec=3D$2
= + client_conf=3D$3
+
+ # Ensure that= old log and pid files are gone
+ rm -f "${log}" "${pid}"
+

+ "${client_exec}" \
+ $client_conf \
+ --writepid "${pid}" = \
+ --setenv p= id $pid \
+ --= log "${log}" &
+}
++wait_for_results() {<= br>+ tests_running=3D"y= es"
+
= + # Wait a bit to allow an O= penVPN client process to create a pidfile to
+ # prevent exiting too early
+ sleep 1
+
+ while [ "${tests_running}" =3D "yes" ]; d= o
+ tests_runn= ing=3D"no"
= + for t in $test_names; do
+ if [ -f "${t}.pid" ]; then
+ tests_running=3D= "yes"
+ = fi
+ d= one
+
+ if [ "${tests_running}= " =3D "yes" ]; then
+ echo "Clients still running"+ sleep 1+ fi
+ done
+}
+
+get_client_= test_result() {
+ = test_name=3D$1
+ s= hould_pass=3D$2
+ = log=3D"${test_name}.log"
+
+ = grep "Initialization Sequence Completed" "${log}" > = /dev/null
+ exit_c= ode=3D$?
+
= + if [ $exit_code -eq 0 ] &a= mp;& [ "${should_pass}" =3D "yes" ]; then+ echo "PASS ${tes= t_name}"
+ el= if [ $exit_code -eq 1 ] && [ "${should_pass}" =3D "n= o" ]; then
+ = echo "PASS ${test_name} (test failure)"
+ elif [ $exit_code -eq 0 ] && = [ "${should_pass}" =3D "no" ]; then
+ echo "FAIL ${test_name} (t= est failure)"
+ = cat "${log}"
+ retval=3D1
+ elif [ $exit_code -eq 1 ] && [ "${should_pass}&qu= ot; =3D "yes" ]; then
+ echo "FAIL ${test_name}"
+ cat "${log}"+ retval=3D1
= + fi
+}
+
+# L= oad basic/default tests
+. ${srcdir}/t_server_null_default.rc || exit 1
+
+# Load additional local tests, if any
+test -r ./t_server_null.rc && . ./t_s= erver_null.rc
+

+# Return value for the en= tire test suite. Gets set to 1 if any test fails.
+export retval=3D0
+
+# Wait until servers are up. This check is based on the presence o= f processes
+# matchi= ng the PIDs in each servers PID files
+count=3D0
+server_max_wait=3D15
+while [ $count -lt $server_max_wait ]; do
+ server_pids=3D""
+ server_count=3D$(set|grep = 9;SERVER_NAME_'|wc -l)
+
+ # We nee= d to trim single-quotes because some shells return quoted values
= + # and some don't. Usin= g "set -o posix" which would resolve this problem is
+ # not supported in all shell= s.
+ for i in `set= |grep 'SERVER_NAME_'|cut -d "=3D" -f 2|tr -d "[\'= ;]"`; do
+ = server_pid=3D$(cat $i.pid 2> /dev/null)
+ server_pids=3D"${server_pids} ${serve= r_pid}"
+ don= e
+
+ servers_up=3D$(ps -p $server_pids= 2>/dev/null|sed '1d'|wc -l)
+
= + echo "OpenVPN test servers up: ${servers_up}/${server_count}"= ;
+
+ if [ $servers_up -ge $server_coun= t ]; then
+ re= tval=3D0
+ bre= ak
+ else+ count=3D$(( count + = 1))
+ sleep 1<= /span>
+ fi
+

+ if [ $count -eq $server_max_wait ]; then<= br>+ retval=3D1+ fi
+done
+
+= # Wait a while to let server processes to settle down
+sleep 1
+
+# is used la= ter to determine when all OpenVPN clients have exited and it is
<= span style=3D"color: hsl(120, 100%, 40%);">+# safe to check the test result= s.
+test_names=3D&quo= t;"
+for SUF in = $TEST_RUN_LIST
+do

+ eval test_name=3D\= "\$TEST_NAME_$SUF\"
+ eval client_exec=3D\"\$CLIENT_EXEC_$SUF\"+ eval client_conf=3D\"= ;\$CLIENT_CONF_$SUF\"
+
+ test_nam= es=3D"${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 te= st_name=3D\"\$TEST_NAME_$SUF\"
+ eval should_pass=3D\"\$SHOULD_PASS_$SUF\"= ;
+
+ (get_client_test_result "${t= est_name}" "${should_pass}")
+done
+
+exit $retv= al
diff --git a/tests/t_server_null_default.rc b/tests/t_se= rver_null_default.rc
new file mode 100755
i= ndex 0000000..63b6bcd
--- /dev/null
+++ b/t= ests/t_server_null_default.rc
@@ -0,0 +1,66 @@
+# Notes regarding --dev null ser= ver and client configurations:
+#
+# The t= _server_null_server.sh exits when all client pid files have gone
= +# missing. That is the most re= liable and fastest way to detect client
+# disconnections in the "everything runs on localh= ost" context. Checking server
+# status files for client connections works, but introduces = long delays as
+# --e= xplicit-exit-notify does not seem to work on all client configurations.

+# This means that, by d= efault, there is about 1 minute delay before the server
+# purges clients that have already exit= ed and have not reported back.
+#
+srcdir= =3D"${srcdir:-.}"
+top_builddir=3D"${top_builddir:-..}"
+sample_keys=3D"${srcdir}/../sample/= sample-keys"
+
+DH=3D"${sample_k= eys}/dh2048.pem"
+CA=3D"${sample_keys}/ca.crt"
+CLIENT_CERT=3D"${sample_keys}/client.crt"

+CLIENT_KEY=3D"${s= ample_keys}/client.key"
+SERVER_CERT=3D"${sample_keys}/server.crt"
+SERVER_KEY=3D"${sample_keys}/= server.key"
+TA= =3D"${sample_keys}/ta.key"
+
+# = Test server configurations
+MAX_CLIENTS=3D"10"
+CLIENT_MATCH=3D"Test-Client"
+SERVER_EXEC=3D"${top_builddir}/src/= openvpn/openvpn"
+SERVER_BASE_OPTS=3D"--daemon --local 127.0.0.1 --dev tun --topology = subnet --server 10.29.41.0 255.255.255.0 --max-clients $MAX_CLIENTS --persi= st-tun --verb 3"
+SERVER_CIPHER_OPTS=3D""
+SERVER_CERT_OPTS=3D"--ca ${CA} --dh ${DH} --cert ${SER= VER_CERT} --key ${SERVER_KEY} --tls-auth ${TA} 0"
+SERVER_CONF_BASE=3D"${SERVER_BASE_O= PTS} ${SERVER_CIPHER_OPTS} ${SERVER_CERT_OPTS}"
+
+TEST_SERVER_LIST=3D"1 2"
+
+SERVER_NAME_1=3D"t_server_null_server-1194_udp"=
+SERVER_MGMT_PORT_1=3D"= ;11194"
+SERVER_= EXEC_1=3D"${SERVER_EXEC}"
+SERVER_CONF_1=3D"${SERVER_CONF_BASE} --lport 1194 --pr= oto udp --management 127.0.0.1 ${SERVER_MGMT_PORT_1}"
+
+SERVER_NAME_2=3D"t_server_null_server-1195_tcp&quo= t;
+SERVER_MGMT_PORT_= 2=3D"11195"
+SERVER_EXEC_2=3D"${SERVER_EXEC}"
+SERVER_CONF_2=3D"${SERVER_CONF_BASE} --lport = 1195 --proto tcp --management 127.0.0.1 ${SERVER_MGMT_PORT_2}"<= br>+
+# Test client configurations
+CLIENT_EXEC=3D"${top_builddir}/s= rc/openvpn/openvpn"
+CLIENT_BASE_OPTS=3D"--client --dev null --ifconfig-noexec --nobin= d --remote-cert-tls server --persist-tun --verb 3 --resolv-retry infinite -= -connect-retry-max 3 --server-poll-timeout 5 --explicit-exit-notify 3 --scr= ipt-security 2 --up ${srcdir}/null_client_up.sh"
+CLIENT_CIPHER_OPTS=3D""<= br>+CLIENT_CERT_OPTS=3D"--= ca ${CA} --cert ${CLIENT_CERT} --key ${CLIENT_KEY} --tls-auth ${TA} 1"=
+
+TEST_RUN_LIST=3D"1 2 3"

+CLIENT_CONF_BASE=3D"= ;${CLIENT_BASE_OPTS} ${CLIENT_CIPHER_OPTS} ${CLIENT_CERT_OPTS}"=
+
+TEST_NAME_1=3D"t_server_null_client.sh-o= penvpn_current_udp"
+SHOULD_PASS_1=3D"yes"
+CLIENT_EXEC_1=3D"${CLIENT_EXEC}"
+CLIENT_CONF_1=3D"${CLIENT_CONF= _BASE} --remote 127.0.0.1 1194 udp --proto udp"
+
+TEST_NAME_2=3D"t_server_null_client.sh-openvpn_current_= tcp"
+SHOULD_PAS= S_2=3D"yes"
+CLIENT_EXEC_2=3D"${CLIENT_EXEC}"
+CLIENT_CONF_2=3D"${CLIENT_CONF_BASE} --remote= 127.0.0.1 1195 tcp --proto tcp"
+
+T= EST_NAME_3=3D"t_server_null_client.sh-openvpn_current_udp_fail"
+SHOULD_PASS_3=3D"= ;no"
+CLIENT_EXE= C_3=3D"${CLIENT_EXEC}"
+CLIENT_CONF_3=3D"${CLIENT_CONF_BASE} --remote 127.0.0.1 1= 1194 udp --proto udp"
diff --git a/tests/t_server_null= _server.sh b/tests/t_server_null_server.sh
new file mode 10= 0755
index 0000000..9bc0c88
--- /dev/null
+++ b/tests/t_server_null_server.sh
@@ -0,0 = +1,78 @@
+#!/usr/bin/= env sh
+
+launch_server() {

+ server_name=3D$1

+ server_exec=3D$2
+ server_conf=3D$3
<= span style=3D"color: hsl(120, 100%, 40%);">+ log=3D"${server_name}.= log"
+ status= =3D"${server_name}.status"
+ pid=3D"${server_name}.pid"
+
+ # Ensure that old status, log and pid files are gone=
+ rm -f "${s= tatus}" "${log}" "${pid}"
+
+ "${server_exec}" \
+ $server_conf \
+ --status "${status}" 1 \
+ --log "${lo= g}" \
+ -= -writepid "${pid}" \
+ --explicit-exit-notify 3
+
+}
+
+# Load base/default configuratio= n

+. "${srcdir}/= t_server_null_default.rc" || exit 1
+
+# Load local configuration, if any
+test -r ./t_server_null.rc && . ./t_server_null.rc=
+
+# Launch test servers
+for SUF in $TEST_SERVER_LIST<= br>+do
+ eval server_name=3D\"\$SERVER_NAME_= $SUF\"
+ eval= server_exec=3D\"\$SERVER_EXEC_$SUF\"
+ eval server_conf=3D\"\$SERVER_CONF_$SU= F\"
+
= + (launch_server "${ser= ver_name}" "${server_exec}" "${server_conf}")
+done
+
+# Create a list of server pid files so that servers can be= killed at the end of
+# the test run.
+#<= /span>
+export server_pid_fi= les=3D""
+f= or SUF in $TEST_SERVER_LIST
+do
+ eval = server_name=3D\"\$SERVER_NAME_$SUF\"
+ server_pid_files=3D"${server_pid_files}= ./${server_name}.pid"
+done
+=
+# Wait until clients are n= o more, based on the presence of their pid files.
+# Based on practical testing we have to wait = at least four seconds to avoid
+# accidentally exiting too early.
+count=3D0
+maxcount=3D4
+while [ $count -le $maxcount ]; do
+ if ls t_server_null_client.sh*.pid > /dev/nul= l 2>&1
+ th= en
+ count=3D0=
+ sleep 1

+ else
+ count=3D$(( count + 1))+ sleep 1
+ fi
+done
+
+echo = "All clients have disconnected from all servers"
+
+for PID_FILE in $server_pid_files
+do
+ SERVER_PID=3D$(cat "${PID_FILE}")
= + $KILL_EXEC "${SERVER_= PID}"
++ # Make sure that the ser= ver processes are truly dead before exiting
+ while :
+ do
+ sleep 0.2
= + done
+done
diff --git a/tests/t= _server_null_stress.sh b/tests/t_server_null_stress.sh
new = file mode 100755
index 0000000..1281397
---= /dev/null
+++ b/tests/t_server_null_stress.sh
@@ -0,0 +1,33 @@
= +#!/usr/bin/env sh
+#=
+# Run this stress t= est as root to avoid sudo authorization from timing out.
+
+ITERATIONS=3D"${1:-100}"
+
+. ./t_server_null_default.rc
+
+export pid_files=3D""
+for SUF in $TEST_SERVER_LIST
+do
+ eval server_name=3D\"\$SERVER_NAME_$SUF\"
= + pid_files=3D"${pid_fi= les} ./${server_name}.pid"
+done
+

+LOG_BASEDIR=3D"ma= ke-check"
+mkdir= -p "${LOG_BASEDIR}"
+
+count=3D= 0
+while [ $count -lt= $ITERATIONS ]; do
+ = count=3D$(( count + 1 ))
+ make check TESTS=3Dt_server_null.sh SUBDIRS=3D > /dev/null 2= >&1
+ retva= l=3D$?
+
+ echo "Iteration ${count= }: return value ${retval}" >> "${LOG_BASEDIR}/make-check.lo= g"
+ if [ $re= tval -ne 0 ]; then
+ = DIR=3D"${LOG_BASEDIR}/make-check-${count}"
+ mkdir -p "${DIR}"

+ cp t_server_null*= .log "${DIR}/"
+ cp test-suite.log "${DIR}/"
+ ps aux|grep openvpn|grep -vE '(s= uppress|grep)' > "${DIR}/psaux"
+ fi
+done

To view, visit change 663. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I1b54da258c7d15551b6c3de7522= a0d19afdb66de
Gerrit-Change-Number: 663
Gerrit-PatchSet: 2
Gerrit-Owner: mattock <samuli@...515...>=
Gerrit-Reviewer: flichtenheld <frank@...2716...= 1...>
Gerrit-Reviewer: plaisthos <arne-openvpn@...1186...= .1227...>
Gerrit-CC: openvpn-devel <openvpn-devel@...1484...= ts.sourceforge.net>
Gerrit-Attention: plaisthos <arne-openvpn@...220...= ..1227...>
Gerrit-Attention: mattock <samuli@...515...= >
Gerrit-MessageType: newpatchset
--ErG8nJVqCTQ=--