diff options
Diffstat (limited to 'plugins/tests/check_curl.t')
| -rwxr-xr-x | plugins/tests/check_curl.t | 406 |
1 files changed, 358 insertions, 48 deletions
diff --git a/plugins/tests/check_curl.t b/plugins/tests/check_curl.t index eaa9f518..d0a866cb 100755 --- a/plugins/tests/check_curl.t +++ b/plugins/tests/check_curl.t | |||
| @@ -15,14 +15,20 @@ | |||
| 15 | # Email Address []:devel@monitoring-plugins.org | 15 | # Email Address []:devel@monitoring-plugins.org |
| 16 | 16 | ||
| 17 | use strict; | 17 | use strict; |
| 18 | use warnings; | ||
| 18 | use Test::More; | 19 | use Test::More; |
| 19 | use NPTest; | 20 | use NPTest; |
| 20 | use FindBin qw($Bin); | 21 | use FindBin qw($Bin); |
| 21 | 22 | ||
| 23 | use URI; | ||
| 24 | use URI::QueryParam; | ||
| 25 | use HTTP::Daemon; | ||
| 26 | use HTTP::Daemon::SSL; | ||
| 27 | |||
| 22 | $ENV{'LC_TIME'} = "C"; | 28 | $ENV{'LC_TIME'} = "C"; |
| 23 | 29 | ||
| 24 | my $common_tests = 75; | 30 | my $common_tests = 111; |
| 25 | my $ssl_only_tests = 8; | 31 | my $ssl_only_tests = 12; |
| 26 | # Check that all dependent modules are available | 32 | # Check that all dependent modules are available |
| 27 | eval "use HTTP::Daemon 6.01;"; | 33 | eval "use HTTP::Daemon 6.01;"; |
| 28 | plan skip_all => 'HTTP::Daemon >= 6.01 required' if $@; | 34 | plan skip_all => 'HTTP::Daemon >= 6.01 required' if $@; |
| @@ -35,7 +41,7 @@ my $plugin = 'check_http'; | |||
| 35 | $plugin = 'check_curl' if $0 =~ m/check_curl/mx; | 41 | $plugin = 'check_curl' if $0 =~ m/check_curl/mx; |
| 36 | 42 | ||
| 37 | # 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) |
| 38 | my $advanced_checks = 12; | 44 | my $advanced_checks = 16; |
| 39 | my $use_advanced_checks = 0; | 45 | my $use_advanced_checks = 0; |
| 40 | my $required_version = '7.49.0'; | 46 | my $required_version = '7.49.0'; |
| 41 | my $virtual_host = 'www.somefunnyhost.com'; | 47 | my $virtual_host = 'www.somefunnyhost.com'; |
| @@ -185,6 +191,123 @@ sub run_server { | |||
| 185 | $c->send_response('moved to /redirect2'); | 191 | $c->send_response('moved to /redirect2'); |
| 186 | } elsif ($r->url->path eq "/redir_timeout") { | 192 | } elsif ($r->url->path eq "/redir_timeout") { |
| 187 | $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 | } | ||
| 188 | } elsif ($r->url->path eq "/timeout") { | 311 | } elsif ($r->url->path eq "/timeout") { |
| 189 | # Keep $c from being destroyed, but prevent severe leaks | 312 | # Keep $c from being destroyed, but prevent severe leaks |
| 190 | unshift @persist, $c; | 313 | unshift @persist, $c; |
| @@ -214,7 +337,7 @@ sub run_server { | |||
| 214 | return($chunk); | 337 | return($chunk); |
| 215 | })); | 338 | })); |
| 216 | } else { | 339 | } else { |
| 217 | $c->send_error(HTTP::Status->RC_FORBIDDEN); | 340 | $c->send_error(HTTP::Status->RC_FORBIDDEN, "unknown url path:" . $r->url->path ); |
| 218 | } | 341 | } |
| 219 | $c->close; | 342 | $c->close; |
| 220 | } | 343 | } |
| @@ -245,21 +368,21 @@ SKIP: { | |||
| 245 | 368 | ||
| 246 | $result = NPTest->testCmd( "$command -p $port_https -S -C 14" ); | 369 | $result = NPTest->testCmd( "$command -p $port_https -S -C 14" ); |
| 247 | is( $result->return_code, 0, "$command -p $port_https -S -C 14" ); | 370 | is( $result->return_code, 0, "$command -p $port_https -S -C 14" ); |
| 248 | is( $result->output, "OK - Certificate 'Monitoring Plugins' will expire on $expiry.", "output ok" ); | 371 | like( $result->output, '/.*Certificate \'Monitoring Plugins\' will expire on ' . quotemeta($expiry) . '.*/', "output ok" ); |
| 249 | 372 | ||
| 250 | $result = NPTest->testCmd( "$command -p $port_https -S -C 14000" ); | 373 | $result = NPTest->testCmd( "$command -p $port_https -S -C 14000" ); |
| 251 | is( $result->return_code, 1, "$command -p $port_https -S -C 14000" ); | 374 | is( $result->return_code, 1, "$command -p $port_https -S -C 14000" ); |
| 252 | like( $result->output, '/WARNING - Certificate \'Monitoring Plugins\' expires in \d+ day\(s\) \(' . quotemeta($expiry) . '\)./', "output ok" ); | 375 | like( $result->output, '/.*Certificate \'Monitoring Plugins\' expires in \d+ day\(s\) \(' . quotemeta($expiry) . '\).*/', "output ok" ); |
| 253 | 376 | ||
| 254 | # Expired cert tests | 377 | # Expired cert tests |
| 255 | $result = NPTest->testCmd( "$command -p $port_https -S -C 13960,14000" ); | 378 | $result = NPTest->testCmd( "$command -p $port_https -S -C 13960,14000" ); |
| 256 | is( $result->return_code, 2, "$command -p $port_https -S -C 13960,14000" ); | 379 | is( $result->return_code, 2, "$command -p $port_https -S -C 13960,14000" ); |
| 257 | like( $result->output, '/CRITICAL - Certificate \'Monitoring Plugins\' expires in \d+ day\(s\) \(' . quotemeta($expiry) . '\)./', "output ok" ); | 380 | like( $result->output, '/.*Certificate \'Monitoring Plugins\' expires in \d+ day\(s\) \(' . quotemeta($expiry) . '\).*/', "output ok" ); |
| 258 | 381 | ||
| 259 | $result = NPTest->testCmd( "$command -p $port_https_expired -S -C 7" ); | 382 | $result = NPTest->testCmd( "$command -p $port_https_expired -S -C 7" ); |
| 260 | is( $result->return_code, 2, "$command -p $port_https_expired -S -C 7" ); | 383 | is( $result->return_code, 2, "$command -p $port_https_expired -S -C 7" ); |
| 261 | is( $result->output, | 384 | like( $result->output, |
| 262 | 'CRITICAL - Certificate \'Monitoring Plugins\' expired on Wed Jan 2 12:00:00 2008 +0000.', | 385 | '/.*Certificate \'Monitoring Plugins\' expired on Wed Jan\s+2 12:00:00 2008 \+0000.*/', |
| 263 | "output ok" ); | 386 | "output ok" ); |
| 264 | 387 | ||
| 265 | } | 388 | } |
| @@ -274,19 +397,54 @@ SKIP: { | |||
| 274 | $cmd = "./$plugin -H $virtual_host -I 127.0.0.1 -p $port_http -u /virtual_port -r ^$virtual_host:$port_http\$"; | 397 | $cmd = "./$plugin -H $virtual_host -I 127.0.0.1 -p $port_http -u /virtual_port -r ^$virtual_host:$port_http\$"; |
| 275 | $result = NPTest->testCmd( $cmd ); | 398 | $result = NPTest->testCmd( $cmd ); |
| 276 | is( $result->return_code, 0, $cmd); | 399 | is( $result->return_code, 0, $cmd); |
| 277 | like( $result->output, '/^HTTP OK: HTTP/1.1 200 OK - \d+ bytes in [\d\.]+ second/', "Output correct: ".$result->output ); | 400 | like( $result->output, '/.*HTTP/1.1 200 OK - \d+ bytes in [\d\.]+ second.*/', "Output correct: ".$result->output ); |
| 278 | 401 | ||
| 279 | # http with virtual port (!= 80) | 402 | # http with virtual port (!= 80) |
| 280 | $cmd = "./$plugin -H $virtual_host:$virtual_port -I 127.0.0.1 -p $port_http -u /virtual_port -r ^$virtual_host:$virtual_port\$"; | 403 | $cmd = "./$plugin -H $virtual_host:$virtual_port -I 127.0.0.1 -p $port_http -u /virtual_port -r ^$virtual_host:$virtual_port\$"; |
| 281 | $result = NPTest->testCmd( $cmd ); | 404 | $result = NPTest->testCmd( $cmd ); |
| 282 | is( $result->return_code, 0, $cmd); | 405 | is( $result->return_code, 0, $cmd); |
| 283 | like( $result->output, '/^HTTP OK: HTTP/1.1 200 OK - \d+ bytes in [\d\.]+ second/', "Output correct: ".$result->output ); | 406 | like( $result->output, '/.*HTTP/1.1 200 OK - \d+ bytes in [\d\.]+ second.*/', "Output correct: ".$result->output ); |
| 284 | 407 | ||
| 285 | # http with virtual port (80) | 408 | # http with virtual port (80) |
| 286 | $cmd = "./$plugin -H $virtual_host:80 -I 127.0.0.1 -p $port_http -u /virtual_port -r ^$virtual_host\$"; | 409 | $cmd = "./$plugin -H $virtual_host:80 -I 127.0.0.1 -p $port_http -u /virtual_port -r ^$virtual_host\$"; |
| 287 | $result = NPTest->testCmd( $cmd ); | 410 | $result = NPTest->testCmd( $cmd ); |
| 288 | is( $result->return_code, 0, $cmd); | 411 | is( $result->return_code, 0, $cmd); |
| 289 | like( $result->output, '/^HTTP OK: 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 | } | ||
| 290 | } | 448 | } |
| 291 | 449 | ||
| 292 | # and the same for SSL | 450 | # and the same for SSL |
| @@ -296,19 +454,54 @@ SKIP: { | |||
| 296 | $cmd = "./$plugin -H $virtual_host -I 127.0.0.1 -p $port_https --ssl -u /virtual_port -r ^$virtual_host:$port_https\$"; | 454 | $cmd = "./$plugin -H $virtual_host -I 127.0.0.1 -p $port_https --ssl -u /virtual_port -r ^$virtual_host:$port_https\$"; |
| 297 | $result = NPTest->testCmd( $cmd ); | 455 | $result = NPTest->testCmd( $cmd ); |
| 298 | is( $result->return_code, 0, $cmd); | 456 | is( $result->return_code, 0, $cmd); |
| 299 | like( $result->output, '/^HTTP OK: HTTP/1.1 200 OK - \d+ bytes in [\d\.]+ second/', "Output correct: ".$result->output ); | 457 | like( $result->output, '/.*HTTP/1.1 200 OK - \d+ bytes in [\d\.]+ second.*/', "Output correct: ".$result->output ); |
| 300 | 458 | ||
| 301 | # https with virtual port (!= 443) | 459 | # https with virtual port (!= 443) |
| 302 | $cmd = "./$plugin -H $virtual_host:$virtual_port -I 127.0.0.1 -p $port_https --ssl -u /virtual_port -r ^$virtual_host:$virtual_port\$"; | 460 | $cmd = "./$plugin -H $virtual_host:$virtual_port -I 127.0.0.1 -p $port_https --ssl -u /virtual_port -r ^$virtual_host:$virtual_port\$"; |
| 303 | $result = NPTest->testCmd( $cmd ); | 461 | $result = NPTest->testCmd( $cmd ); |
| 304 | is( $result->return_code, 0, $cmd); | 462 | is( $result->return_code, 0, $cmd); |
| 305 | like( $result->output, '/^HTTP OK: HTTP/1.1 200 OK - \d+ bytes in [\d\.]+ second/', "Output correct: ".$result->output ); | 463 | like( $result->output, '/.*HTTP/1.1 200 OK - \d+ bytes in [\d\.]+ second.*/', "Output correct: ".$result->output ); |
| 306 | 464 | ||
| 307 | # https with virtual port (443) | 465 | # https with virtual port (443) |
| 308 | $cmd = "./$plugin -H $virtual_host:443 -I 127.0.0.1 -p $port_https --ssl -u /virtual_port -r ^$virtual_host\$"; | 466 | $cmd = "./$plugin -H $virtual_host:443 -I 127.0.0.1 -p $port_https --ssl -u /virtual_port -r ^$virtual_host\$"; |
| 309 | $result = NPTest->testCmd( $cmd ); | 467 | $result = NPTest->testCmd( $cmd ); |
| 310 | is( $result->return_code, 0, $cmd); | 468 | is( $result->return_code, 0, $cmd); |
| 311 | like( $result->output, '/^HTTP OK: 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 | } | ||
| 312 | } | 505 | } |
| 313 | 506 | ||
| 314 | 507 | ||
| @@ -321,165 +514,223 @@ sub run_common_tests { | |||
| 321 | 514 | ||
| 322 | $result = NPTest->testCmd( "$command -u /file/root" ); | 515 | $result = NPTest->testCmd( "$command -u /file/root" ); |
| 323 | is( $result->return_code, 0, "/file/root"); | 516 | is( $result->return_code, 0, "/file/root"); |
| 324 | like( $result->output, '/^HTTP OK: HTTP/1.1 200 OK - 274 bytes in [\d\.]+ second/', "Output correct" ); | 517 | like( $result->output, '/.*HTTP/1.1 200 OK - 274 bytes in [\d\.]+ second.*/', "Output correct" ); |
| 325 | 518 | ||
| 326 | $result = NPTest->testCmd( "$command -u /file/root -s Root" ); | 519 | $result = NPTest->testCmd( "$command -u /file/root -s Root" ); |
| 327 | is( $result->return_code, 0, "/file/root search for string"); | 520 | is( $result->return_code, 0, "/file/root search for string"); |
| 328 | like( $result->output, '/^HTTP OK: HTTP/1.1 200 OK - 274 bytes in [\d\.]+ second/', "Output correct" ); | 521 | like( $result->output, '/.*HTTP/1.1 200 OK - 274 bytes in [\d\.]+ second.*/', "Output correct" ); |
| 329 | 522 | ||
| 330 | $result = NPTest->testCmd( "$command -u /file/root -s NonRoot" ); | 523 | $result = NPTest->testCmd( "$command -u /file/root -s NonRoot" ); |
| 331 | is( $result->return_code, 2, "Missing string check"); | 524 | is( $result->return_code, 2, "Missing string check"); |
| 332 | like( $result->output, qr%^HTTP CRITICAL: HTTP/1\.1 200 OK - string 'NonRoot' not found on 'https?://127\.0\.0\.1:\d+/file/root'%, "Shows search string and location"); | 525 | like( $result->output, qr%string 'NonRoot' not found on 'https?://127\.0\.0\.1:\d+/file/root'%, "Shows search string and location"); |
| 333 | 526 | ||
| 334 | $result = NPTest->testCmd( "$command -u /file/root -s NonRootWithOver30charsAndMoreFunThanAWetFish" ); | 527 | $result = NPTest->testCmd( "$command -u /file/root -s NonRootWithOver30charsAndMoreFunThanAWetFish" ); |
| 335 | is( $result->return_code, 2, "Missing string check"); | 528 | is( $result->return_code, 2, "Missing string check"); |
| 336 | like( $result->output, qr%HTTP CRITICAL: HTTP/1\.1 200 OK - string 'NonRootWithOver30charsAndM...' not found on 'https?://127\.0\.0\.1:\d+/file/root'%, "Shows search string and location"); | 529 | like( $result->output, qr%string 'NonRootWithOver30charsAndM...' not found on 'https?://127\.0\.0\.1:\d+/file/root'%, "Shows search string and location"); |
| 337 | 530 | ||
| 338 | $result = NPTest->testCmd( "$command -u /header_check -d foo" ); | 531 | $result = NPTest->testCmd( "$command -u /header_check -d foo" ); |
| 339 | is( $result->return_code, 0, "header_check search for string"); | 532 | is( $result->return_code, 0, "header_check search for string"); |
| 340 | like( $result->output, '/^HTTP OK: HTTP/1.1 200 OK - 96 bytes in [\d\.]+ second/', "Output correct" ); | 533 | like( $result->output, '/.*HTTP/1.1 200 OK - 96 bytes in [\d\.]+ second.*/', "Output correct" ); |
| 341 | 534 | ||
| 342 | $result = NPTest->testCmd( "$command -u /header_check -d bar" ); | 535 | $result = NPTest->testCmd( "$command -u /header_check -d bar" ); |
| 343 | is( $result->return_code, 2, "Missing header string check"); | 536 | is( $result->return_code, 2, "Missing header string check"); |
| 344 | like( $result->output, qr%^HTTP CRITICAL: HTTP/1\.1 200 OK - header 'bar' not found on 'https?://127\.0\.0\.1:\d+/header_check'%, "Shows search string and location"); | 537 | like( $result->output, qr%header 'bar' not found on 'https?://127\.0\.0\.1:\d+/header_check'%, "Shows search string and location"); |
| 345 | 538 | ||
| 346 | $result = NPTest->testCmd( "$command -u /header_broken_check" ); | 539 | $result = NPTest->testCmd( "$command -u /header_broken_check" ); |
| 347 | is( $result->return_code, 0, "header_check search for string"); | 540 | is( $result->return_code, 0, "header_check search for string"); |
| 348 | like( $result->output, '/^HTTP OK: HTTP/1.1 200 OK - 138 bytes in [\d\.]+ second/', "Output correct" ); | 541 | like( $result->output, '/.*HTTP/1.1 200 OK - \d+ bytes in [\d\.]+ second.*/', "Output correct" ); |
| 349 | 542 | ||
| 350 | my $cmd; | 543 | my $cmd; |
| 351 | $cmd = "$command -u /slow"; | 544 | $cmd = "$command -u /slow"; |
| 352 | $result = NPTest->testCmd( $cmd ); | 545 | $result = NPTest->testCmd( $cmd ); |
| 353 | is( $result->return_code, 0, "$cmd"); | 546 | is( $result->return_code, 0, "$cmd"); |
| 354 | like( $result->output, '/^HTTP OK: HTTP/1.1 200 OK - \d+ bytes in [\d\.]+ second/', "Output correct: ".$result->output ); | 547 | like( $result->output, '/.*HTTP/1.1 200 OK - \d+ bytes in [\d\.]+ second.*/', "Output correct: ".$result->output ); |
| 355 | $result->output =~ /in ([\d\.]+) second/; | 548 | $result->output =~ /in ([\d\.]+) second/; |
| 356 | cmp_ok( $1, ">", 1, "Time is > 1 second" ); | 549 | cmp_ok( $1, ">", 1, "Time is > 1 second" ); |
| 357 | 550 | ||
| 358 | $cmd = "$command -u /statuscode/200"; | 551 | $cmd = "$command -u /statuscode/200"; |
| 359 | $result = NPTest->testCmd( $cmd ); | 552 | $result = NPTest->testCmd( $cmd ); |
| 360 | is( $result->return_code, 0, $cmd); | 553 | is( $result->return_code, 0, $cmd); |
| 361 | like( $result->output, '/^HTTP OK: HTTP/1.1 200 OK - \d+ bytes in [\d\.]+ second/', "Output correct: ".$result->output ); | 554 | like( $result->output, '/.*HTTP/1.1 200 OK - \d+ bytes in [\d\.]+ second.*/', "Output correct: ".$result->output ); |
| 362 | 555 | ||
| 363 | $cmd = "$command -u /statuscode/200 -e 200"; | 556 | $cmd = "$command -u /statuscode/200 -e 200"; |
| 364 | $result = NPTest->testCmd( $cmd ); | 557 | $result = NPTest->testCmd( $cmd ); |
| 365 | is( $result->return_code, 0, $cmd); | 558 | is( $result->return_code, 0, $cmd); |
| 366 | like( $result->output, '/^HTTP OK: HTTP/1.1 200 OK - Status line output matched "200" - \d+ bytes in [\d\.]+ second/', "Output correct: ".$result->output ); | 559 | like( $result->output, '/.*Status line output matched "200".*/', "Output correct: ".$result->output ); |
| 367 | 560 | ||
| 368 | $cmd = "$command -u /statuscode/201"; | 561 | $cmd = "$command -u /statuscode/201"; |
| 369 | $result = NPTest->testCmd( $cmd ); | 562 | $result = NPTest->testCmd( $cmd ); |
| 370 | is( $result->return_code, 0, $cmd); | 563 | is( $result->return_code, 0, $cmd); |
| 371 | like( $result->output, '/^HTTP OK: HTTP/1.1 201 Created - \d+ bytes in [\d\.]+ second /', "Output correct: ".$result->output ); | 564 | like( $result->output, '/.*HTTP/1.1 201 Created - \d+ bytes in [\d\.]+ second.*/', "Output correct: ".$result->output ); |
| 372 | 565 | ||
| 373 | $cmd = "$command -u /statuscode/201 -e 201"; | 566 | $cmd = "$command -u /statuscode/201 -e 201"; |
| 374 | $result = NPTest->testCmd( $cmd ); | 567 | $result = NPTest->testCmd( $cmd ); |
| 375 | is( $result->return_code, 0, $cmd); | 568 | is( $result->return_code, 0, $cmd); |
| 376 | like( $result->output, '/^HTTP OK: HTTP/1.1 201 Created - Status line output matched "201" - \d+ bytes in [\d\.]+ second /', "Output correct: ".$result->output ); | 569 | like( $result->output, '/.*Status line output matched "201".*/', "Output correct: ".$result->output ); |
| 377 | 570 | ||
| 378 | $cmd = "$command -u /statuscode/201 -e 200"; | 571 | $cmd = "$command -u /statuscode/201 -e 200"; |
| 379 | $result = NPTest->testCmd( $cmd ); | 572 | $result = NPTest->testCmd( $cmd ); |
| 380 | is( $result->return_code, 2, $cmd); | 573 | is( $result->return_code, 2, $cmd); |
| 381 | like( $result->output, '/^HTTP CRITICAL - Invalid HTTP response received from host on port \d+: HTTP/1.1 201 Created/', "Output correct: ".$result->output ); | 574 | like( $result->output, '/.*Invalid HTTP response received from host on port \d+: HTTP/1.1 201 Created.*/', "Output correct: ".$result->output ); |
| 382 | 575 | ||
| 383 | $cmd = "$command -u /statuscode/200 -e 200,201,202"; | 576 | $cmd = "$command -u /statuscode/200 -e 200,201,202"; |
| 384 | $result = NPTest->testCmd( $cmd ); | 577 | $result = NPTest->testCmd( $cmd ); |
| 385 | is( $result->return_code, 0, $cmd); | 578 | is( $result->return_code, 0, $cmd); |
| 386 | like( $result->output, '/^HTTP OK: HTTP/1.1 200 OK - Status line output matched "200,201,202" - \d+ bytes in [\d\.]+ second/', "Output correct: ".$result->output ); | 579 | like( $result->output, '/.*Status line output matched "200,201,202".*/', "Output correct: ".$result->output ); |
| 387 | 580 | ||
| 388 | $cmd = "$command -u /statuscode/201 -e 200,201,202"; | 581 | $cmd = "$command -u /statuscode/201 -e 200,201,202"; |
| 389 | $result = NPTest->testCmd( $cmd ); | 582 | $result = NPTest->testCmd( $cmd ); |
| 390 | is( $result->return_code, 0, $cmd); | 583 | is( $result->return_code, 0, $cmd); |
| 391 | like( $result->output, '/^HTTP OK: HTTP/1.1 201 Created - Status line output matched "200,201,202" - \d+ bytes in [\d\.]+ second/', "Output correct: ".$result->output ); | 584 | like( $result->output, '/.*Status line output matched "200,201,202".*/', "Output correct: ".$result->output ); |
| 392 | 585 | ||
| 393 | $cmd = "$command -u /statuscode/203 -e 200,201,202"; | 586 | $cmd = "$command -u /statuscode/203 -e 200,201,202"; |
| 394 | $result = NPTest->testCmd( $cmd ); | 587 | $result = NPTest->testCmd( $cmd ); |
| 395 | is( $result->return_code, 2, $cmd); | 588 | is( $result->return_code, 2, $cmd); |
| 396 | like( $result->output, '/^HTTP CRITICAL - Invalid HTTP response received from host on port (\d+): HTTP/1.1 203 Non-Authoritative Information/', "Output correct: ".$result->output ); | 589 | like( $result->output, '/.*Invalid HTTP response received from host on port (\d+): HTTP/1.1 203 Non-Authoritative Information.*/', "Output correct: ".$result->output ); |
| 397 | 590 | ||
| 398 | $cmd = "$command -j HEAD -u /method"; | 591 | $cmd = "$command -j HEAD -u /method"; |
| 399 | $result = NPTest->testCmd( $cmd ); | 592 | $result = NPTest->testCmd( $cmd ); |
| 400 | is( $result->return_code, 0, $cmd); | 593 | is( $result->return_code, 0, $cmd); |
| 401 | like( $result->output, '/^HTTP OK: HTTP/1.1 200 HEAD - \d+ bytes in [\d\.]+ second/', "Output correct: ".$result->output ); | 594 | like( $result->output, '/.*HTTP/1.1 200 HEAD - \d+ bytes in [\d\.]+ second.*/', "Output correct: ".$result->output ); |
| 402 | 595 | ||
| 403 | $cmd = "$command -j POST -u /method"; | 596 | $cmd = "$command -j POST -u /method"; |
| 404 | $result = NPTest->testCmd( $cmd ); | 597 | $result = NPTest->testCmd( $cmd ); |
| 405 | is( $result->return_code, 0, $cmd); | 598 | is( $result->return_code, 0, $cmd); |
| 406 | like( $result->output, '/^HTTP OK: HTTP/1.1 200 POST - \d+ bytes in [\d\.]+ second/', "Output correct: ".$result->output ); | 599 | like( $result->output, '/.*HTTP/1.1 200 POST - \d+ bytes in [\d\.]+ second.*/', "Output correct: ".$result->output ); |
| 407 | 600 | ||
| 408 | $cmd = "$command -j GET -u /method"; | 601 | $cmd = "$command -j GET -u /method"; |
| 409 | $result = NPTest->testCmd( $cmd ); | 602 | $result = NPTest->testCmd( $cmd ); |
| 410 | is( $result->return_code, 0, $cmd); | 603 | is( $result->return_code, 0, $cmd); |
| 411 | like( $result->output, '/^HTTP OK: HTTP/1.1 200 GET - \d+ bytes in [\d\.]+ second/', "Output correct: ".$result->output ); | 604 | like( $result->output, '/.*HTTP/1.1 200 GET - \d+ bytes in [\d\.]+ second.*/', "Output correct: ".$result->output ); |
| 412 | 605 | ||
| 413 | $cmd = "$command -u /method"; | 606 | $cmd = "$command -u /method"; |
| 414 | $result = NPTest->testCmd( $cmd ); | 607 | $result = NPTest->testCmd( $cmd ); |
| 415 | is( $result->return_code, 0, $cmd); | 608 | is( $result->return_code, 0, $cmd); |
| 416 | like( $result->output, '/^HTTP OK: HTTP/1.1 200 GET - \d+ bytes in [\d\.]+ second/', "Output correct: ".$result->output ); | 609 | like( $result->output, '/.*HTTP/1.1 200 GET - \d+ bytes in [\d\.]+ second.*/', "Output correct: ".$result->output ); |
| 417 | 610 | ||
| 418 | $cmd = "$command -P foo -u /method"; | 611 | $cmd = "$command -P foo -u /method"; |
| 419 | $result = NPTest->testCmd( $cmd ); | 612 | $result = NPTest->testCmd( $cmd ); |
| 420 | is( $result->return_code, 0, $cmd); | 613 | is( $result->return_code, 0, $cmd); |
| 421 | like( $result->output, '/^HTTP OK: HTTP/1.1 200 POST - \d+ bytes in [\d\.]+ second/', "Output correct: ".$result->output ); | 614 | like( $result->output, '/.*HTTP/1.1 200 POST - \d+ bytes in [\d\.]+ second.*/', "Output correct: ".$result->output ); |
| 422 | 615 | ||
| 423 | $cmd = "$command -j DELETE -u /method"; | 616 | $cmd = "$command -j DELETE -u /method"; |
| 424 | $result = NPTest->testCmd( $cmd ); | 617 | $result = NPTest->testCmd( $cmd ); |
| 425 | is( $result->return_code, 1, $cmd); | 618 | is( $result->return_code, 1, $cmd); |
| 426 | like( $result->output, '/^HTTP WARNING: HTTP/1.1 405 Method Not Allowed/', "Output correct: ".$result->output ); | 619 | like( $result->output, '/.*HTTP/1.1 405 Method Not Allowed.*/', "Output correct: ".$result->output ); |
| 427 | 620 | ||
| 428 | $cmd = "$command -j foo -u /method"; | 621 | $cmd = "$command -j foo -u /method"; |
| 429 | $result = NPTest->testCmd( $cmd ); | 622 | $result = NPTest->testCmd( $cmd ); |
| 430 | is( $result->return_code, 2, $cmd); | 623 | is( $result->return_code, 2, $cmd); |
| 431 | like( $result->output, '/^HTTP CRITICAL: HTTP/1.1 501 Not Implemented/', "Output correct: ".$result->output ); | 624 | like( $result->output, '/.*HTTP/1.1 501 Not Implemented.*/', "Output correct: ".$result->output ); |
| 432 | 625 | ||
| 433 | $cmd = "$command -P stufftoinclude -u /postdata -s POST:stufftoinclude"; | 626 | $cmd = "$command -P stufftoinclude -u /postdata -s POST:stufftoinclude"; |
| 434 | $result = NPTest->testCmd( $cmd ); | 627 | $result = NPTest->testCmd( $cmd ); |
| 435 | is( $result->return_code, 0, $cmd); | 628 | is( $result->return_code, 0, $cmd); |
| 436 | like( $result->output, '/^HTTP OK: HTTP/1.1 200 OK - \d+ bytes in [\d\.]+ second/', "Output correct: ".$result->output ); | 629 | like( $result->output, '/.*HTTP/1.1 200 OK - \d+ bytes in [\d\.]+ second.*/', "Output correct: ".$result->output ); |
| 437 | 630 | ||
| 438 | $cmd = "$command -j PUT -P stufftoinclude -u /postdata -s PUT:stufftoinclude"; | 631 | $cmd = "$command -j PUT -P stufftoinclude -u /postdata -s PUT:stufftoinclude"; |
| 439 | $result = NPTest->testCmd( $cmd ); | 632 | $result = NPTest->testCmd( $cmd ); |
| 440 | is( $result->return_code, 0, $cmd); | 633 | is( $result->return_code, 0, $cmd); |
| 441 | like( $result->output, '/^HTTP OK: HTTP/1.1 200 OK - \d+ bytes in [\d\.]+ second/', "Output correct: ".$result->output ); | 634 | like( $result->output, '/.*HTTP/1.1 200 OK - \d+ bytes in [\d\.]+ second.*/', "Output correct: ".$result->output ); |
| 442 | 635 | ||
| 443 | # To confirm that the free doesn't segfault | 636 | # To confirm that the free doesn't segfault |
| 444 | $cmd = "$command -P stufftoinclude -j PUT -u /postdata -s PUT:stufftoinclude"; | 637 | $cmd = "$command -P stufftoinclude -j PUT -u /postdata -s PUT:stufftoinclude"; |
| 445 | $result = NPTest->testCmd( $cmd ); | 638 | $result = NPTest->testCmd( $cmd ); |
| 446 | is( $result->return_code, 0, $cmd); | 639 | is( $result->return_code, 0, $cmd); |
| 447 | like( $result->output, '/^HTTP OK: HTTP/1.1 200 OK - \d+ bytes in [\d\.]+ second/', "Output correct: ".$result->output ); | 640 | like( $result->output, '/.*HTTP/1.1 200 OK - \d+ bytes in [\d\.]+ second.*/', "Output correct: ".$result->output ); |
| 448 | 641 | ||
| 449 | $cmd = "$command -u /redirect"; | 642 | $cmd = "$command -u /redirect"; |
| 450 | $result = NPTest->testCmd( $cmd ); | 643 | $result = NPTest->testCmd( $cmd ); |
| 451 | is( $result->return_code, 0, $cmd); | 644 | is( $result->return_code, 0, $cmd); |
| 452 | like( $result->output, '/^HTTP OK: HTTP/1.1 301 Moved Permanently - \d+ bytes in [\d\.]+ second/', "Output correct: ".$result->output ); | 645 | like( $result->output, '/.*HTTP/1.1 301 Moved Permanently - \d+ bytes in [\d\.]+ second.*/', "Output correct: ".$result->output ); |
| 453 | 646 | ||
| 454 | $cmd = "$command -f follow -u /redirect"; | 647 | $cmd = "$command -f follow -u /redirect"; |
| 455 | $result = NPTest->testCmd( $cmd ); | 648 | $result = NPTest->testCmd( $cmd ); |
| 456 | is( $result->return_code, 0, $cmd); | 649 | is( $result->return_code, 0, $cmd); |
| 457 | like( $result->output, '/^HTTP OK: HTTP/1.1 200 OK - \d+ bytes in [\d\.]+ second/', "Output correct: ".$result->output ); | 650 | like( $result->output, '/.*HTTP/1.1 200 OK - \d+ bytes in [\d\.]+ second.*/', "Output correct: ".$result->output ); |
| 458 | 651 | ||
| 459 | $cmd = "$command -u /redirect -k 'follow: me'"; | 652 | $cmd = "$command -u /redirect -k 'follow: me'"; |
| 460 | $result = NPTest->testCmd( $cmd ); | 653 | $result = NPTest->testCmd( $cmd ); |
| 461 | is( $result->return_code, 0, $cmd); | 654 | is( $result->return_code, 0, $cmd); |
| 462 | like( $result->output, '/^HTTP OK: HTTP/1.1 301 Moved Permanently - \d+ bytes in [\d\.]+ second/', "Output correct: ".$result->output ); | 655 | like( $result->output, '/.*HTTP/1.1 301 Moved Permanently - \d+ bytes in [\d\.]+ second.*/', "Output correct: ".$result->output ); |
| 463 | 656 | ||
| 464 | $cmd = "$command -f follow -u /redirect -k 'follow: me'"; | 657 | $cmd = "$command -f follow -u /redirect -k 'follow: me'"; |
| 465 | $result = NPTest->testCmd( $cmd ); | 658 | $result = NPTest->testCmd( $cmd ); |
| 466 | is( $result->return_code, 0, $cmd); | 659 | is( $result->return_code, 0, $cmd); |
| 467 | like( $result->output, '/^HTTP OK: HTTP/1.1 200 OK - \d+ bytes in [\d\.]+ second/', "Output correct: ".$result->output ); | 660 | like( $result->output, '/.*HTTP/1.1 200 OK - \d+ bytes in [\d\.]+ second.*/', "Output correct: ".$result->output ); |
| 468 | 661 | ||
| 469 | $cmd = "$command -f sticky -u /redirect -k 'follow: me'"; | 662 | $cmd = "$command -f sticky -u /redirect -k 'follow: me'"; |
| 470 | $result = NPTest->testCmd( $cmd ); | 663 | $result = NPTest->testCmd( $cmd ); |
| 471 | is( $result->return_code, 0, $cmd); | 664 | is( $result->return_code, 0, $cmd); |
| 472 | like( $result->output, '/^HTTP OK: HTTP/1.1 200 OK - \d+ bytes in [\d\.]+ second/', "Output correct: ".$result->output ); | 665 | like( $result->output, '/.*HTTP/1.1 200 OK - \d+ bytes in [\d\.]+ second.*/', "Output correct: ".$result->output ); |
| 473 | 666 | ||
| 474 | $cmd = "$command -f stickyport -u /redirect -k 'follow: me'"; | 667 | $cmd = "$command -f stickyport -u /redirect -k 'follow: me'"; |
| 475 | $result = NPTest->testCmd( $cmd ); | 668 | $result = NPTest->testCmd( $cmd ); |
| 476 | is( $result->return_code, 0, $cmd); | 669 | is( $result->return_code, 0, $cmd); |
| 477 | like( $result->output, '/^HTTP OK: HTTP/1.1 200 OK - \d+ bytes in [\d\.]+ second/', "Output correct: ".$result->output ); | 670 | like( $result->output, '/.*HTTP/1.1 200 OK - \d+ bytes in [\d\.]+ second.*/', "Output correct: ".$result->output ); |
| 478 | 671 | ||
| 479 | $cmd = "$command -f follow -u /redirect_rel -s redirected"; | 672 | $cmd = "$command -f follow -u /redirect_rel -s redirected"; |
| 480 | $result = NPTest->testCmd( $cmd ); | 673 | $result = NPTest->testCmd( $cmd ); |
| 481 | is( $result->return_code, 0, $cmd); | 674 | is( $result->return_code, 0, $cmd); |
| 482 | like( $result->output, '/^HTTP OK: 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 ); |
| 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 ); | ||
| 483 | 734 | ||
| 484 | # These tests may block | 735 | # These tests may block |
| 485 | # stickyport - on full urlS port is set back to 80 otherwise | 736 | # stickyport - on full urlS port is set back to 80 otherwise |
| @@ -531,4 +782,63 @@ sub run_common_tests { | |||
| 531 | $result = NPTest->testCmd( $cmd, 5 ); | 782 | $result = NPTest->testCmd( $cmd, 5 ); |
| 532 | }; | 783 | }; |
| 533 | 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, '/.*have local name resolution: true.*/', "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, '/.*have local name resolution: true.*/', "Proxy will not be used due to '127.0.0.1' in noproxy: ".$result->output ); | ||
| 842 | } | ||
| 843 | |||
| 534 | } | 844 | } |
