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. --- tests/authenticate.sh | 40 +++++++++++++++++----------------------- 1 file changed, 17 insertions(+), 23 deletions(-) (limited to 'tests/authenticate.sh') 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 -- cgit v1.2.3