diff options
Diffstat (limited to 'plugins/tests')
| -rwxr-xr-x | plugins/tests/check_curl.t | 317 |
1 files changed, 313 insertions, 4 deletions
diff --git a/plugins/tests/check_curl.t b/plugins/tests/check_curl.t index 52c5ad1c..94058d5b 100755 --- a/plugins/tests/check_curl.t +++ b/plugins/tests/check_curl.t | |||
| @@ -20,10 +20,15 @@ use Test::More; | |||
| 20 | use NPTest; | 20 | use NPTest; |
| 21 | use FindBin qw($Bin); | 21 | use FindBin qw($Bin); |
| 22 | 22 | ||
| 23 | use URI; | ||
| 24 | use URI::QueryParam; | ||
| 25 | use HTTP::Daemon; | ||
| 26 | use HTTP::Daemon::SSL; | ||
| 27 | |||
| 23 | $ENV{'LC_TIME'} = "C"; | 28 | $ENV{'LC_TIME'} = "C"; |
| 24 | 29 | ||
| 25 | my $common_tests = 75; | 30 | my $common_tests = 111; |
| 26 | my $ssl_only_tests = 8; | 31 | my $ssl_only_tests = 12; |
| 27 | # Check that all dependent modules are available | 32 | # Check that all dependent modules are available |
| 28 | eval "use HTTP::Daemon 6.01;"; | 33 | eval "use HTTP::Daemon 6.01;"; |
| 29 | plan skip_all => 'HTTP::Daemon >= 6.01 required' if $@; | 34 | plan skip_all => 'HTTP::Daemon >= 6.01 required' if $@; |
| @@ -36,7 +41,7 @@ my $plugin = 'check_http'; | |||
| 36 | $plugin = 'check_curl' if $0 =~ m/check_curl/mx; | 41 | $plugin = 'check_curl' if $0 =~ m/check_curl/mx; |
| 37 | 42 | ||
| 38 | # look for libcurl version to see if some advanced checks are possible (>= 7.49.0) | 43 | # look for libcurl version to see if some advanced checks are possible (>= 7.49.0) |
| 39 | my $advanced_checks = 12; | 44 | my $advanced_checks = 16; |
| 40 | my $use_advanced_checks = 0; | 45 | my $use_advanced_checks = 0; |
| 41 | my $required_version = '7.49.0'; | 46 | my $required_version = '7.49.0'; |
| 42 | my $virtual_host = 'www.somefunnyhost.com'; | 47 | my $virtual_host = 'www.somefunnyhost.com'; |
| @@ -186,6 +191,123 @@ sub run_server { | |||
| 186 | $c->send_response('moved to /redirect2'); | 191 | $c->send_response('moved to /redirect2'); |
| 187 | } elsif ($r->url->path eq "/redir_timeout") { | 192 | } elsif ($r->url->path eq "/redir_timeout") { |
| 188 | $c->send_redirect( "/timeout" ); | 193 | $c->send_redirect( "/timeout" ); |
| 194 | } elsif ($r->url->path =~ m{^/redirect_with_increment}) { | ||
| 195 | # <scheme>://<username>:<password>@<host>:<port>/<path>;<parameters>?<query>#<fragment> | ||
| 196 | # Find every parameter, query , and fragment keys and increment them | ||
| 197 | |||
| 198 | my $content = ""; | ||
| 199 | |||
| 200 | # Use URI to help with query/fragment; parse path params manually. | ||
| 201 | my $original_url = $r->url->as_string; | ||
| 202 | $content .= " original_url: ${original_url}\n"; | ||
| 203 | my $uri = URI->new($original_url); | ||
| 204 | $content .= " uri: ${uri}\n"; | ||
| 205 | |||
| 206 | my $path = $uri->path // ''; | ||
| 207 | my $query = $uri->query // ''; | ||
| 208 | my $fragment = $uri->fragment // ''; | ||
| 209 | |||
| 210 | $content .= " path: ${path}\n"; | ||
| 211 | $content .= " query: ${query}\n"; | ||
| 212 | $content .= " fragment: ${fragment}\n"; | ||
| 213 | |||
| 214 | # split the URI part and parameters. URI package cannot do this | ||
| 215 | # group 1 is captured: anything without a semicolon: ([^;]*) | ||
| 216 | # group 2 is uncaptured: (?:;(.*))? | ||
| 217 | # (?: ... )? prevents capturing the parameter section | ||
| 218 | # inside group 2, ';' matches the first ever semicolon | ||
| 219 | # group3 is captured: any character string : (.*) | ||
| 220 | # \? matches an actual ? mark, which starts the query parameters | ||
| 221 | my ($before_params, $params) = $uri =~ m{^([^;]*)(?:;(.*))?\?}; | ||
| 222 | $before_params //= ''; | ||
| 223 | $params //= ''; | ||
| 224 | $content .= " before_params: ${before_params}\n"; | ||
| 225 | $content .= " params: ${params}\n"; | ||
| 226 | my @parameter_pairs; | ||
| 227 | if (defined $params && length $params) { | ||
| 228 | for my $p (split /;/, $params) { | ||
| 229 | my ($key,$value) = split /=/, $p, 2; | ||
| 230 | $value //= ''; | ||
| 231 | push @parameter_pairs, [ $key, $value ]; | ||
| 232 | $content .= " parameter: ${key} -> ${value}\n"; | ||
| 233 | } | ||
| 234 | } | ||
| 235 | |||
| 236 | # query parameters are offered directly from the library | ||
| 237 | my @query_form = $uri->query_form; | ||
| 238 | my @query_parameter_pairs; | ||
| 239 | while (@query_form) { | ||
| 240 | my $key = shift @query_form; | ||
| 241 | my $value = shift @query_form; | ||
| 242 | $value //= ''; # there can be valueless keys | ||
| 243 | push @query_parameter_pairs, [ $key, $value ]; | ||
| 244 | $content .= " query: ${key} -> ${value}\n"; | ||
| 245 | } | ||
| 246 | |||
| 247 | # helper to increment value | ||
| 248 | my $increment = sub { | ||
| 249 | my ($v) = @_; | ||
| 250 | return $v if !defined $v || $v eq ''; | ||
| 251 | # numeric integer | ||
| 252 | if ($v =~ /^-?\d+$/) { | ||
| 253 | return $v + 1; | ||
| 254 | } | ||
| 255 | # otherwise -> increment as if its an ascii character | ||
| 256 | # sed replacement syntax, but the $& holds the matched character | ||
| 257 | if (length($v)) { | ||
| 258 | (my $new_v = $v) =~ s/./chr(ord($&) + 1)/ge; | ||
| 259 | return $new_v; | ||
| 260 | } | ||
| 261 | }; | ||
| 262 | |||
| 263 | # increment values in pairs | ||
| 264 | for my $pair (@parameter_pairs) { | ||
| 265 | $pair->[1] = $increment->($pair->[1]); | ||
| 266 | $content .= " parameter new: " . $pair->[0] . " -> " . $pair->[1] . "\n"; | ||
| 267 | } | ||
| 268 | for my $pair (@query_parameter_pairs) { | ||
| 269 | $pair->[1] = $increment->($pair->[1]); | ||
| 270 | $content .= " query parameter new: " . $pair->[0] . " -> " . $pair->[1] . "\n"; | ||
| 271 | } | ||
| 272 | |||
| 273 | # rebuild strings | ||
| 274 | my $new_parameter_str = join(';', map { $_->[0] . '=' . $_->[1] } @parameter_pairs); | ||
| 275 | $content .= " new_parameter_str: ${new_parameter_str}\n"; | ||
| 276 | |||
| 277 | # library can rebuild from an array | ||
| 278 | my @new_query_form; | ||
| 279 | for my $p (@query_parameter_pairs) { push @new_query_form, $p->[0], $p->[1] } | ||
| 280 | |||
| 281 | my $new_fragment_str = ''; | ||
| 282 | for my $pair (@parameter_pairs) { | ||
| 283 | my $key = $pair->[0]; | ||
| 284 | my $value = $pair->[1]; | ||
| 285 | if ($key eq "fragment") { | ||
| 286 | $new_fragment_str = $value | ||
| 287 | } | ||
| 288 | } | ||
| 289 | $content .= " new_fragment_str: ${new_fragment_str}\n"; | ||
| 290 | |||
| 291 | # construct new URI using the library | ||
| 292 | my $new_uri = URI->new(''); | ||
| 293 | $new_uri->path( $before_params . ($new_parameter_str ? ';' . $new_parameter_str : '') ); | ||
| 294 | $new_uri->query_form( \@new_query_form ) if @new_query_form; | ||
| 295 | $new_uri->fragment( $new_fragment_str ) if $new_fragment_str ne ''; | ||
| 296 | $content .= " new_uri: ${new_uri}\n"; | ||
| 297 | |||
| 298 | # Redirect until fail_count or redirect_count reaches 3 | ||
| 299 | if ($new_uri =~ /fail_count=3/){ | ||
| 300 | $c->send_error(HTTP::Status->RC_FORBIDDEN, "fail count reached 3, url path:" . $r->url->path ); | ||
| 301 | } elsif ($new_uri =~ /redirect_count=3/){ | ||
| 302 | $c->send_response(HTTP::Response->new( 200, 'OK', undef , $content )); | ||
| 303 | } elsif ($new_uri =~ /location_redirect_count=3/){ | ||
| 304 | $c->send_basic_header(302); | ||
| 305 | $c->send_header("Location", "$new_uri" ); | ||
| 306 | $c->send_crlf; | ||
| 307 | $c->send_response("$content \n moved to $new_uri"); | ||
| 308 | } else { | ||
| 309 | $c->send_redirect( $new_uri->as_string, 301, $content ); | ||
| 310 | } | ||
| 189 | } elsif ($r->url->path eq "/timeout") { | 311 | } elsif ($r->url->path eq "/timeout") { |
| 190 | # Keep $c from being destroyed, but prevent severe leaks | 312 | # Keep $c from being destroyed, but prevent severe leaks |
| 191 | unshift @persist, $c; | 313 | unshift @persist, $c; |
| @@ -215,7 +337,7 @@ sub run_server { | |||
| 215 | return($chunk); | 337 | return($chunk); |
| 216 | })); | 338 | })); |
| 217 | } else { | 339 | } else { |
| 218 | $c->send_error(HTTP::Status->RC_FORBIDDEN); | 340 | $c->send_error(HTTP::Status->RC_FORBIDDEN, "unknown url path:" . $r->url->path ); |
| 219 | } | 341 | } |
| 220 | $c->close; | 342 | $c->close; |
| 221 | } | 343 | } |
| @@ -288,6 +410,41 @@ SKIP: { | |||
| 288 | $result = NPTest->testCmd( $cmd ); | 410 | $result = NPTest->testCmd( $cmd ); |
| 289 | is( $result->return_code, 0, $cmd); | 411 | is( $result->return_code, 0, $cmd); |
| 290 | like( $result->output, '/.*HTTP/1.1 200 OK - \d+ bytes in [\d\.]+ second.*/', "Output correct: ".$result->output ); | 412 | like( $result->output, '/.*HTTP/1.1 200 OK - \d+ bytes in [\d\.]+ second.*/', "Output correct: ".$result->output ); |
| 413 | |||
| 414 | # curlopt proxy/noproxy parsing tests, ssl disabled | ||
| 415 | { | ||
| 416 | # Make a scope and change environment variables here, to not mess them up for other tests using environment variables | ||
| 417 | |||
| 418 | local $ENV{"http_proxy"} = 'http://proxy.example.com:8080'; | ||
| 419 | $cmd = "$command -u /statuscode/200 -v"; | ||
| 420 | $result = NPTest->testCmd( $cmd ); | ||
| 421 | like( $result->output, '/.*CURLOPT_PROXY: http://proxy.example.com:8080 */', "Correctly took 'http_proxy' environment variable: ".$result->output ); | ||
| 422 | delete($ENV{"http_proxy"}); | ||
| 423 | |||
| 424 | local $ENV{"http_proxy"} = 'http://taken.proxy.example:8080'; | ||
| 425 | local $ENV{"HTTP_PROXY"} = 'http://discarded.proxy.example:8080'; | ||
| 426 | $cmd = "$command -u /statuscode/200 -v"; | ||
| 427 | $result = NPTest->testCmd( $cmd ); | ||
| 428 | like( $result->output, '/.*CURLOPT_PROXY: http://taken.proxy.example:8080 */', "Correctly took 'http_proxy' environment variable over 'HTTP_PROXY': ".$result->output ); | ||
| 429 | delete(local $ENV{"http_proxy"}); | ||
| 430 | delete(local $ENV{"HTTP_PROXY"}); | ||
| 431 | |||
| 432 | local $ENV{"http_proxy"} = 'http://discarded1.proxy.example:8080'; | ||
| 433 | local $ENV{"HTTP_PROXY"} = 'http://discarded2.proxy.example:8080'; | ||
| 434 | $cmd = "$command -u /statuscode/200 -x 'http://taken.proxy.example:8080' -v"; | ||
| 435 | $result = NPTest->testCmd( $cmd ); | ||
| 436 | like( $result->output, '/.*CURLOPT_PROXY: http://taken.proxy.example:8080 */', "Argument -x overwrote 'http_proxy' and 'HTTP_PROXY' environment variables: ".$result->output ); | ||
| 437 | delete(local $ENV{"http_proxy"}); | ||
| 438 | delete(local $ENV{"HTTP_PROXY"}); | ||
| 439 | |||
| 440 | local $ENV{"http_proxy"} = 'http://discarded1.proxy.example:8080'; | ||
| 441 | local $ENV{"HTTP_PROXY"} = 'http://discarded2.proxy.example:8080'; | ||
| 442 | $cmd = "$command -u /statuscode/200 --proxy 'http://taken.example.com:8080' -v"; | ||
| 443 | $result = NPTest->testCmd( $cmd ); | ||
| 444 | like( $result->output, '/.*CURLOPT_PROXY: http://taken.example.com:8080 */', "Argument --proxy overwrote 'http_proxy' and 'HTTP_PROXY' environment variables: ".$result->output ); | ||
| 445 | delete(local $ENV{"http_proxy"}); | ||
| 446 | delete(local $ENV{"HTTP_PROXY"}); | ||
| 447 | } | ||
| 291 | } | 448 | } |
| 292 | 449 | ||
| 293 | # and the same for SSL | 450 | # and the same for SSL |
| @@ -310,6 +467,41 @@ SKIP: { | |||
| 310 | $result = NPTest->testCmd( $cmd ); | 467 | $result = NPTest->testCmd( $cmd ); |
| 311 | is( $result->return_code, 0, $cmd); | 468 | is( $result->return_code, 0, $cmd); |
| 312 | like( $result->output, '/.*HTTP/1.1 200 OK - \d+ bytes in [\d\.]+ second.*/', "Output correct: ".$result->output ); | 469 | like( $result->output, '/.*HTTP/1.1 200 OK - \d+ bytes in [\d\.]+ second.*/', "Output correct: ".$result->output ); |
| 470 | |||
| 471 | # curlopt proxy/noproxy parsing tests, ssl enabled | ||
| 472 | { | ||
| 473 | # Make a scope and change environment variables here, to not mess them up for other tests using environment variables | ||
| 474 | |||
| 475 | local $ENV{"https_proxy"} = 'http://proxy.example.com:8080'; | ||
| 476 | $cmd = "$command -u /statuscode/200 --ssl -v"; | ||
| 477 | $result = NPTest->testCmd( $cmd ); | ||
| 478 | like( $result->output, '/.*CURLOPT_PROXY: http://proxy.example.com:8080 */', "Correctly took 'https_proxy' environment variable: ".$result->output ); | ||
| 479 | delete($ENV{"https_proxy"}); | ||
| 480 | |||
| 481 | local $ENV{"https_proxy"} = 'http://taken.proxy.example:8080'; | ||
| 482 | local $ENV{"HTTPS_PROXY"} = 'http://discarded.proxy.example:8080'; | ||
| 483 | $cmd = "$command -u /statuscode/200 --ssl -v"; | ||
| 484 | $result = NPTest->testCmd( $cmd ); | ||
| 485 | like( $result->output, '/.*CURLOPT_PROXY: http://taken.proxy.example:8080 */', "Correctly took 'https_proxy' environment variable over 'HTTPS_PROXY': ".$result->output ); | ||
| 486 | delete(local $ENV{"https_proxy"}); | ||
| 487 | delete(local $ENV{"HTTPS_PROXY"}); | ||
| 488 | |||
| 489 | local $ENV{"https_proxy"} = 'http://discarded1.proxy.example:8080'; | ||
| 490 | local $ENV{"HTTPS_PROXY"} = 'http://discarded2.proxy.example:8080'; | ||
| 491 | $cmd = "$command -u /statuscode/200 --ssl -x 'http://taken.example.com:8080' -v"; | ||
| 492 | $result = NPTest->testCmd( $cmd ); | ||
| 493 | like( $result->output, '/.*CURLOPT_PROXY: http://taken.example.com:8080 */', "Argument -x overwrote environment variables 'https_proxy' and 'HTTPS_PROXY': ".$result->output ); | ||
| 494 | delete(local $ENV{"https_proxy"}); | ||
| 495 | delete(local $ENV{"HTTPS_PROXY"}); | ||
| 496 | |||
| 497 | local $ENV{"https_proxy"} = 'http://discarded1.proxy.example:8080'; | ||
| 498 | local $ENV{"HTTPS_PROXY"} = 'http://discarded2.proxy.example:8080'; | ||
| 499 | $cmd = "$command -u /statuscode/200 --ssl --proxy 'http://taken.example.com:8080' -v"; | ||
| 500 | $result = NPTest->testCmd( $cmd ); | ||
| 501 | like( $result->output, '/.*CURLOPT_PROXY: http://taken.example.com:8080 */', "Argument --proxy overwrote environment variables 'https_proxy' and 'HTTPS_PROXY': ".$result->output ); | ||
| 502 | delete(local $ENV{"https_proxy"}); | ||
| 503 | delete(local $ENV{"HTTPS_PROXY"}); | ||
| 504 | } | ||
| 313 | } | 505 | } |
| 314 | 506 | ||
| 315 | 507 | ||
| @@ -482,6 +674,64 @@ sub run_common_tests { | |||
| 482 | is( $result->return_code, 0, $cmd); | 674 | is( $result->return_code, 0, $cmd); |
| 483 | like( $result->output, '/.*HTTP/1.1 200 OK - \d+ bytes in [\d\.]+ second.*/', "Output correct: ".$result->output ); | 675 | like( $result->output, '/.*HTTP/1.1 200 OK - \d+ bytes in [\d\.]+ second.*/', "Output correct: ".$result->output ); |
| 484 | 676 | ||
| 677 | # Redirect with increment tests. These are for checking if the url parameters, query parameters and fragment are parsed. | ||
| 678 | # The server at this point has dynamic redirection. It tries to increment values that it sees in these fields, then redirects. | ||
| 679 | # It also appends some debug log and writes it into HTTP content, pass the -vvv parameter to see them. | ||
| 680 | |||
| 681 | $cmd = "$command -u '/redirect_with_increment/path1/path2/path3/path4' --onredirect=follow -vvv"; | ||
| 682 | $result = NPTest->testCmd( "$cmd" ); | ||
| 683 | is( $result->return_code, 1, $cmd); | ||
| 684 | like( $result->output, '/.*HTTP/1.1 403 Forbidden - \d+ bytes in [\d\.]+ second.*/', "Output correct, redirect_count was not present, got redirected to / : ".$result->output ); | ||
| 685 | |||
| 686 | # redirect_count=0 is parsed as a parameter and incremented. When it goes up to 3, the redirection returns HTTP OK | ||
| 687 | $cmd = "$command -u '/redirect_with_increment/path1/path2;redirect_count=0;p1=1;p2=ab?qp1=10&qp2=kl#f1=test' --onredirect=follow -vvv"; | ||
| 688 | $result = NPTest->testCmd( "$cmd" ); | ||
| 689 | is( $result->return_code, 0, $cmd); | ||
| 690 | like( $result->output, '/.*HTTP/1.1 200 OK - \d+ bytes in [\d\.]+ second.*/', "Output correct, redirect_count went up to 3, and returned OK: ".$result->output ); | ||
| 691 | |||
| 692 | # location_redirect_count=0 goes up to 3, which uses the HTTP 302 style of redirection with 'Location' header | ||
| 693 | $cmd = "$command -u '/redirect_with_increment/path1/path2;location_redirect_count=0;p1=1;p2=ab?qp1=10&qp2=kl#f1=test' --onredirect=follow -vvv"; | ||
| 694 | $result = NPTest->testCmd( "$cmd" ); | ||
| 695 | is( $result->return_code, 0, $cmd); | ||
| 696 | like( $result->output, '/.*HTTP/1.1 200 OK - \d+ bytes in [\d\.]+ second.*/', "Output correct, location_redirect_count went up to 3: ".$result->output ); | ||
| 697 | |||
| 698 | # fail_count parameter may also go up to 3, which returns a HTTP 403 | ||
| 699 | $cmd = "$command -u '/redirect_with_increment/path1/path2;redirect_count=0;fail_count=2' --onredirect=follow -vvv"; | ||
| 700 | $result = NPTest->testCmd( "$cmd" ); | ||
| 701 | is( $result->return_code, 1, $cmd); | ||
| 702 | like( $result->output, '/.*HTTP/1.1 403 Forbidden - \d+ bytes in [\d\.]+ second.*/', "Output correct, early due to fail_count reaching 3: ".$result->output ); | ||
| 703 | |||
| 704 | # redirect_count=0, p1=1 , p2=ab => redirect_count=1, p1=2 , p2=bc => redirect_count=2, p1=3 , p2=cd => redirect_count=3 , p1=4 , p2=de | ||
| 705 | # Last visited URI returns HTTP OK instead of redirect, and the one before that contains the new_uri in its content | ||
| 706 | $cmd = "$command -u '/redirect_with_increment/path1/path2;redirect_count=0;p1=1;p2=ab?qp1=10&qp2=kl#f1=test' --onredirect=follow -vvv"; | ||
| 707 | $result = NPTest->testCmd( "$cmd" ); | ||
| 708 | is( $result->return_code, 0, $cmd); | ||
| 709 | like( $result->output, '/.*redirect_count=3;p1=4;p2=de\?*/', "Output correct, parsed and incremented both parameters p1 and p2 : ".$result->output ); | ||
| 710 | like( $result->output, '/.*HTTP/1.1 200 OK - \d+ bytes in [\d\.]+ second.*/', "Output correct, location_redirect_count went up to 3: ".$result->output ); | ||
| 711 | |||
| 712 | # Same incrementation as before, uses the query parameters that come after the first '?' : qp1 and qp2 | ||
| 713 | $cmd = "$command -u '/redirect_with_increment/path1/path2;redirect_count=0;p1=1;p2=ab?qp1=10&qp2=kl#f1=test' --onredirect=follow -vvv"; | ||
| 714 | $result = NPTest->testCmd( "$cmd" ); | ||
| 715 | is( $result->return_code, 0, $cmd); | ||
| 716 | like( $result->output, '/.*\?qp1=13&qp2=no*/', "Output correct, parsed and incremented both query parameters qp1 and qp2 : ".$result->output ); | ||
| 717 | like( $result->output, '/.*HTTP/1.1 200 OK - \d+ bytes in [\d\.]+ second.*/', "Output correct, location_redirect_count went up to 3: ".$result->output ); | ||
| 718 | |||
| 719 | # Check if the query parameter order is kept intact | ||
| 720 | $cmd = "$command -u '/redirect_with_increment;redirect_count=0;?qp0=0&qp1=1&qp2=2&qp3=3&qp4=4&qp5=5' --onredirect=follow -vvv"; | ||
| 721 | $result = NPTest->testCmd( "$cmd" ); | ||
| 722 | is( $result->return_code, 0, $cmd); | ||
| 723 | like( $result->output, '/.*\?qp0=3&qp1=4&qp2=5&qp3=6&qp4=7&qp5=8*/', "Output correct, parsed and incremented query parameters qp1,qp2,qp3,qp4,qp5 in order : ".$result->output ); | ||
| 724 | like( $result->output, '/.*HTTP/1.1 200 OK - \d+ bytes in [\d\.]+ second.*/', "Output correct, location_redirect_count went up to 3: ".$result->output ); | ||
| 725 | |||
| 726 | # The fragment is passed as another parameter. | ||
| 727 | # During the server redirects the fragment will be set to its value, if such a key is present. | ||
| 728 | # 'ebiil' => 'fcjjm' => 'gdkkn' => 'hello' | ||
| 729 | $cmd = "$command -u '/redirect_with_increment/path1/path2;redirect_count=0;fragment=ebiil?qp1=0' --onredirect=follow -vvv"; | ||
| 730 | $result = NPTest->testCmd( "$cmd" ); | ||
| 731 | is( $result->return_code, 0, $cmd); | ||
| 732 | like( $result->output, '/.*redirect_count=3;fragment=hello\?qp1=3#hello*/', "Output correct, fragments are specified by server and followed by check_curl: ".$result->output ); | ||
| 733 | like( $result->output, '/.*HTTP/1.1 200 OK - \d+ bytes in [\d\.]+ second.*/', "Output correct, location_redirect_count went up to 3: ".$result->output ); | ||
| 734 | |||
| 485 | # These tests may block | 735 | # These tests may block |
| 486 | # stickyport - on full urlS port is set back to 80 otherwise | 736 | # stickyport - on full urlS port is set back to 80 otherwise |
| 487 | $cmd = "$command -f stickyport -u /redir_external -t 5 -s redirected"; | 737 | $cmd = "$command -f stickyport -u /redir_external -t 5 -s redirected"; |
| @@ -532,4 +782,63 @@ sub run_common_tests { | |||
| 532 | $result = NPTest->testCmd( $cmd, 5 ); | 782 | $result = NPTest->testCmd( $cmd, 5 ); |
| 533 | }; | 783 | }; |
| 534 | is( $@, "", $cmd ); | 784 | is( $@, "", $cmd ); |
| 785 | |||
| 786 | # curlopt proxy/noproxy parsing tests | ||
| 787 | { | ||
| 788 | # Make a scope and change environment variables here, to not mess them up for other tests using environment variables | ||
| 789 | |||
| 790 | local $ENV{"no_proxy"} = 'internal.acme.org'; | ||
| 791 | $cmd = "$command -u /statuscode/200 -v"; | ||
| 792 | $result = NPTest->testCmd( $cmd ); | ||
| 793 | like( $result->output, '/.* curl CURLOPT_NOPROXY: internal.acme.org */', "Correctly took 'no_proxy' environment variable: ".$result->output ); | ||
| 794 | delete($ENV{"no_proxy"}); | ||
| 795 | |||
| 796 | local $ENV{"no_proxy"} = 'taken.acme.org'; | ||
| 797 | local $ENV{"NO_PROXY"} = 'discarded.acme.org'; | ||
| 798 | $cmd = "$command -u /statuscode/200 -v"; | ||
| 799 | $result = NPTest->testCmd( $cmd ); | ||
| 800 | is( $result->return_code, 0, $cmd); | ||
| 801 | like( $result->output, '/.*CURLOPT_NOPROXY: taken.acme.org*/', "Correctly took 'no_proxy' environment variable over 'NO_PROXY': ".$result->output ); | ||
| 802 | delete(local $ENV{"no_proxy"}); | ||
| 803 | delete(local $ENV{"NO_PROXY"}); | ||
| 804 | |||
| 805 | local $ENV{"no_proxy"} = 'taken.acme.org'; | ||
| 806 | local $ENV{"NO_PROXY"} = 'discarded.acme.org'; | ||
| 807 | $cmd = "$command -u /statuscode/200 --noproxy 'taken.acme.org' -v"; | ||
| 808 | $result = NPTest->testCmd( $cmd ); | ||
| 809 | is( $result->return_code, 0, $cmd); | ||
| 810 | like( $result->output, '/.*CURLOPT_NOPROXY: taken.acme.org*/', "Argument --noproxy overwrote environment variables 'no_proxy' and 'NO_PROXY': ".$result->output ); | ||
| 811 | delete(local $ENV{"no_proxy"}); | ||
| 812 | delete(local $ENV{"NO_PROXY"}); | ||
| 813 | |||
| 814 | $cmd = "$command -u /statuscode/200 --noproxy 'internal1.acme.org,internal2.acme.org,internal3.acme.org' -v"; | ||
| 815 | $result = NPTest->testCmd( $cmd ); | ||
| 816 | is( $result->return_code, 0, $cmd); | ||
| 817 | like( $result->output, '/.*CURLOPT_NOPROXY: internal1.acme.org,internal2.acme.org,internal3.acme.org*/', "Argument --noproxy read multiple noproxy domains: ".$result->output ); | ||
| 818 | |||
| 819 | $cmd = "$command -u /statuscode/200 --noproxy '10.11.12.13,256.256.256.256,0.0.0.0,192.156.0.0/22,10.0.0.0/4' -v"; | ||
| 820 | $result = NPTest->testCmd( $cmd ); | ||
| 821 | is( $result->return_code, 0, $cmd); | ||
| 822 | like( $result->output, '/.*CURLOPT_NOPROXY: 10.11.12.13,256.256.256.256,0.0.0.0,192.156.0.0/22,10.0.0.0/4*/', "Argument --noproxy took multiple noproxy domains: ".$result->output ); | ||
| 823 | |||
| 824 | $cmd = "$command -u /statuscode/200 --noproxy '0123:4567:89AB:CDEF:0123:4567:89AB:CDEF,0123::CDEF,0123:4567/96,[::1],::1,[1234::5678:ABCD/4]' -v"; | ||
| 825 | $result = NPTest->testCmd( $cmd ); | ||
| 826 | is( $result->return_code, 0, $cmd); | ||
| 827 | like( $result->output, '/.*CURLOPT_NOPROXY: 0123:4567:89AB:CDEF:0123:4567:89AB:CDEF,0123::CDEF,0123:4567\/96,\[::1\],::1,\[1234::5678:ABCD\/4\].*/', "Argument --noproxy took multiple noproxy domains: ".$result->output ); | ||
| 828 | |||
| 829 | $cmd = "$command -u /statuscode/200 --noproxy '300.400.500.600,1.2.3,XYZD:0123::,1:2:3:4:5:6:7,1::2::3,1.1.1.1/64,::/256' -v"; | ||
| 830 | $result = NPTest->testCmd( $cmd ); | ||
| 831 | is( $result->return_code, 0, $cmd); | ||
| 832 | |||
| 833 | $cmd = "$command -u /statuscode/200 --proxy http://proxy.example.com:8080 --noproxy '*' -v"; | ||
| 834 | $result = NPTest->testCmd( $cmd ); | ||
| 835 | is( $result->return_code, 0, $cmd); | ||
| 836 | like( $result->output, '/.*proxy_resolves_hostname: 0.*/', "Proxy will not be used due to '*' in noproxy: ".$result->output ); | ||
| 837 | |||
| 838 | $cmd = "$command -u /statuscode/200 --proxy http://proxy.example.com:8080 --noproxy '127.0.0.1' -v"; | ||
| 839 | $result = NPTest->testCmd( $cmd ); | ||
| 840 | is( $result->return_code, 0, $cmd); | ||
| 841 | like( $result->output, '/.*proxy_resolves_hostname: 0.*/', "Proxy will not be used due to '127.0.0.1' in noproxy: ".$result->output ); | ||
| 842 | } | ||
| 843 | |||
| 535 | } | 844 | } |
