summaryrefslogtreecommitdiff
path: root/tests/authenticate.sh
diff options
context:
space:
mode:
Diffstat (limited to 'tests/authenticate.sh')
-rwxr-xr-xtests/authenticate.sh40
1 files changed, 17 insertions, 23 deletions
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}"' </dev/null &
-sleep 10
-# Run the client, connect to the server
-echo 'localhost 45678' \
- | ${TLSD} -k "${certdir}/test-key-2.pem" -c "${certdir}/test-cert-2.pem" \
- -i tlsd-test-client -- sh -c \
- '( echo "${SIDE} talks to ${SHA256}" && cat ) > 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}"' </dev/null 2>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