source: mod_gnutls/test/runtests @ 302965e

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

Run monkeysphere-validation-agent only for the test case using it

Running and testing monkeysphere-validation-agent for each test case
causes tests to fail when it is not available, and unnecessary delays
when it is. Test cases using monkeysphere-validation-agent must set the
USE_MSVA environment variable to enable it.

Note that TestMakefile? still calls the "pem2openpgp" tool from
Monkeysphere to set up PGP keys for the test environment.

  • Property mode set to 100755
File size: 3.0 KB
Line 
1#!/bin/bash
2
3# Author: Daniel Kahn Gillmor <dkg@fifthhorseman.net>
4
5set -e
6
7tests="${1##t-}"
8
9BADVARS=0
10for v in TEST_HOST TEST_IP TEST_PORT TEST_QUERY_DELAY TEST_GAP MSVA_PORT; do
11    if [ ! -v "$v" ]; then
12        printf "You need to set the %s environment variable\n" "$v" >&2
13        BADVARS=1
14    fi
15done
16
17if [ 0 != "$BADVARS" ]; then
18    exit 1
19fi
20
21if [ . != "$(dirname "$0")" ]; then
22    printf "You should only run this mod-gnutls test suite from the test/ directory of the mod_gnutls source.\n" >&2
23    exit 1
24fi
25
26function stop_msva() {
27    kill %1
28}
29
30function apache_down_err() {
31    printf "FAILURE: %s\n" "$TEST_NAME"
32    /usr/sbin/apache2 -f "$(pwd)/apache.conf" -k stop || true
33    if [ -e output ]; then
34        printf "\ngnutls-cli outputs:\n"
35        diff -u output <( tail -n "$(wc -l < output)" "$output" ) || true
36    fi
37    printf "\nApache error logs:\n"
38    tail "../../logs/${TEST_NAME}.error.log"
39    if [ -n "${USE_MSVA}" ]; then
40        stop_msva
41    fi
42}
43
44if [ -z "$tests" ] ; then
45    tests=./tests/*
46else
47    tests=./tests/"$(printf "%02d" "$tests")"_*
48fi
49
50if [ -n "${USE_MSVA}" ]; then
51    GNUPGHOME=$(pwd)/msva.gnupghome MSVA_KEYSERVER_POLICY=never monkeysphere-validation-agent &
52    trap stop_msva EXIT
53
54    sleep "$TEST_GAP"
55
56    printf "TESTING: initial MSVA verification\n"
57    MONKEYSPHERE_VALIDATION_AGENT_SOCKET="http://127.0.0.1:$MSVA_PORT" msva-query-agent https "$(cat client.uid)" x509pem client < client/x509.pem
58    printf "\nSUCCESS: initial MSVA verification\n"
59fi
60
61for t in $tests; do 
62    sleep "$TEST_GAP"
63    export TEST_NAME="$(basename "$t")"
64    output="../../outputs/${TEST_NAME}.output"
65    rm -f "$output"
66    cd "$t"
67    if [ -e fail.* ]; then
68        EXPECTED_FAILURE="$(printf " (expected: %s)" fail.*)"
69    else
70        unset EXPECTED_FAILURE
71    fi
72    printf "TESTING: %s%s\n" "$TEST_NAME" "$EXPECTED_FAILURE"
73    trap apache_down_err EXIT
74    if [ -n "${USE_MSVA}" ]; then
75        MONKEYSPHERE_VALIDATION_AGENT_SOCKET="http://127.0.0.1:$MSVA_PORT" /usr/sbin/apache2 -f "$(pwd)/apache.conf" -k start || [ -e fail.server ]
76    else
77        /usr/sbin/apache2 -f "$(pwd)/apache.conf" -k start || [ -e fail.server ]
78    fi
79
80    if (sed "s/__HOSTNAME__/${TEST_HOST}/" < ./input && sleep "$TEST_QUERY_DELAY") | \
81        gnutls-cli -p "${TEST_PORT}" $(cat ./gnutls-cli.args) "${TEST_HOST}" > \
82        "$output" ; then
83        if [ -e fail* ]; then
84            printf "%s should have failed but succeeded\n" "$(basename "$t")" >&2
85            exit 1
86        fi
87    else
88        if [ ! -e fail* ]; then
89            printf "%s should have succeeded but failed\n" "$(basename "$t")" >&2
90            exit 1
91        fi
92    fi
93    if [ -e output ] ; then
94        diff -q -u output <( tail -n "$(wc -l < output)" "$output" )
95    fi
96    /usr/sbin/apache2 -f "$(pwd)/apache.conf" -k stop || [ -e fail.server ]
97    if [ -n "${USE_MSVA}" ]; then
98        trap stop_msva EXIT
99    else
100        trap - EXIT
101    fi
102    printf "SUCCESS: %s\n" "$TEST_NAME"
103    cd ../..
104done
105
106if [ -n "${USE_MSVA}" ]; then
107    stop_msva
108fi
Note: See TracBrowser for help on using the repository browser.