From 46e91feda0374338e688902a7e7cd0e49f4138c9 Mon Sep 17 00:00:00 2001 From: defanor Date: Fri, 5 May 2017 21:02:32 +0300 Subject: Improve the authenticate.sh test Now it's more or less reliable, and faster. --- Makefile.am | 3 ++- configure.ac | 2 +- tests/authenticate.sh | 40 +++++++++++++++++---------------------- tests/wait-for-initialization.sed | 13 +++++++++++++ 4 files changed, 33 insertions(+), 25 deletions(-) create mode 100755 tests/wait-for-initialization.sed diff --git a/Makefile.am b/Makefile.am index 7e31d9b..b941495 100644 --- a/Makefile.am +++ b/Makefile.am @@ -18,9 +18,10 @@ TESTS = tests/authenticate.sh TESTS_ENVIRONMENT = \ builddir="$(builddir)" \ - certdir="$(top_srcdir)/tests/" + testdir="$(top_srcdir)/tests/" EXTRA_DIST = $(TESTS) \ + tests/wait-for-initialization.sed \ tests/test-key-1.pem \ tests/test-cert-1.pem \ tests/test-key-2.pem \ diff --git a/configure.ac b/configure.ac index 8b877db..9306649 100644 --- a/configure.ac +++ b/configure.ac @@ -2,7 +2,7 @@ # Process this file with autoconf to produce a configure script. AC_PREREQ([2.69]) -AC_INIT(TLSd, 0.0.4, defanor@uberspace.net, tlsd, +AC_INIT(TLSd, 0.0.5, defanor@uberspace.net, tlsd, https://defanor.uberspace.net/projects/tlsd/) AM_INIT_AUTOMAKE([-Wall]) AC_CONFIG_SRCDIR([tlsd.c]) diff --git a/tests/authenticate.sh b/tests/authenticate.sh index 5e8c63b..bfcad4e 100755 --- a/tests/authenticate.sh +++ b/tests/authenticate.sh @@ -1,38 +1,32 @@ #!/bin/sh -# Basic authentication test. The test is slow and unreliable: it uses -# `sleep` where something like `expect` would be more suitable, -# doesn't perform any checks except for the final one, the port is -# hardcoded, etc. And maybe it would be easier to just rewrite it in -# C. But including this for now, since there is nothing else yet, and -# it still may be useful for testing. +# Basic authentication test. builddir="${builddir:-.}" TLSD="${builddir}/tlsd" -certdir="${certdir:-.}" +testdir="${testdir:-.}" result=1 quit () { - rm -f client-cmd-out - kill %1 %2 + rm -f server-out client-cmd-out exit $result } trap quit EXIT +mkfifo server-out client-cmd-out -mkfifo client-cmd-out # Run the server -${TLSD} -k "${certdir}/test-key-1.pem" -c "${certdir}/test-cert-1.pem" \ - -i tlsd-test-server -p 45678 -- \ - sh -c 'echo "${SIDE} talks to ${SHA256}"' client-cmd-out' & -sleep 10 -# Check the output -diff client-cmd-out - << EOF +${TLSD} -k "${testdir}/test-key-1.pem" -c "${testdir}/test-cert-1.pem" \ + -e -i tlsd-test-server -- \ + sh -c 'echo "${SIDE} talks to ${SHA256}"' server-out & +{ PORT=`${testdir}/wait-for-initialization.sed` || ( kill %1; cat; exit ) + ${TLSD} -k "${testdir}/test-key-2.pem" -c "${testdir}/test-cert-2.pem" \ + -i tlsd-test-client -- sh -c \ + '( echo "${SIDE} talks to ${SHA256}" && cat ) > client-cmd-out' \ + <<<"localhost ${PORT}" & + diff client-cmd-out - << EOF CLIENT talks to 70ec32556b3682681bd45d32609cfaa13391b69a5994c5cc3b8d2b249085cd0a SERVER talks to c287d5c79baf7eb44756f5cad81d2f84402c57dcdf2957d70c0b11d05cbf5f80 EOF -result=$? + result=$? + kill %1 %2 + cat +} < server-out diff --git a/tests/wait-for-initialization.sed b/tests/wait-for-initialization.sed new file mode 100755 index 0000000..9f0d808 --- /dev/null +++ b/tests/wait-for-initialization.sed @@ -0,0 +1,13 @@ +#!/bin/sed -rf + +s/^[^:]+: Initializing$// +T err +n +s/^[^:]+: Attempting to bind: [^ ,]+, port [0-9]+$// +T err +n +s/^[^:]+: Listening on [^ ,]+, port ([0-9]+)$/\1/ +T err +q 0 +: err +Q 1 -- cgit v1.2.3