diff options
Diffstat (limited to 'plugins/tests/check_curl.t')
| -rwxr-xr-x | plugins/tests/check_curl.t | 135 |
1 files changed, 132 insertions, 3 deletions
diff --git a/plugins/tests/check_curl.t b/plugins/tests/check_curl.t index 248eb4c5..94058d5b 100755 --- a/plugins/tests/check_curl.t +++ b/plugins/tests/check_curl.t | |||
| @@ -27,8 +27,8 @@ use HTTP::Daemon::SSL; | |||
| 27 | 27 | ||
| 28 | $ENV{'LC_TIME'} = "C"; | 28 | $ENV{'LC_TIME'} = "C"; |
| 29 | 29 | ||
| 30 | my $common_tests = 95; | 30 | my $common_tests = 111; |
| 31 | my $ssl_only_tests = 8; | 31 | my $ssl_only_tests = 12; |
| 32 | # Check that all dependent modules are available | 32 | # Check that all dependent modules are available |
| 33 | eval "use HTTP::Daemon 6.01;"; | 33 | eval "use HTTP::Daemon 6.01;"; |
| 34 | plan skip_all => 'HTTP::Daemon >= 6.01 required' if $@; | 34 | plan skip_all => 'HTTP::Daemon >= 6.01 required' if $@; |
| @@ -41,7 +41,7 @@ my $plugin = 'check_http'; | |||
| 41 | $plugin = 'check_curl' if $0 =~ m/check_curl/mx; | 41 | $plugin = 'check_curl' if $0 =~ m/check_curl/mx; |
| 42 | 42 | ||
| 43 | # 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) |
| 44 | my $advanced_checks = 12; | 44 | my $advanced_checks = 16; |
| 45 | my $use_advanced_checks = 0; | 45 | my $use_advanced_checks = 0; |
| 46 | my $required_version = '7.49.0'; | 46 | my $required_version = '7.49.0'; |
| 47 | my $virtual_host = 'www.somefunnyhost.com'; | 47 | my $virtual_host = 'www.somefunnyhost.com'; |
| @@ -410,6 +410,41 @@ SKIP: { | |||
| 410 | $result = NPTest->testCmd( $cmd ); | 410 | $result = NPTest->testCmd( $cmd ); |
| 411 | is( $result->return_code, 0, $cmd); | 411 | is( $result->return_code, 0, $cmd); |
| 412 | 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 | } | ||
| 413 | } | 448 | } |
| 414 | 449 | ||
| 415 | # and the same for SSL | 450 | # and the same for SSL |
| @@ -432,6 +467,41 @@ SKIP: { | |||
| 432 | $result = NPTest->testCmd( $cmd ); | 467 | $result = NPTest->testCmd( $cmd ); |
| 433 | is( $result->return_code, 0, $cmd); | 468 | is( $result->return_code, 0, $cmd); |
| 434 | 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 | } | ||
| 435 | } | 505 | } |
| 436 | 506 | ||
| 437 | 507 | ||
| @@ -712,4 +782,63 @@ sub run_common_tests { | |||
| 712 | $result = NPTest->testCmd( $cmd, 5 ); | 782 | $result = NPTest->testCmd( $cmd, 5 ); |
| 713 | }; | 783 | }; |
| 714 | 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 | |||
| 715 | } | 844 | } |
