From 50c62f7235eacd3b88c59ead983e8be719fb7604 Mon Sep 17 00:00:00 2001 From: Guus Sliepen Date: Fri, 1 Apr 2022 16:00:09 +0200 Subject: [PATCH] Speed up the authentication protocol security tests. The security test took 70 seconds, mainly because it consisted of several subtests that each had to wait for a timeout to pass. Split it into three tests; two for testing a MITM splicing connections between tinc daemons using the legacy and SPTPS protocols, the remaining tests are in a single shell script but now run in parallel. --- test/integration/meson.build | 2 + test/integration/security-legacy.test | 88 +++++++++++++++++++++++++++ test/integration/security-sptps.test | 86 ++++++++++++++++++++++++++ test/integration/security.test | 77 +++-------------------- 4 files changed, 184 insertions(+), 69 deletions(-) create mode 100755 test/integration/security-legacy.test create mode 100755 test/integration/security-sptps.test diff --git a/test/integration/meson.build b/test/integration/meson.build index ef33b085..b32ea82e 100644 --- a/test/integration/meson.build +++ b/test/integration/meson.build @@ -7,6 +7,8 @@ tests = [ 'invite-offline.test', 'invite-tinc-up.test', 'security.test', + 'security-legacy.test', + 'security-sptps.test', 'variables.test', ] diff --git a/test/integration/security-legacy.test b/test/integration/security-legacy.test new file mode 100755 index 00000000..7f036d35 --- /dev/null +++ b/test/integration/security-legacy.test @@ -0,0 +1,88 @@ +#!/bin/sh + +# shellcheck disable=SC1090 +. "$TESTLIB_PATH" + +echo [STEP] Skip this test if tools are missing + +command -v nc >/dev/null || exit "$EXIT_SKIP_TEST" +command -v timeout >/dev/null || exit "$EXIT_SKIP_TEST" + +foo_port=30110 +bar_port=30111 + +# usage: splice protocol_version +splice() { + "$SPLICE_PATH" foo localhost $foo_port bar localhost $bar_port "$1" & + sleep 10 +} + +# usage: send_with_timeout "data to send" "data expected to receive" +send_with_timeout() { + data=$1 + expected=$3 + + result=$( + ( + sleep 6 + printf "%s\n" "$data" + ) | timeout 10 nc localhost $foo_port + ) && exit 1 + + test $? = "$EXIT_TIMEOUT" + + if [ -z "$expected" ]; then + test -z "$result" + else + echo "$result" | grep -q "^$expected" + fi +} + +echo [STEP] Initialize two nodes + +tinc foo </dev/null || exit "$EXIT_SKIP_TEST" +command -v timeout >/dev/null || exit "$EXIT_SKIP_TEST" + +foo_port=30120 +bar_port=30121 + +# usage: splice protocol_version +splice() { + "$SPLICE_PATH" foo localhost $foo_port bar localhost $bar_port "$1" & + sleep 10 +} + +# usage: send_with_timeout "data to send" "data expected to receive" +send_with_timeout() { + data=$1 + expected=$3 + + result=$( + ( + sleep 6 + printf "%s\n" "$data" + ) | timeout 10 nc localhost $foo_port + ) && exit 1 + + test $? = "$EXIT_TIMEOUT" + + if [ -z "$expected" ]; then + test -z "$result" + else + echo "$result" | grep -q "^$expected" + fi +} + +echo [STEP] Initialize two nodes + +tinc foo </dev/null || exit "$EXIT_SKIP_TEST" command -v timeout >/dev/null || exit "$EXIT_SKIP_TEST" foo_port=30050 -bar_port=30051 - -# usage: splice protocol_version -splice() { - "$SPLICE_PATH" foo localhost $foo_port bar localhost $bar_port "$1" & - sleep 10 -} # usage: send_with_timeout "data to send" "data expected to receive" send_with_timeout() { @@ -50,80 +43,26 @@ set AutoConnect no set Subnet 10.96.96.1 EOF -tinc bar <