summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordefanor <defanor@uberspace.net>2017-05-05 21:02:32 +0300
committerdefanor <defanor@uberspace.net>2017-05-05 21:02:32 +0300
commit46e91feda0374338e688902a7e7cd0e49f4138c9 (patch)
treef91721c91f5855d1b7f32e24d4fb0b18c36e5eb3
parentca1bb0b789e954643a1f025698c8b4a1bce1450d (diff)
Improve the authenticate.sh test
Now it's more or less reliable, and faster.
-rw-r--r--Makefile.am3
-rw-r--r--configure.ac2
-rwxr-xr-xtests/authenticate.sh40
-rwxr-xr-xtests/wait-for-initialization.sed13
4 files changed, 33 insertions, 25 deletions
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}"' </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
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