summaryrefslogtreecommitdiffhomepage
path: root/tests/scripts/run_tests.sh
diff options
context:
space:
mode:
Diffstat (limited to 'tests/scripts/run_tests.sh')
-rwxr-xr-xtests/scripts/run_tests.sh81
1 files changed, 70 insertions, 11 deletions
diff --git a/tests/scripts/run_tests.sh b/tests/scripts/run_tests.sh
index dd95400..eb1d3c4 100755
--- a/tests/scripts/run_tests.sh
+++ b/tests/scripts/run_tests.sh
@@ -30,6 +30,7 @@ TINYPROXY_USER=$(id -un)
TINYPROXY_PID_DIR=$TESTENV_DIR/var/run/tinyproxy
TINYPROXY_PID_FILE=$TINYPROXY_PID_DIR/tinyproxy.pid
TINYPROXY_LOG_DIR=$LOG_DIR/tinyproxy
+TINYPROXY_LOG_FILE=$TINYPROXY_LOG_DIR/tinyproxy.log
TINYPROXY_DATA_DIR=$TESTENV_DIR/usr/share/tinyproxy
TINYPROXY_CONF_DIR=$TESTENV_DIR/etc/tinyproxy
TINYPROXY_CONF_FILE=$TINYPROXY_CONF_DIR/tinyproxy.conf
@@ -79,26 +80,30 @@ Listen $TINYPROXY_IP
Timeout 600
StatHost "$TINYPROXY_STATHOST_IP"
DefaultErrorFile "$TINYPROXY_DATA_DIR/debug.html"
+ErrorFile 400 "$TINYPROXY_DATA_DIR/debug.html"
+ErrorFile 403 "$TINYPROXY_DATA_DIR/debug.html"
+ErrorFile 501 "$TINYPROXY_DATA_DIR/debug.html"
StatFile "$TINYPROXY_DATA_DIR/stats.html"
-Logfile "$TINYPROXY_LOG_DIR/tinyproxy.log"
+Logfile "$TINYPROXY_LOG_FILE"
PidFile "$TINYPROXY_PID_FILE"
LogLevel Info
MaxClients 100
-MinSpareServers 5
-MaxSpareServers 20
-StartServers 10
-MaxRequestsPerChild 0
Allow 127.0.0.0/8
ViaProxyName "tinyproxy"
#DisableViaHeader Yes
ConnectPort 443
ConnectPort 563
-FilterURLs On
+#FilterURLs On
Filter "$TINYPROXY_FILTER_FILE"
XTinyproxy Yes
+AddHeader "X-My-Header1" "Powered by Tinyproxy"
+AddHeader "X-My-Header2" "Powered by Tinyproxy"
+AddHeader "X-My-Header3" "Powered by Tinyproxy"
EOF
- touch $TINYPROXY_FILTER_FILE
+cat << 'EOF' > $TINYPROXY_FILTER_FILE
+.*\.google-analytics\.com$
+EOF
}
start_tinyproxy() {
@@ -107,13 +112,26 @@ start_tinyproxy() {
echo " done (listening on $TINYPROXY_IP:$TINYPROXY_PORT)"
}
+reload_config() {
+ echo -n "signaling tinyproxy to reload config..."
+ pid=$(cat $TINYPROXY_PID_FILE)
+ #1: SIGHUP
+ kill -1 $pid && echo "ok" || echo "fail"
+}
+
stop_tinyproxy() {
echo -n "killing tinyproxy..."
- kill $(cat $TINYPROXY_PID_FILE)
+ pid=$(cat $TINYPROXY_PID_FILE)
+ kill $pid
if test "x$?" = "x0" ; then
echo " ok"
else
- echo " error"
+ echo " error killing pid $pid"
+ ps aux | grep tinyproxy
+ echo "### printing logfile"
+ cat $TINYPROXY_LOG_FILE
+ echo "### printing stderr logfile"
+ cat $TINYPROXY_STDERR_LOG
fi
}
@@ -154,7 +172,7 @@ wait_for_some_seconds() {
}
run_basic_webclient_request() {
- $WEBCLIENT_BIN $1 $2 >> $WEBCLIENT_LOG 2>&1
+ $WEBCLIENT_BIN $1 $2 > $WEBCLIENT_LOG 2>&1
WEBCLIENT_EXIT_CODE=$?
if test "x$WEBCLIENT_EXIT_CODE" = "x0" ; then
echo " ok"
@@ -162,11 +180,31 @@ run_basic_webclient_request() {
echo "ERROR ($WEBCLIENT_EXIT_CODE)"
echo "webclient output:"
cat $WEBCLIENT_LOG
+ echo "######################################"
fi
return $WEBCLIENT_EXIT_CODE
}
+run_failure_webclient_request() {
+ ec=$1
+ expected_error=$(($1 - 399))
+ shift
+ $WEBCLIENT_BIN "$1" "$2" "$3" "$4" > $WEBCLIENT_LOG 2>&1
+ WEBCLIENT_EXIT_CODE=$?
+ if test "x$WEBCLIENT_EXIT_CODE" = "x$expected_error" ; then
+ echo " ok, got expected error code $ec"
+ return 0
+ else
+ echo "ERROR ($WEBCLIENT_EXIT_CODE)"
+ echo "webclient output:"
+ cat $WEBCLIENT_LOG
+ echo "######################################"
+ fi
+
+ return 1
+}
+
# "main"
provision_initial
@@ -176,10 +214,11 @@ provision_webserver
start_webserver
start_tinyproxy
-wait_for_some_seconds 3
+wait_for_some_seconds 1
FAILED=0
+basic_test() {
echo -n "checking direct connection to web server..."
run_basic_webclient_request "$WEBSERVER_IP:$WEBSERVER_PORT" /
test "x$?" = "x0" || FAILED=$((FAILED + 1))
@@ -191,6 +230,26 @@ test "x$?" = "x0" || FAILED=$((FAILED + 1))
echo -n "requesting statspage via stathost url..."
run_basic_webclient_request "$TINYPROXY_IP:$TINYPROXY_PORT" "http://$TINYPROXY_STATHOST_IP"
test "x$?" = "x0" || FAILED=$((FAILED + 1))
+}
+
+ext_test() {
+echo -n "checking bogus request..."
+run_failure_webclient_request 400 --method="BIG FART" "$TINYPROXY_IP:$TINYPROXY_PORT" "http://$WEBSERVER_IP:$WEBSERVER_PORT"
+test "x$?" = "x0" || FAILED=$((FAILED + 1))
+
+echo -n "testing connection to filtered domain..."
+run_failure_webclient_request 403 "$TINYPROXY_IP:$TINYPROXY_PORT" "http://badgoy.google-analytics.com/"
+test "x$?" = "x0" || FAILED=$((FAILED + 1))
+
+echo -n "requesting connect method to denied port..."
+run_failure_webclient_request 403 --method=CONNECT "$TINYPROXY_IP:$TINYPROXY_PORT" "localhost:12345"
+test "x$?" = "x0" || FAILED=$((FAILED + 1))
+}
+
+basic_test
+reload_config
+basic_test
+ext_test
echo "$FAILED errors"