diff options
Diffstat (limited to 'plugins/t/check_curl.t')
| -rw-r--r-- | plugins/t/check_curl.t | 58 |
1 files changed, 36 insertions, 22 deletions
diff --git a/plugins/t/check_curl.t b/plugins/t/check_curl.t index 4bff538a..eae98cc1 100644 --- a/plugins/t/check_curl.t +++ b/plugins/t/check_curl.t | |||
| @@ -1,15 +1,22 @@ | |||
| 1 | #! /usr/bin/perl -w -I .. | 1 | #! /usr/bin/perl -w -I .. |
| 2 | # | 2 | # |
| 3 | # HyperText Transfer Protocol (HTTP) Test via check_http | 3 | # HyperText Transfer Protocol (HTTP) Test via check_curl |
| 4 | # | 4 | # |
| 5 | # | 5 | # |
| 6 | 6 | ||
| 7 | use strict; | 7 | use strict; |
| 8 | use Test::More; | 8 | use Test::More; |
| 9 | use POSIX qw/mktime strftime/; | 9 | use POSIX qw/mktime strftime/; |
| 10 | use NPTest; | ||
| 11 | 10 | ||
| 12 | plan tests => 57; | 11 | use vars qw($tests $has_ipv6); |
| 12 | |||
| 13 | BEGIN { | ||
| 14 | use NPTest; | ||
| 15 | $has_ipv6 = NPTest::has_ipv6(); | ||
| 16 | $tests = $has_ipv6 ? 59 : 57; | ||
| 17 | plan tests => $tests; | ||
| 18 | } | ||
| 19 | |||
| 13 | 20 | ||
| 14 | my $successOutput = '/OK.*HTTP.*second/'; | 21 | my $successOutput = '/OK.*HTTP.*second/'; |
| 15 | 22 | ||
| @@ -18,6 +25,7 @@ my $plugin = 'check_http'; | |||
| 18 | $plugin = 'check_curl' if $0 =~ m/check_curl/mx; | 25 | $plugin = 'check_curl' if $0 =~ m/check_curl/mx; |
| 19 | 26 | ||
| 20 | my $host_tcp_http = getTestParameter("NP_HOST_TCP_HTTP", "A host providing the HTTP Service (a web server)", "localhost"); | 27 | my $host_tcp_http = getTestParameter("NP_HOST_TCP_HTTP", "A host providing the HTTP Service (a web server)", "localhost"); |
| 28 | my $host_tcp_http_ipv6 = getTestParameter("NP_HOST_TCP_HTTP_IPV6", "An IPv6 address providing a HTTP Service (a web server)", "::1"); | ||
| 21 | my $host_tls_http = getTestParameter("NP_HOST_TLS_HTTP", "A host providing the HTTPS Service (a tls web server)", "localhost"); | 29 | my $host_tls_http = getTestParameter("NP_HOST_TLS_HTTP", "A host providing the HTTPS Service (a tls web server)", "localhost"); |
| 22 | my $host_tls_cert = getTestParameter("NP_HOST_TLS_CERT", "the common name of the certificate.", "localhost"); | 30 | my $host_tls_cert = getTestParameter("NP_HOST_TLS_CERT", "the common name of the certificate.", "localhost"); |
| 23 | my $host_nonresponsive = getTestParameter("NP_HOST_NONRESPONSIVE", "The hostname of system not responsive to network requests", "10.0.0.1"); | 31 | my $host_nonresponsive = getTestParameter("NP_HOST_NONRESPONSIVE", "The hostname of system not responsive to network requests", "10.0.0.1"); |
| @@ -31,32 +39,41 @@ my $faketime = -x '/usr/bin/faketime' ? 1 : 0; | |||
| 31 | 39 | ||
| 32 | 40 | ||
| 33 | $res = NPTest->testCmd( | 41 | $res = NPTest->testCmd( |
| 34 | "./$plugin $host_tcp_http -wt 300 -ct 600" | 42 | "./$plugin $host_tcp_http -wt 300 -ct 600" |
| 35 | ); | 43 | ); |
| 36 | cmp_ok( $res->return_code, '==', 0, "Webserver $host_tcp_http responded" ); | 44 | cmp_ok( $res->return_code, '==', 0, "Webserver $host_tcp_http responded" ); |
| 37 | like( $res->output, $successOutput, "Output OK" ); | 45 | like( $res->output, $successOutput, "Output OK" ); |
| 38 | 46 | ||
| 47 | if ($has_ipv6) { | ||
| 48 | # Test for IPv6 formatting | ||
| 49 | $res = NPTest->testCmd( | ||
| 50 | "./$plugin -I $host_tcp_http_ipv6 -wt 300 -ct 600" | ||
| 51 | ); | ||
| 52 | cmp_ok( $res->return_code, '==', 0, "IPv6 URL formatting is working" ); | ||
| 53 | like( $res->output, $successOutput, "Output OK" ); | ||
| 54 | } | ||
| 55 | |||
| 39 | $res = NPTest->testCmd( | 56 | $res = NPTest->testCmd( |
| 40 | "./$plugin $host_tcp_http -wt 300 -ct 600 -v -v -v -k 'bob:there' -k 'carl:frown'" | 57 | "./$plugin $host_tcp_http -wt 300 -ct 600 -v -v -v -k 'bob:there' -k 'carl:frown'" |
| 41 | ); | 58 | ); |
| 42 | like( $res->output, '/bob:there\r\ncarl:frown\r\n/', "Got headers with multiple -k options" ); | 59 | like( $res->output, '/bob:there\r\ncarl:frown\r\n/', "Got headers with multiple -k options" ); |
| 43 | 60 | ||
| 44 | $res = NPTest->testCmd( | 61 | $res = NPTest->testCmd( |
| 45 | "./$plugin $host_nonresponsive -wt 1 -ct 2 -t 3" | 62 | "./$plugin $host_nonresponsive -wt 1 -ct 2 -t 3" |
| 46 | ); | 63 | ); |
| 47 | cmp_ok( $res->return_code, '==', 2, "Webserver $host_nonresponsive not responding" ); | 64 | cmp_ok( $res->return_code, '==', 2, "Webserver $host_nonresponsive not responding" ); |
| 48 | # was CRITICAL only, but both check_curl and check_http print HTTP CRITICAL (puzzle?!) | 65 | # was CRITICAL only, but both check_curl and check_http print HTTP CRITICAL (puzzle?!) |
| 49 | cmp_ok( $res->output, 'eq', "HTTP CRITICAL - Invalid HTTP response received from host on port 80: cURL returned 28 - Timeout was reached", "Output OK"); | 66 | like( $res->output, "/HTTP CRITICAL - Invalid HTTP response received from host on port 80: cURL returned 28 - Connection timed out after/", "Output OK"); |
| 50 | 67 | ||
| 51 | $res = NPTest->testCmd( | 68 | $res = NPTest->testCmd( |
| 52 | "./$plugin $hostname_invalid -wt 1 -ct 2" | 69 | "./$plugin $hostname_invalid -wt 1 -ct 2" |
| 53 | ); | 70 | ); |
| 54 | cmp_ok( $res->return_code, '==', 2, "Webserver $hostname_invalid not valid" ); | 71 | cmp_ok( $res->return_code, '==', 2, "Webserver $hostname_invalid not valid" ); |
| 55 | # The first part of the message comes from the OS catalogue, so cannot check this. | 72 | # The first part of the message comes from the OS catalogue, so cannot check this. |
| 56 | # On Debian, it is Name or service not known, on Darwin, it is No address associated with nodename | 73 | # On Debian, it is Name or service not known, on Darwin, it is No address associated with nodename |
| 57 | # Is also possible to get a socket timeout if DNS is not responding fast enough | 74 | # Is also possible to get a socket timeout if DNS is not responding fast enough |
| 58 | # cURL gives us consistent strings from it's own 'lib/strerror.c' | 75 | # cURL gives us consistent strings from it's own 'lib/strerror.c' |
| 59 | like( $res->output, "/cURL returned 6 - Couldn't resolve host name/", "Output OK"); | 76 | like( $res->output, "/cURL returned 6 - Could not resolve host:/", "Output OK"); |
| 60 | 77 | ||
| 61 | # host header checks | 78 | # host header checks |
| 62 | $res = NPTest->testCmd("./$plugin -v -H $host_tcp_http"); | 79 | $res = NPTest->testCmd("./$plugin -v -H $host_tcp_http"); |
| @@ -84,7 +101,7 @@ like( $res->output, '/^Host: testhost:8001\s*$/ms', "Host Header OK" ); | |||
| 84 | like( $res->output, '/CURLOPT_URL: http:\/\/'.$host_tcp_http.':80\//ms', "Url OK" ); | 101 | like( $res->output, '/CURLOPT_URL: http:\/\/'.$host_tcp_http.':80\//ms', "Url OK" ); |
| 85 | 102 | ||
| 86 | SKIP: { | 103 | SKIP: { |
| 87 | skip "No internet access", 3 if $internet_access eq "no"; | 104 | skip "No internet access", 4 if $internet_access eq "no"; |
| 88 | 105 | ||
| 89 | $res = NPTest->testCmd("./$plugin -v -H $host_tls_http -S"); | 106 | $res = NPTest->testCmd("./$plugin -v -H $host_tls_http -S"); |
| 90 | like( $res->output, '/^Host: '.$host_tls_http.'\s*$/ms', "Host Header OK" ); | 107 | like( $res->output, '/^Host: '.$host_tls_http.'\s*$/ms', "Host Header OK" ); |
| @@ -94,6 +111,9 @@ SKIP: { | |||
| 94 | 111 | ||
| 95 | $res = NPTest->testCmd("./$plugin -v -H $host_tls_http:443 -S -p 443"); | 112 | $res = NPTest->testCmd("./$plugin -v -H $host_tls_http:443 -S -p 443"); |
| 96 | like( $res->output, '/^Host: '.$host_tls_http.'\s*$/ms', "Host Header OK" ); | 113 | like( $res->output, '/^Host: '.$host_tls_http.'\s*$/ms', "Host Header OK" ); |
| 114 | |||
| 115 | $res = NPTest->testCmd("./$plugin -v -H $host_tls_http -D -S -p 443"); | ||
| 116 | like( $res->output, '/(^Host: '.$host_tls_http.'\s*$)|(cURL returned 60)/ms', "Host Header OK" ); | ||
| 97 | }; | 117 | }; |
| 98 | 118 | ||
| 99 | SKIP: { | 119 | SKIP: { |
| @@ -117,7 +137,7 @@ SKIP: { | |||
| 117 | cmp_ok( $res->return_code, "==", 0, "And also when not found"); | 137 | cmp_ok( $res->return_code, "==", 0, "And also when not found"); |
| 118 | } | 138 | } |
| 119 | SKIP: { | 139 | SKIP: { |
| 120 | skip "No internet access", 16 if $internet_access eq "no"; | 140 | skip "No internet access", 28 if $internet_access eq "no"; |
| 121 | 141 | ||
| 122 | $res = NPTest->testCmd( | 142 | $res = NPTest->testCmd( |
| 123 | "./$plugin --ssl $host_tls_http" | 143 | "./$plugin --ssl $host_tls_http" |
| @@ -185,13 +205,7 @@ SKIP: { | |||
| 185 | like ( $res->output, '/time_connect=[\d\.]+/', 'Extended Performance Data Output OK' ); | 205 | like ( $res->output, '/time_connect=[\d\.]+/', 'Extended Performance Data Output OK' ); |
| 186 | like ( $res->output, '/time_ssl=[\d\.]+/', 'Extended Performance Data SSL Output OK' ); | 206 | like ( $res->output, '/time_ssl=[\d\.]+/', 'Extended Performance Data SSL Output OK' ); |
| 187 | 207 | ||
| 188 | $res = NPTest->testCmd( | 208 | $res = NPTest->testCmd( "./$plugin -H www.mozilla.com -u /firefox -f curl" ); |
| 189 | "./$plugin --ssl -H www.e-paycobalt.com" | ||
| 190 | ); | ||
| 191 | cmp_ok( $res->return_code, "==", 0, "Can read https for www.e-paycobalt.com (uses AES certificate)" ); | ||
| 192 | |||
| 193 | |||
| 194 | $res = NPTest->testCmd( "./$plugin -H www.mozilla.com -u /firefox -f follow" ); | ||
| 195 | is( $res->return_code, 0, "Redirection based on location is okay"); | 209 | is( $res->return_code, 0, "Redirection based on location is okay"); |
| 196 | 210 | ||
| 197 | $res = NPTest->testCmd( "./$plugin -H www.mozilla.com --extended-perfdata" ); | 211 | $res = NPTest->testCmd( "./$plugin -H www.mozilla.com --extended-perfdata" ); |
