From 2bc5c80c603c785018ff82e62feba37fd14866e4 Mon Sep 17 00:00:00 2001 From: Gilles Peskine Date: Wed, 4 Sep 2024 16:05:11 +0200 Subject: [PATCH] Allow test cases to use a specific port This is necessary for the SSL sample programs: they hard-code port 4433. Signed-off-by: Gilles Peskine --- tests/ssl-opt.sh | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/tests/ssl-opt.sh b/tests/ssl-opt.sh index 6f5996309c..364f5817e3 100755 --- a/tests/ssl-opt.sh +++ b/tests/ssl-opt.sh @@ -1410,7 +1410,16 @@ analyze_test_commands() { if [ -n "$PXY_CMD" ]; then CLI_CMD=$( echo "$CLI_CMD" | sed s/+SRV_PORT/$PXY_PORT/g ) else - CLI_CMD=$( echo "$CLI_CMD" | sed s/+SRV_PORT/$SRV_PORT/g ) + CLI_CMD=$( echo "$CLI_CMD" | sed s/+SRV_PORT/$THIS_SRV_PORT/g ) + fi + + # If the test forces a specific port and the server is OpenSSL or + # GnuTLS, override its port specification. + if [ "$THIS_SRV_PORT" != "$SRV_PORT" ]; then + case "$SRV_CMD" in + "$G_SRV"*|"$G_NEXT_SRV"*) SRV_CMD="$SRV_CMD -p $THIS_SRV_PORT";; + "$O_SRV"*|"$O_NEXT_SRV"*) SRV_CMD="$SRV_CMD -accept $THIS_SRV_PORT";; + esac fi # prepend valgrind to our commands if active @@ -1609,7 +1618,7 @@ do_run_test_once() { printf '# %s\n%s\n' "$NAME" "$SRV_CMD" > $SRV_OUT provide_input | $SRV_CMD >> $SRV_OUT 2>&1 & SRV_PID=$! - wait_server_start "$SRV_PORT" "$SRV_PID" + wait_server_start "$THIS_SRV_PORT" "$SRV_PID" printf '# %s\n%s\n' "$NAME" "$CLI_CMD" > $CLI_OUT # The client must be a subprocess of the script in order for killing it to @@ -1740,6 +1749,14 @@ run_test() { PXY_CMD="" fi + # Does this test force a specific port? + if [ "$1" = "-P" ]; then + THIS_SRV_PORT="$2" + shift 2 + else + THIS_SRV_PORT="$SRV_PORT" + fi + # get commands and client output SRV_CMD="$1" CLI_CMD="$2"