Let it digest shiny new LWS tests properly.
[privoxy.git] / tools / privoxy-regression-test.pl
index b30a39f..644f2e4 100755 (executable)
@@ -7,15 +7,12 @@
 # A regression test "framework" for Privoxy. For documentation see:
 # perldoc privoxy-regression-test.pl
 #
-# $Id: privoxy-regression-test.pl,v 1.143 2008/04/04 17:17:32 fk Exp $
+# $Id: privoxy-regression-test.pl,v 1.149 2008/05/17 14:11:29 fk Exp $
 #
 # Wish list:
 #
 # - Update documentation
 # - Validate HTTP times.
-# - Understand default.action.master comment syntax
-#   and verify that we actually block and unblock what
-#   the comments claim we do.
 # - Implement a HTTP_VERSION directive or allow to
 #   specify whole request lines.
 # - Support filter regression tests.
@@ -703,7 +700,7 @@ sub get_final_results ($) {
     my %final_results = ();
     my $final_results_reached = 0;
 
-    die "Unacceptable characterss in $url" if $url =~ m@[\\'"]@;
+    die "Unacceptable characters in $url" if $url =~ m@[\\'"]@;
     # XXX: should be URL-encoded properly
     $url =~ s@%@%25@g;
     $url =~ s@\s@%20@g;
@@ -711,7 +708,7 @@ sub get_final_results ($) {
     $url =~ s@:@%3A@g;
     $url =~ s@/@%2F@g;
 
-    $curl_parameters .= "'" . PRIVOXY_CGI_URL . 'show-url-info?url=' . $url . "'";
+    $curl_parameters .= quote(PRIVOXY_CGI_URL . 'show-url-info?url=' . $url);
 
     foreach (@{get_cgi_page_or_else($curl_parameters)}) {
 
@@ -726,10 +723,10 @@ sub get_final_results ($) {
             
             if (defined $parameter) {
                 # In case the caller needs to check
-                # the action and it's parameter
+                # the action and its parameter
                 $final_results{$action . $parameter} = 1;
             }
-            # In case the action doesn't have paramters
+            # In case the action doesn't have parameters
             # or the caller doesn't care for the parameter.
             $final_results{$action} = 1;
         }
@@ -806,8 +803,6 @@ sub check_header_result ($$) {
     my $expect_header = $test{'expect-header'};
     my $success = 0;
 
-    $header =~ s@   @ @g if defined($header);
-
     if ($expect_header eq 'NO CHANGE') {
 
         if (defined($header) and $header eq $test{'data'}) {
@@ -922,6 +917,9 @@ sub get_header ($$) {
         s@^\s*<.*?>@@g;
         s@\s*$@@g;
 
+        # Decode characters we care about. 
+        s@&quot;@"@g;
+
         $filtered_request .=  "\n" . $_;
          
         if (/^$header_to_get/) {
@@ -1103,15 +1101,15 @@ sub get_head_with_curl ($) {
 
 sub get_page_with_curl ($) {
 
+    our $proxy;
+
     my $parameters = shift;
     my @buffer;
     my $curl_line = CURL;
     my $retries_left = get_cli_option('retries') + 1;
     my $failure_reason;
 
-    if (cli_option_is_set('privoxy-address')) {
-        $curl_line .= ' --proxy ' . get_cli_option('privoxy-address');
-    }
+    $curl_line .= ' --proxy ' . $proxy if (defined $proxy);
 
     # We want to see the HTTP status code
     $curl_line .= " --include ";
@@ -1307,7 +1305,7 @@ sub log_result ($$) {
         }
     }
 
-    log_message($message) unless ($result && cli_option_is_set('silent'));
+    log_message($message) if (!$result or cli_option_is_set('verbose'));
 }
 
 sub quote ($) {
@@ -1329,6 +1327,7 @@ sub help () {
 
 Options and their default values if they have any:
     [--debug $cli_options{'debug'}]
+    [--fuzzer-address]
     [--fuzzer-feeding]
     [--help]
     [--level]
@@ -1338,7 +1337,7 @@ Options and their default values if they have any:
     [--min-level $cli_options{'min-level'}]
     [--privoxy-address]
     [--retries $cli_options{'retries'}]
-    [--silent]
+    [--verbose]
     [--version]
 see "perldoc $0" for more information
     EOF
@@ -1369,16 +1368,17 @@ sub parse_cli_options () {
     GetOptions (
                 'debug=s' => \$cli_options{'debug'},
                 'help'     => sub { help },
-                'silent' => \$cli_options{'silent'},
                 'min-level=s' => \$cli_options{'min-level'},
                 'max-level=s' => \$cli_options{'max-level'},
                 'privoxy-address=s' => \$cli_options{'privoxy-address'},
+                'fuzzer-address=s' => \$cli_options{'fuzzer-address'},
                 'level=s' => \$cli_options{'level'},
                 'loops=s' => \$cli_options{'loops'},
                 'test-number=s' => \$cli_options{'test-number'},
                 'fuzzer-feeding' => \$cli_options{'fuzzer-feeding'},
                 'retries=s' => \$cli_options{'retries'},
                 'max-time=s' => \$cli_options{'max-time'},
+                'verbose' => \$cli_options{'verbose'},
                 'version'  => sub { print_version && exit(0) }
     );
     $log_level |= $cli_options{'debug'};
@@ -1402,12 +1402,32 @@ sub get_cli_option ($) {
     return $cli_options{$cli_option};
 }
 
+sub init_proxy_settings($) {
+
+    my $choice = shift;
+    our $proxy = undef;
+
+    if (($choice eq 'fuzz-proxy') and cli_option_is_set('fuzzer-address')) {
+        $proxy = get_cli_option('fuzzer-address');
+    }
+
+    if ((not defined $proxy) or ($choice eq 'vanilla-proxy')) {
+
+        if (cli_option_is_set('privoxy-address')) {
+            $proxy .=  get_cli_option('privoxy-address');
+        }
+
+    }
+}
+
 sub main () {
 
     init_our_variables();
     parse_cli_options();
     check_for_curl();
+    init_proxy_settings('vanilla-proxy');
     load_regressions_tests();
+    init_proxy_settings('fuzz-proxy');
     execute_regression_tests();
 }
 
@@ -1419,10 +1439,11 @@ B<privoxy-regression-test> - A regression test "framework" for Privoxy.
 
 =head1 SYNOPSIS
 
-B<privoxy-regression-test> [B<--debug bitmask>] [B<--fuzzer-feeding>] [B<--help>]
-[B<--level level>] [B<--loops count>] [B<--max-level max-level>]
-[B<--max-time max-time>] [B<--min-level min-level>] B<--privoxy-address proxy-address>
-[B<--retries retries>] [B<--silent>] [B<--version>]
+B<privoxy-regression-test> [B<--debug bitmask>] [B<--fuzzer-feeding>]
+[B<--fuzzer-feeding>] [B<--help>] [B<--level level>] [B<--loops count>]
+[B<--max-level max-level>] [B<--max-time max-time>]
+[B<--min-level min-level>] B<--privoxy-address proxy-address>
+[B<--retries retries>] [B<--verbose>] [B<--version>]
 
 =head1 DESCRIPTION
 
@@ -1521,6 +1542,10 @@ requests to level 3 and client-header-action tests to level 1.
 B<--debug bitmask> Add the bitmask provided as integer
 to the debug settings.
 
+B<--fuzzer-address> Listening address used when executing
+the regression tests. Useful to make sure that the requests
+to load the regression tests don't fail due to fuzzing.
+
 B<--fuzzer-feeding> Ignore some errors that would otherwise
 cause Privoxy-Regression-Test to abort the test because
 they shouldn't happen in normal operation. This option is
@@ -1557,7 +1582,7 @@ syntax.
 
 B<--retries retries> Retry B<retries> times.
 
-B<--silent> Don't log succesful test runs.
+B<--verbose> Also log succesful test runs.
 
 B<--version> Print version and exit.