From 7c6cc6bf5e8e3d09f85a6c9245abf584b74888ac Mon Sep 17 00:00:00 2001
From: Fabian Keil <fk@fabiankeil.de>
Date: Sun, 29 Aug 2010 14:12:30 +0200
Subject: [PATCH 1/4] runtests.pl: Add a -P option to specify an external proxy

... that should be used when executing the tests.

This doesn't work for all test types yet.

The assumption is that the proxy is an HTTP proxy and the
mode sets a User-Agent that allows the proxy to detect that
the request is part of a curl test (only works for tool=curl).

This option should be used together with -R to provide
a customized compareparts() version that knows which
proxy-specific header differences should be ignored.
---
 tests/runtests.pl | 35 +++++++++++++++++++++++++++++++++++
 1 file changed, 35 insertions(+)

diff --git a/tests/runtests.pl b/tests/runtests.pl
index 99be57d..b75831e 100755
--- a/tests/runtests.pl
+++ b/tests/runtests.pl
@@ -114,6 +114,9 @@ my $HOST6IP="[::1]";      # address on which the test server listens
 my $CLIENTIP="127.0.0.1"; # address which curl uses for incoming connections
 my $CLIENT6IP="[::1]";    # address which curl uses for incoming connections
 
+my $use_external_proxy = 0;
+my $proxy_address;
+
 my $base = 8990; # base port number
 
 my $HTTPPORT;            # HTTP server port
@@ -695,6 +698,13 @@ sub stopserver {
 }
 
 #######################################################################
+# Return flags to let curl use an external HTTP proxy
+#
+sub getexternalproxyflags {
+    return " --proxy $proxy_address -H 'User-Agent: curl regression tests' ";
+}
+
+#######################################################################
 # Verify that the server that runs on $ip, $port is our server.  This also
 # implies that we can speak with it, as there might be occasions when the
 # server runs fine but we cannot talk to it ("Failed to connect to ::1: Can't
@@ -726,6 +736,9 @@ sub verifyhttp {
     $flags .= "--globoff ";
     $flags .= "-1 "         if($has_axtls);
     $flags .= "--insecure " if($proto eq 'https');
+    if($use_external_proxy) {
+        $flags .= getexternalproxyflags();
+    }
     $flags .= "\"$proto://$ip:$port/${bonus}verifiedserver\"";
 
     my $cmd = "$VCURL $flags 2>$verifylog";
@@ -800,6 +813,9 @@ sub verifyftp {
     $flags .= "--verbose ";
     $flags .= "--globoff ";
     $flags .= $extra;
+    if($use_external_proxy) {
+        $flags .= getexternalproxyflags();
+    }
     $flags .= "\"$proto://$ip:$port/verifiedserver\"";
 
     my $cmd = "$VCURL $flags 2>$verifylog";
@@ -862,6 +878,9 @@ sub verifyrtsp {
     $flags .= "--silent ";
     $flags .= "--verbose ";
     $flags .= "--globoff ";
+    if($use_external_proxy) {
+        $flags .= getexternalproxyflags();
+    }
     # currently verification is done using http
     $flags .= "\"http://$ip:$port/verifiedserver\"";
 
@@ -1003,6 +1022,9 @@ sub verifyhttptls {
     $flags .= "--tlsauthtype SRP ";
     $flags .= "--tlsuser jsmith ";
     $flags .= "--tlspassword abc ";
+    if($use_external_proxy) {
+        $flags .= getexternalproxyflags();
+    }
     $flags .= "\"https://$ip:$port/verifiedserver\"";
 
     my $cmd = "$VCURL $flags 2>$verifylog";
@@ -3090,6 +3112,10 @@ sub singletest {
             }
         }
     }
+    if($use_external_proxy) {
+        $ENV{http_proxy} = $proxy_address;
+        $ENV{HTTPS_PROXY} = $proxy_address;
+    }
 
     if(!$why) {
         # TODO:
@@ -3317,6 +3343,9 @@ sub singletest {
             $fail_due_event_based--;
         }
         $cmdargs .= $cmd;
+        if ($use_external_proxy) {
+            $cmdargs .= " --proxy $proxy_address -H 'User-Agent: curl regression tests'";
+        }
     }
     else {
         $cmdargs = " $cmd"; # $cmd is the command line for the test file
@@ -4659,6 +4688,11 @@ while(@ARGV) {
     elsif($ARGV[0] eq "-p") {
         $postmortem=1;
     }
+    elsif($ARGV[0] eq "-P") {
+        shift @ARGV;
+        $use_external_proxy=1;
+        $proxy_address=$ARGV[0];
+    }
     elsif($ARGV[0] eq "-l") {
         # lists the test case names only
         $listonly=1;
@@ -4710,6 +4744,7 @@ Usage: runtests.pl [options] [test selection(s)]
   -l       list all test case names/descriptions
   -n       no valgrind
   -p       print log file contents when a test fails
+  -P proxy use the specified proxy
   -r       run time statistics
   -rf      full run time statistics
   -s       short output
-- 
1.9.0


