aboutsummaryrefslogtreecommitdiff
path: root/tests/runtests.pl
diff options
context:
space:
mode:
authorDaniel Stenberg <daniel@haxx.se>2011-12-17 23:47:22 +0100
committerDaniel Stenberg <daniel@haxx.se>2012-01-03 15:01:22 +0100
commit82180643f4886d47816cf654f2ee46114e9c296f (patch)
treeee7b55634dbeca7fd641397a6c10dd360cc602d4 /tests/runtests.pl
parent585b89a6c3640af5a1ca963eeafc7d0d82408f00 (diff)
test proxy supports CONNECT
There's a new 'http-proxy' server for tests that runs on a separate port and lets clients do HTTP CONNECT to other ports on the same host to allow us to test HTTP "tunneling" properly. Test cases now have a <proxy> section in <verify> to check that the proxy protocol part matches correctly. Test case 80, 83, 95, 275, 503 and 1078 have been converted. Test 1316 was added.
Diffstat (limited to 'tests/runtests.pl')
-rwxr-xr-xtests/runtests.pl108
1 files changed, 99 insertions, 9 deletions
diff --git a/tests/runtests.pl b/tests/runtests.pl
index 76816887c..7ee7d60a3 100755
--- a/tests/runtests.pl
+++ b/tests/runtests.pl
@@ -6,7 +6,7 @@
# | (__| |_| | _ <| |___
# \___|\___/|_| \_\_____|
#
-# Copyright (C) 1998 - 2011, Daniel Stenberg, <daniel@haxx.se>, et al.
+# Copyright (C) 1998 - 2012, Daniel Stenberg, <daniel@haxx.se>, et al.
#
# This software is licensed as described in the file COPYING, which
# you should have received as part of this distribution. The terms
@@ -138,6 +138,7 @@ my $GOPHERPORT; # Gopher
my $GOPHER6PORT; # Gopher IPv6 server port
my $HTTPTLSPORT; # HTTP TLS (non-stunnel) server port
my $HTTPTLS6PORT; # HTTP TLS (non-stunnel) IPv6 server port
+my $HTTPPROXYPORT; # HTTP proxy port, when using CONNECT
my $srcdir = $ENV{'srcdir'} || '.';
my $CURL="../src/curl".exe_ext(); # what curl executable to run on the tests
@@ -151,6 +152,8 @@ my $LIBDIR="./libtest";
my $UNITDIR="./unit";
# TODO: change this to use server_inputfilename()
my $SERVERIN="$LOGDIR/server.input"; # what curl sent the server
+my $SERVER2IN="$LOGDIR/server2.input"; # what curl sent the second server
+my $PROXYIN="$LOGDIR/proxy.input"; # what curl sent the proxy
my $CURLLOG="$LOGDIR/curl.log"; # all command lines run
my $FTPDCMD="$LOGDIR/ftpserver.cmd"; # copy ftp server instructions here
my $SERVERLOGS_LOCK="$LOGDIR/serverlogs.lock"; # server logs advisor read lock
@@ -1154,7 +1157,7 @@ sub responsiveserver {
# start the http server
#
sub runhttpserver {
- my ($proto, $verbose, $ipv6, $port) = @_;
+ my ($proto, $verbose, $alt, $port) = @_;
my $ip = $HOSTIP;
my $ipvnum = 4;
my $idnum = 1;
@@ -1164,11 +1167,15 @@ sub runhttpserver {
my $logfile;
my $flags = "";
- if($ipv6) {
+ if($alt eq "ipv6") {
# if IPv6, use a different setup
$ipvnum = 6;
$ip = $HOST6IP;
}
+ elsif($alt eq "proxy") {
+ # basically the same, but another ID
+ $idnum = 2;
+ }
$server = servername_id($proto, $ipvnum, $idnum);
@@ -1191,6 +1198,7 @@ sub runhttpserver {
$flags .= "--fork " if($forkserver);
$flags .= "--gopher " if($proto eq "gopher");
+ $flags .= "--connect $HOSTIP " if($alt eq "proxy");
$flags .= "--verbose " if($debugprotocol);
$flags .= "--pidfile \"$pidfile\" --logfile \"$logfile\" ";
$flags .= "--id $idnum " if($idnum > 1);
@@ -1974,16 +1982,19 @@ sub runsocksserver {
# be used to verify that a server present in %run hash is still functional
#
sub responsive_http_server {
- my ($proto, $verbose, $ipv6, $port) = @_;
+ my ($proto, $verbose, $alt, $port) = @_;
my $ip = $HOSTIP;
my $ipvnum = 4;
my $idnum = 1;
- if($ipv6) {
+ if($alt eq "ipv6") {
# if IPv6, use a different setup
$ipvnum = 6;
$ip = $HOST6IP;
}
+ elsif($alt eq "proxy") {
+ $idnum = 2;
+ }
return &responsiveserver($proto, $ipvnum, $idnum, $ip, $port);
}
@@ -2280,6 +2291,9 @@ sub checksystem {
# compiled in because the <features> test will fail.
push @protocols, map($_ . '-ipv6', @protocols);
+ # 'http-proxy' is used in test cases to do CONNECT through
+ push @protocols, 'http-proxy';
+
# 'none' is used in test cases to mean no server
push @protocols, 'none';
}
@@ -2505,6 +2519,7 @@ sub subVariables {
$$thing =~ s/%HTTP6PORT/$HTTP6PORT/g;
$$thing =~ s/%HTTPSPORT/$HTTPSPORT/g;
$$thing =~ s/%HTTPPORT/$HTTPPORT/g;
+ $$thing =~ s/%PROXYPORT/$HTTPPROXYPORT/g;
$$thing =~ s/%IMAP6PORT/$IMAP6PORT/g;
$$thing =~ s/%IMAPPORT/$IMAPPORT/g;
@@ -2896,6 +2911,9 @@ sub singletest {
# this is the valid protocol blurb curl should generate
my @protocol= fixarray ( getpart("verify", "protocol") );
+ # this is the valid protocol blurb curl should generate to a proxy
+ my @proxyprot = fixarray ( getpart("verify", "proxy") );
+
# redirected stdout/stderr to these files
$STDOUT="$LOGDIR/stdout$testnum";
$STDERR="$LOGDIR/stderr$testnum";
@@ -2935,6 +2953,8 @@ sub singletest {
# remove server output logfile
unlink($SERVERIN);
+ unlink($SERVER2IN);
+ unlink($PROXYIN);
if(@ftpservercmd) {
# write the instructions to file
@@ -3428,6 +3448,56 @@ sub singletest {
$ok .= "-"; # protocol not checked
}
+ if(@proxyprot) {
+ # Verify the sent proxy request
+ my @out = loadarray($PROXYIN);
+
+ # what to cut off from the live protocol sent by curl, we use the
+ # same rules as for <protocol>
+ my @strip = getpart("verify", "strip");
+
+ my @protstrip=@proxyprot;
+
+ # check if there's any attributes on the verify/protocol section
+ my %hash = getpartattr("verify", "proxy");
+
+ if($hash{'nonewline'}) {
+ # Yes, we must cut off the final newline from the final line
+ # of the protocol data
+ chomp($protstrip[$#protstrip]);
+ }
+
+ for(@strip) {
+ # strip off all lines that match the patterns from both arrays
+ chomp $_;
+ @out = striparray( $_, \@out);
+ @protstrip= striparray( $_, \@protstrip);
+ }
+
+ # what parts to cut off from the protocol
+ my @strippart = getpart("verify", "strippart");
+ my $strip;
+ for $strip (@strippart) {
+ chomp $strip;
+ for(@out) {
+ eval $strip;
+ }
+ }
+
+ $res = compare("proxy", \@out, \@protstrip);
+ if($res) {
+ # timestamp test result verification end
+ $timevrfyend{$testnum} = Time::HiRes::time() if($timestats);
+ return 1;
+ }
+
+ $ok .= "P";
+
+ }
+ else {
+ $ok .= "-"; # protocol not checked
+ }
+
my @outfile=getpart("verify", "file");
if(@outfile) {
# we're supposed to verify a dynamically generated file!
@@ -3718,7 +3788,8 @@ sub startservers {
if($pid <= 0) {
return "failed starting GOPHER server";
}
- printf ("* pid gopher => %d %d\n", $pid, $pid2) if($verbose);
+ logmsg sprintf ("* pid gopher => %d %d\n", $pid, $pid2)
+ if($verbose);
$run{'gopher'}="$pid $pid2";
}
}
@@ -3750,17 +3821,35 @@ sub startservers {
if($pid <= 0) {
return "failed starting HTTP server";
}
- printf ("* pid http => %d %d\n", $pid, $pid2) if($verbose);
+ logmsg sprintf ("* pid http => %d %d\n", $pid, $pid2)
+ if($verbose);
$run{'http'}="$pid $pid2";
}
}
+ elsif($what eq "http-proxy") {
+ if($torture && $run{'http-proxy'} &&
+ !responsive_http_server("http", $verbose, "proxy",
+ $HTTPPROXYPORT)) {
+ stopserver('http-proxy');
+ }
+ if(!$run{'http-proxy'}) {
+ ($pid, $pid2) = runhttpserver("http", $verbose, "proxy",
+ $HTTPPROXYPORT);
+ if($pid <= 0) {
+ return "failed starting HTTP-proxy server";
+ }
+ logmsg sprintf ("* pid http-proxy => %d %d\n", $pid, $pid2)
+ if($verbose);
+ $run{'http-proxy'}="$pid $pid2";
+ }
+ }
elsif($what eq "http-ipv6") {
if($torture && $run{'http-ipv6'} &&
!responsive_http_server("http", $verbose, "IPv6", $HTTP6PORT)) {
stopserver('http-ipv6');
}
if(!$run{'http-ipv6'}) {
- ($pid, $pid2) = runhttpserver("http", $verbose, "IPv6",
+ ($pid, $pid2) = runhttpserver("http", $verbose, "ipv6",
$HTTP6PORT);
if($pid <= 0) {
return "failed starting HTTP-IPv6 server";
@@ -4021,7 +4110,7 @@ sub serverfortest {
return "curl lacks $tlsext support";
}
else {
- return "curl lacks $server support";
+ return "curl lacks $server server support";
}
}
}
@@ -4411,6 +4500,7 @@ $GOPHERPORT = $base++; # Gopher IPv4 server port
$GOPHER6PORT = $base++; # Gopher IPv6 server port
$HTTPTLSPORT = $base++; # HTTP TLS (non-stunnel) server port
$HTTPTLS6PORT = $base++; # HTTP TLS (non-stunnel) IPv6 server port
+$HTTPPROXYPORT = $base++; # HTTP proxy port, when using CONNECT
#######################################################################
# clear and create logging directory: