source: mod_gnutls/test/runtests @ 6bbc00a

debian/masterdebian/stretch-backportsjessie-backportsupstream
Last change on this file since 6bbc00a was 9e35c48, checked in by Thomas Klute <thomas2.klute@…>, 5 years ago

runtests: Fix flock/Apache call when running with MSVA

The environment variable MONKEYSPHERE_VALIDATION_AGENT_SOCKET must be the
first part of the command line, not the first argument to flock.

  • Property mode set to 100755
File size: 3.2 KB
Line 
1#!/bin/bash
2
3# Author: Daniel Kahn Gillmor <dkg@fifthhorseman.net>
4
5set -e
6
7tests="${1##t-}"
8
9if [ -n "${TEST_LOCK}" ]; then
10    TEST_LOCK="$(realpath ${TEST_LOCK})"
11    flock_cmd="flock -w 10 ${TEST_LOCK}"
12fi
13
14BADVARS=0
15for 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
20done
21
22if [ 0 != "$BADVARS" ]; then
23    exit 1
24fi
25
26if [ . != "$(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
29fi
30
31function stop_msva() {
32    kill %1
33}
34
35function 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
49if [ -z "$tests" ] ; then
50    tests=./tests/*
51else
52    tests=./tests/"$(printf "%02d" "$tests")"_*
53fi
54
55if [ -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"
64fi
65
66for 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    if (sed "s/__HOSTNAME__/${TEST_HOST}/" < ./input && sleep "$TEST_QUERY_DELAY") | \
94        gnutls-cli -p "${TEST_PORT}" $(cat ./gnutls-cli.args) "${TEST_HOST}" > \
95        "$output" ; then
96        if [ -e fail* ]; then
97            printf "%s should have failed but succeeded\n" "$(basename "$t")" >&2
98            exit 1
99        fi
100    else
101        if [ ! -e fail* ]; then
102            printf "%s should have succeeded but failed\n" "$(basename "$t")" >&2
103            exit 1
104        fi
105    fi
106    if [ -e output ] ; then
107        diff -q -u output <( tail -n "$(wc -l < output)" "$output" )
108    fi
109    /usr/sbin/apache2 -f "$(pwd)/apache.conf" -k stop || [ -e fail.server ]
110    if [ -n "${USE_MSVA}" ]; then
111        trap stop_msva EXIT
112    else
113        trap - EXIT
114    fi
115    printf "SUCCESS: %s\n" "$TEST_NAME"
116    cd ../..
117done
118
119if [ -n "${USE_MSVA}" ]; then
120    stop_msva
121fi
Note: See TracBrowser for help on using the repository browser.