diff options
Diffstat (limited to 'plugins/tests/check_http.t')
-rwxr-xr-x | plugins/tests/check_http.t | 70 |
1 files changed, 56 insertions, 14 deletions
diff --git a/plugins/tests/check_http.t b/plugins/tests/check_http.t index 1bc0ecb7..2f051fad 100755 --- a/plugins/tests/check_http.t +++ b/plugins/tests/check_http.t | |||
@@ -4,13 +4,15 @@ | |||
4 | # | 4 | # |
5 | # To create the https server certificate: | 5 | # To create the https server certificate: |
6 | # openssl req -new -x509 -keyout server-key.pem -out server-cert.pem -days 3650 -nodes | 6 | # openssl req -new -x509 -keyout server-key.pem -out server-cert.pem -days 3650 -nodes |
7 | # Country Name (2 letter code) [AU]:UK | 7 | # to create a new expired certificate: |
8 | # State or Province Name (full name) [Some-State]:Derbyshire | 8 | # faketime '2008-01-01 12:00:00' openssl req -new -x509 -keyout expired-key.pem -out expired-cert.pem -days 1 -nodes |
9 | # Locality Name (eg, city) []:Belper | 9 | # Country Name (2 letter code) [AU]:DE |
10 | # State or Province Name (full name) [Some-State]:Bavaria | ||
11 | # Locality Name (eg, city) []:Munich | ||
10 | # Organization Name (eg, company) [Internet Widgits Pty Ltd]:Monitoring Plugins | 12 | # Organization Name (eg, company) [Internet Widgits Pty Ltd]:Monitoring Plugins |
11 | # Organizational Unit Name (eg, section) []: | 13 | # Organizational Unit Name (eg, section) []: |
12 | # Common Name (eg, YOUR name) []:Ton Voon | 14 | # Common Name (e.g. server FQDN or YOUR name) []:Monitoring Plugins |
13 | # Email Address []:tonvoon@mac.com | 15 | # Email Address []:devel@monitoring-plugins.org |
14 | 16 | ||
15 | use strict; | 17 | use strict; |
16 | use Test::More; | 18 | use Test::More; |
@@ -20,6 +22,7 @@ use FindBin qw($Bin); | |||
20 | $ENV{'LC_TIME'} = "C"; | 22 | $ENV{'LC_TIME'} = "C"; |
21 | 23 | ||
22 | my $common_tests = 70; | 24 | my $common_tests = 70; |
25 | my $virtual_port_tests = 8; | ||
23 | my $ssl_only_tests = 8; | 26 | my $ssl_only_tests = 8; |
24 | # Check that all dependent modules are available | 27 | # Check that all dependent modules are available |
25 | eval "use HTTP::Daemon 6.01;"; | 28 | eval "use HTTP::Daemon 6.01;"; |
@@ -29,13 +32,16 @@ eval { | |||
29 | require HTTP::Response; | 32 | require HTTP::Response; |
30 | }; | 33 | }; |
31 | 34 | ||
35 | my $plugin = 'check_http'; | ||
36 | $plugin = 'check_curl' if $0 =~ m/check_curl/mx; | ||
37 | |||
32 | if ($@) { | 38 | if ($@) { |
33 | plan skip_all => "Missing required module for test: $@"; | 39 | plan skip_all => "Missing required module for test: $@"; |
34 | } else { | 40 | } else { |
35 | if (-x "./check_http") { | 41 | if (-x "./$plugin") { |
36 | plan tests => $common_tests * 2 + $ssl_only_tests; | 42 | plan tests => $common_tests * 2 + $ssl_only_tests + $virtual_port_tests; |
37 | } else { | 43 | } else { |
38 | plan skip_all => "No check_http compiled"; | 44 | plan skip_all => "No $plugin compiled"; |
39 | } | 45 | } |
40 | } | 46 | } |
41 | 47 | ||
@@ -158,6 +164,11 @@ sub run_server { | |||
158 | $c->send_basic_header; | 164 | $c->send_basic_header; |
159 | $c->send_header('foo'); | 165 | $c->send_header('foo'); |
160 | $c->send_crlf; | 166 | $c->send_crlf; |
167 | } elsif ($r->url->path eq "/virtual_port") { | ||
168 | # return sent Host header | ||
169 | $c->send_basic_header; | ||
170 | $c->send_crlf; | ||
171 | $c->send_response(HTTP::Response->new( 200, 'OK', undef, $r->header ('Host'))); | ||
161 | } else { | 172 | } else { |
162 | $c->send_error(HTTP::Status->RC_FORBIDDEN); | 173 | $c->send_error(HTTP::Status->RC_FORBIDDEN); |
163 | } | 174 | } |
@@ -179,7 +190,7 @@ if ($ARGV[0] && $ARGV[0] eq "-d") { | |||
179 | } | 190 | } |
180 | 191 | ||
181 | my $result; | 192 | my $result; |
182 | my $command = "./check_http -H 127.0.0.1"; | 193 | my $command = "./$plugin -H 127.0.0.1"; |
183 | 194 | ||
184 | run_common_tests( { command => "$command -p $port_http" } ); | 195 | run_common_tests( { command => "$command -p $port_http" } ); |
185 | SKIP: { | 196 | SKIP: { |
@@ -188,25 +199,56 @@ SKIP: { | |||
188 | 199 | ||
189 | $result = NPTest->testCmd( "$command -p $port_https -S -C 14" ); | 200 | $result = NPTest->testCmd( "$command -p $port_https -S -C 14" ); |
190 | is( $result->return_code, 0, "$command -p $port_https -S -C 14" ); | 201 | is( $result->return_code, 0, "$command -p $port_https -S -C 14" ); |
191 | is( $result->output, 'OK - Certificate \'Ton Voon\' will expire on Sun Mar 3 21:41:28 2019 +0000.', "output ok" ); | 202 | is( $result->output, "OK - Certificate 'Monitoring Plugins' will expire on Fri Feb 16 15:31:44 2029 +0000.", "output ok" ); |
192 | 203 | ||
193 | $result = NPTest->testCmd( "$command -p $port_https -S -C 14000" ); | 204 | $result = NPTest->testCmd( "$command -p $port_https -S -C 14000" ); |
194 | is( $result->return_code, 1, "$command -p $port_https -S -C 14000" ); | 205 | is( $result->return_code, 1, "$command -p $port_https -S -C 14000" ); |
195 | like( $result->output, '/WARNING - Certificate \'Ton Voon\' expires in \d+ day\(s\) \(Sun Mar 3 21:41:28 2019 \+0000\)./', "output ok" ); | 206 | like( $result->output, '/WARNING - Certificate \'Monitoring Plugins\' expires in \d+ day\(s\) \(Fri Feb 16 15:31:44 2029 \+0000\)./', "output ok" ); |
196 | 207 | ||
197 | # Expired cert tests | 208 | # Expired cert tests |
198 | $result = NPTest->testCmd( "$command -p $port_https -S -C 13960,14000" ); | 209 | $result = NPTest->testCmd( "$command -p $port_https -S -C 13960,14000" ); |
199 | is( $result->return_code, 2, "$command -p $port_https -S -C 13960,14000" ); | 210 | is( $result->return_code, 2, "$command -p $port_https -S -C 13960,14000" ); |
200 | like( $result->output, '/CRITICAL - Certificate \'Ton Voon\' expires in \d+ day\(s\) \(Sun Mar 3 21:41:28 2019 \+0000\)./', "output ok" ); | 211 | like( $result->output, '/CRITICAL - Certificate \'Monitoring Plugins\' expires in \d+ day\(s\) \(Fri Feb 16 15:31:44 2029 \+0000\)./', "output ok" ); |
201 | 212 | ||
202 | $result = NPTest->testCmd( "$command -p $port_https_expired -S -C 7" ); | 213 | $result = NPTest->testCmd( "$command -p $port_https_expired -S -C 7" ); |
203 | is( $result->return_code, 2, "$command -p $port_https_expired -S -C 7" ); | 214 | is( $result->return_code, 2, "$command -p $port_https_expired -S -C 7" ); |
204 | is( $result->output, | 215 | is( $result->output, |
205 | 'CRITICAL - Certificate \'Ton Voon\' expired on Thu Mar 5 00:13:16 2009 +0000.', | 216 | 'CRITICAL - Certificate \'Monitoring Plugins\' expired on Wed Jan 2 11:00:26 2008 +0000.', |
206 | "output ok" ); | 217 | "output ok" ); |
207 | 218 | ||
208 | } | 219 | } |
209 | 220 | ||
221 | my $cmd; | ||
222 | # check virtual port behaviour | ||
223 | # | ||
224 | # http without virtual port | ||
225 | $cmd = "$command -p $port_http -u /virtual_port -r ^127.0.0.1:$port_http\$"; | ||
226 | $result = NPTest->testCmd( $cmd ); | ||
227 | is( $result->return_code, 0, $cmd); | ||
228 | like( $result->output, '/^HTTP OK: HTTP/1.1 200 OK - \d+ bytes in [\d\.]+ second/', "Output correct: ".$result->output ); | ||
229 | |||
230 | # http with virtual port | ||
231 | $cmd = "$command:80 -p $port_http -u /virtual_port -r ^127.0.0.1\$"; | ||
232 | $result = NPTest->testCmd( $cmd ); | ||
233 | is( $result->return_code, 0, $cmd); | ||
234 | like( $result->output, '/^HTTP OK: HTTP/1.1 200 OK - \d+ bytes in [\d\.]+ second/', "Output correct: ".$result->output ); | ||
235 | |||
236 | SKIP: { | ||
237 | skip "HTTP::Daemon::SSL not installed", 4 if ! exists $servers->{https}; | ||
238 | # https without virtual port | ||
239 | $cmd = "$command -p $port_https --ssl -u /virtual_port -r ^127.0.0.1:$port_https\$"; | ||
240 | $result = NPTest->testCmd( $cmd ); | ||
241 | is( $result->return_code, 0, $cmd); | ||
242 | like( $result->output, '/^HTTP OK: HTTP/1.1 200 OK - \d+ bytes in [\d\.]+ second/', "Output correct: ".$result->output ); | ||
243 | |||
244 | # https with virtual port | ||
245 | $cmd = "$command:443 -p $port_https --ssl -u /virtual_port -r ^127.0.0.1\$"; | ||
246 | $result = NPTest->testCmd( $cmd ); | ||
247 | is( $result->return_code, 0, $cmd); | ||
248 | like( $result->output, '/^HTTP OK: HTTP/1.1 200 OK - \d+ bytes in [\d\.]+ second/', "Output correct: ".$result->output ); | ||
249 | } | ||
250 | |||
251 | |||
210 | sub run_common_tests { | 252 | sub run_common_tests { |
211 | my ($opts) = @_; | 253 | my ($opts) = @_; |
212 | my $command = $opts->{command}; | 254 | my $command = $opts->{command}; |
@@ -392,7 +434,7 @@ sub run_common_tests { | |||
392 | 434 | ||
393 | # Test an external address - timeout | 435 | # Test an external address - timeout |
394 | SKIP: { | 436 | SKIP: { |
395 | skip "This doesn't seems to work all the time", 1 unless ($ENV{HTTP_EXTERNAL}); | 437 | skip "This doesn't seem to work all the time", 1 unless ($ENV{HTTP_EXTERNAL}); |
396 | $cmd = "$command -f follow -u /redir_external -t 5"; | 438 | $cmd = "$command -f follow -u /redir_external -t 5"; |
397 | eval { | 439 | eval { |
398 | $result = NPTest->testCmd( $cmd, 2 ); | 440 | $result = NPTest->testCmd( $cmd, 2 ); |