1 | #!/bin/bash |
---|
2 | |
---|
3 | # Author: Daniel Kahn Gillmor <dkg@fifthhorseman.net> |
---|
4 | |
---|
5 | set -e |
---|
6 | |
---|
7 | tests="${1##t-}" |
---|
8 | |
---|
9 | if [ -n "${TEST_LOCK}" ]; then |
---|
10 | TEST_LOCK="$(realpath ${TEST_LOCK})" |
---|
11 | flock_cmd="flock -w 10 ${TEST_LOCK}" |
---|
12 | fi |
---|
13 | |
---|
14 | BADVARS=0 |
---|
15 | for v in TEST_HOST TEST_IP TEST_PORT TEST_QUERY_DELAY TEST_GAP MSVA_PORT; do |
---|
16 | if [ ! -v "$v" ]; then |
---|
17 | printf "You need to set the %s environment variable\n" "$v" >&2 |
---|
18 | BADVARS=1 |
---|
19 | fi |
---|
20 | done |
---|
21 | |
---|
22 | if [ 0 != "$BADVARS" ]; then |
---|
23 | exit 1 |
---|
24 | fi |
---|
25 | |
---|
26 | if [ . != "$(dirname "$0")" ]; then |
---|
27 | printf "You should only run this mod-gnutls test suite from the test/ directory of the mod_gnutls source.\n" >&2 |
---|
28 | exit 1 |
---|
29 | fi |
---|
30 | |
---|
31 | function stop_msva() { |
---|
32 | kill %1 |
---|
33 | } |
---|
34 | |
---|
35 | function apache_down_err() { |
---|
36 | printf "FAILURE: %s\n" "$TEST_NAME" |
---|
37 | /usr/sbin/apache2 -f "$(pwd)/apache.conf" -k stop || true |
---|
38 | if [ -e output ]; then |
---|
39 | printf "\ngnutls-cli outputs:\n" |
---|
40 | diff -u output <( tail -n "$(wc -l < output)" "$output" ) || true |
---|
41 | fi |
---|
42 | printf "\nApache error logs:\n" |
---|
43 | tail "../../logs/${TEST_NAME}.error.log" |
---|
44 | if [ -n "${USE_MSVA}" ]; then |
---|
45 | stop_msva |
---|
46 | fi |
---|
47 | } |
---|
48 | |
---|
49 | if [ -z "$tests" ] ; then |
---|
50 | tests=./tests/* |
---|
51 | else |
---|
52 | tests=./tests/"$(printf "%02d" "$tests")"_* |
---|
53 | fi |
---|
54 | |
---|
55 | if [ -n "${USE_MSVA}" ]; then |
---|
56 | GNUPGHOME=$(pwd)/msva.gnupghome MSVA_KEYSERVER_POLICY=never monkeysphere-validation-agent & |
---|
57 | trap stop_msva EXIT |
---|
58 | |
---|
59 | sleep "$TEST_GAP" |
---|
60 | |
---|
61 | printf "TESTING: initial MSVA verification\n" |
---|
62 | MONKEYSPHERE_VALIDATION_AGENT_SOCKET="http://127.0.0.1:$MSVA_PORT" msva-query-agent https "$(cat client.uid)" x509pem client < client/x509.pem |
---|
63 | printf "\nSUCCESS: initial MSVA verification\n" |
---|
64 | fi |
---|
65 | |
---|
66 | for t in $tests; do |
---|
67 | if [ -z "${flock_cmd}" ]; then |
---|
68 | echo "Warning: no lock file set" |
---|
69 | sleep "$TEST_GAP" |
---|
70 | fi |
---|
71 | export TEST_NAME="$(basename "$t")" |
---|
72 | output="../../outputs/${TEST_NAME}.output" |
---|
73 | rm -f "$output" |
---|
74 | cd "$t" |
---|
75 | if [ -e fail.* ]; then |
---|
76 | EXPECTED_FAILURE="$(printf " (expected: %s)" fail.*)" |
---|
77 | else |
---|
78 | unset EXPECTED_FAILURE |
---|
79 | fi |
---|
80 | printf "TESTING: %s%s\n" "$TEST_NAME" "$EXPECTED_FAILURE" |
---|
81 | trap apache_down_err EXIT |
---|
82 | if [ -n "${USE_MSVA}" ]; then |
---|
83 | MONKEYSPHERE_VALIDATION_AGENT_SOCKET="http://127.0.0.1:$MSVA_PORT" \ |
---|
84 | ${flock_cmd} \ |
---|
85 | /usr/sbin/apache2 -f "$(pwd)/apache.conf" -k start \ |
---|
86 | || [ -e fail.server ] |
---|
87 | else |
---|
88 | ${flock_cmd} \ |
---|
89 | /usr/sbin/apache2 -f "$(pwd)/apache.conf" -k start \ |
---|
90 | || [ -e fail.server ] |
---|
91 | fi |
---|
92 | |
---|
93 | # The sleep call keeps the pipe from the subshell to gnutls-cli |
---|
94 | # open. Without it gnutls-cli would terminate as soon as sed is |
---|
95 | # done, and not wait for a response from the server, leading to |
---|
96 | # failing tests. Sending sleep to the background allows the test |
---|
97 | # case to proceed instead of waiting for it to return, but has the |
---|
98 | # disadvantage of leaving the sleep process dangling until it |
---|
99 | # eventually times out. Still preferable to a fixed delay. |
---|
100 | if (sed "s/__HOSTNAME__/${TEST_HOST}/" <./input && \ |
---|
101 | sleep "${TEST_QUERY_DELAY}" &) | \ |
---|
102 | gnutls-cli -p "${TEST_PORT}" $(cat ./gnutls-cli.args) "${TEST_HOST}" \ |
---|
103 | >"$output"; |
---|
104 | then |
---|
105 | if [ -e fail* ]; then |
---|
106 | printf "%s should have failed but succeeded\n" "$(basename "$t")" >&2 |
---|
107 | exit 1 |
---|
108 | fi |
---|
109 | else |
---|
110 | if [ ! -e fail* ]; then |
---|
111 | printf "%s should have succeeded but failed\n" "$(basename "$t")" >&2 |
---|
112 | exit 1 |
---|
113 | fi |
---|
114 | fi |
---|
115 | |
---|
116 | if [ -e output ] ; then |
---|
117 | diff -q -u output <( tail -n "$(wc -l < output)" "$output" ) |
---|
118 | fi |
---|
119 | /usr/sbin/apache2 -f "$(pwd)/apache.conf" -k stop || [ -e fail.server ] |
---|
120 | if [ -n "${USE_MSVA}" ]; then |
---|
121 | trap stop_msva EXIT |
---|
122 | else |
---|
123 | trap - EXIT |
---|
124 | fi |
---|
125 | printf "SUCCESS: %s\n" "$TEST_NAME" |
---|
126 | cd ../.. |
---|
127 | done |
---|
128 | |
---|
129 | if [ -n "${USE_MSVA}" ]; then |
---|
130 | stop_msva |
---|
131 | fi |
---|