X-Git-Url: https://ruderich.org/simon/gitweb/?a=blobdiff_plain;f=tests%2Fcommon.sh;h=37c691beaf71bbb43480940b98dc58c9e17e1875;hb=2a478be51f6e6d8f56895e3fee3b122625042d8c;hp=587b5f897f56e3b97b5c61a7addb07bd3a824d57;hpb=cf65dc05b04654c77b71d881e3196c2b5fa3d715;p=tlsproxy%2Ftlsproxy.git diff --git a/tests/common.sh b/tests/common.sh index 587b5f8..37c691b 100644 --- a/tests/common.sh +++ b/tests/common.sh @@ -21,6 +21,7 @@ set -e cleanup() { rm -f \ + tmp tlsproxy-log \ certificate-localhost-proxy.pem certificate-localhost-server.pem \ proxy-ca-key.pem proxy-ca.pem proxy-invalid.pem proxy-key.pem } @@ -33,8 +34,14 @@ abort() { stop_servers exit 1 } +tlsproxy_setup() { + "$srcdir/../src/tlsproxy-setup" >/dev/null 2>&1 +} +tlsproxy_add() { + "$srcdir/../src/tlsproxy-add" "$1" "$srcdir/$2" >/dev/null 2>&1 +} tlsproxy() { - ../src/tlsproxy -d2 "$@" >/dev/null & + ../src/tlsproxy -d2 "$@" >tlsproxy-log 2>&1 & pid_tlsproxy=$! } server() { @@ -45,6 +52,26 @@ client() { ./client ./proxy-ca.pem "$@" > tmp 2>&1 } +wait_for_ports() { + while :; do + sleep 1 + + # Check if each given port can be reached. + ready=1 + for port in "$@"; do + printf 'invalid request\r\n\r\n' \ + | nc localhost "$port" >/dev/null 2>&1 \ + || ready= + done + + if test -n "$ready"; then + break + fi + + echo "waiting for ports $* ..." + done +} + test_proxy_failure() { grep 'proxy failure' tmp >/dev/null \ || abort 'test_proxy_failure'