diff options
Diffstat (limited to 'plugins/tests/check_http.t')
-rwxr-xr-x | plugins/tests/check_http.t | 46 |
1 files changed, 28 insertions, 18 deletions
diff --git a/plugins/tests/check_http.t b/plugins/tests/check_http.t index d6d31de..188f5e7 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; |
@@ -30,13 +32,16 @@ eval { | |||
30 | require HTTP::Response; | 32 | require HTTP::Response; |
31 | }; | 33 | }; |
32 | 34 | ||
35 | my $plugin = 'check_http'; | ||
36 | $plugin = 'check_curl' if $0 =~ m/check_curl/mx; | ||
37 | |||
33 | if ($@) { | 38 | if ($@) { |
34 | plan skip_all => "Missing required module for test: $@"; | 39 | plan skip_all => "Missing required module for test: $@"; |
35 | } else { | 40 | } else { |
36 | if (-x "./check_http") { | 41 | if (-x "./$plugin") { |
37 | plan tests => $common_tests * 2 + $ssl_only_tests + $virtual_port_tests; | 42 | plan tests => $common_tests * 2 + $ssl_only_tests + $virtual_port_tests; |
38 | } else { | 43 | } else { |
39 | plan skip_all => "No check_http compiled"; | 44 | plan skip_all => "No $plugin compiled"; |
40 | } | 45 | } |
41 | } | 46 | } |
42 | 47 | ||
@@ -86,6 +91,8 @@ if ($pid) { | |||
86 | exit; | 91 | exit; |
87 | } | 92 | } |
88 | } else { | 93 | } else { |
94 | # closing the connection after -C cert checks make the daemon exit with a sigpipe otherwise | ||
95 | local $SIG{'PIPE'} = 'IGNORE'; | ||
89 | my $d = HTTP::Daemon::SSL->new( | 96 | my $d = HTTP::Daemon::SSL->new( |
90 | LocalPort => $port_https, | 97 | LocalPort => $port_https, |
91 | LocalAddr => "127.0.0.1", | 98 | LocalAddr => "127.0.0.1", |
@@ -97,8 +104,6 @@ if ($pid) { | |||
97 | exit; | 104 | exit; |
98 | } | 105 | } |
99 | } | 106 | } |
100 | # give our webservers some time to startup | ||
101 | sleep(1); | ||
102 | } else { | 107 | } else { |
103 | # Child | 108 | # Child |
104 | #print "child\n"; | 109 | #print "child\n"; |
@@ -111,6 +116,9 @@ if ($pid) { | |||
111 | exit; | 116 | exit; |
112 | } | 117 | } |
113 | 118 | ||
119 | # give our webservers some time to startup | ||
120 | sleep(3); | ||
121 | |||
114 | # Run the same server on http and https | 122 | # Run the same server on http and https |
115 | sub run_server { | 123 | sub run_server { |
116 | my $d = shift; | 124 | my $d = shift; |
@@ -185,7 +193,7 @@ if ($ARGV[0] && $ARGV[0] eq "-d") { | |||
185 | } | 193 | } |
186 | 194 | ||
187 | my $result; | 195 | my $result; |
188 | my $command = "./check_http -H 127.0.0.1"; | 196 | my $command = "./$plugin -H 127.0.0.1"; |
189 | 197 | ||
190 | run_common_tests( { command => "$command -p $port_http" } ); | 198 | run_common_tests( { command => "$command -p $port_http" } ); |
191 | SKIP: { | 199 | SKIP: { |
@@ -194,21 +202,21 @@ SKIP: { | |||
194 | 202 | ||
195 | $result = NPTest->testCmd( "$command -p $port_https -S -C 14" ); | 203 | $result = NPTest->testCmd( "$command -p $port_https -S -C 14" ); |
196 | is( $result->return_code, 0, "$command -p $port_https -S -C 14" ); | 204 | is( $result->return_code, 0, "$command -p $port_https -S -C 14" ); |
197 | is( $result->output, 'OK - Certificate \'Ton Voon\' will expire on Sun Mar 3 21:41:28 2019 +0000.', "output ok" ); | 205 | is( $result->output, "OK - Certificate 'Monitoring Plugins' will expire on Fri Feb 16 15:31:44 2029 +0000.", "output ok" ); |
198 | 206 | ||
199 | $result = NPTest->testCmd( "$command -p $port_https -S -C 14000" ); | 207 | $result = NPTest->testCmd( "$command -p $port_https -S -C 14000" ); |
200 | is( $result->return_code, 1, "$command -p $port_https -S -C 14000" ); | 208 | is( $result->return_code, 1, "$command -p $port_https -S -C 14000" ); |
201 | like( $result->output, '/WARNING - Certificate \'Ton Voon\' expires in \d+ day\(s\) \(Sun Mar 3 21:41:28 2019 \+0000\)./', "output ok" ); | 209 | like( $result->output, '/WARNING - Certificate \'Monitoring Plugins\' expires in \d+ day\(s\) \(Fri Feb 16 15:31:44 2029 \+0000\)./', "output ok" ); |
202 | 210 | ||
203 | # Expired cert tests | 211 | # Expired cert tests |
204 | $result = NPTest->testCmd( "$command -p $port_https -S -C 13960,14000" ); | 212 | $result = NPTest->testCmd( "$command -p $port_https -S -C 13960,14000" ); |
205 | is( $result->return_code, 2, "$command -p $port_https -S -C 13960,14000" ); | 213 | is( $result->return_code, 2, "$command -p $port_https -S -C 13960,14000" ); |
206 | like( $result->output, '/CRITICAL - Certificate \'Ton Voon\' expires in \d+ day\(s\) \(Sun Mar 3 21:41:28 2019 \+0000\)./', "output ok" ); | 214 | like( $result->output, '/CRITICAL - Certificate \'Monitoring Plugins\' expires in \d+ day\(s\) \(Fri Feb 16 15:31:44 2029 \+0000\)./', "output ok" ); |
207 | 215 | ||
208 | $result = NPTest->testCmd( "$command -p $port_https_expired -S -C 7" ); | 216 | $result = NPTest->testCmd( "$command -p $port_https_expired -S -C 7" ); |
209 | is( $result->return_code, 2, "$command -p $port_https_expired -S -C 7" ); | 217 | is( $result->return_code, 2, "$command -p $port_https_expired -S -C 7" ); |
210 | is( $result->output, | 218 | is( $result->output, |
211 | 'CRITICAL - Certificate \'Ton Voon\' expired on Thu Mar 5 00:13:16 2009 +0000.', | 219 | 'CRITICAL - Certificate \'Monitoring Plugins\' expired on Wed Jan 2 11:00:26 2008 +0000.', |
212 | "output ok" ); | 220 | "output ok" ); |
213 | 221 | ||
214 | } | 222 | } |
@@ -409,22 +417,24 @@ sub run_common_tests { | |||
409 | 417 | ||
410 | # stickyport - on full urlS port is set back to 80 otherwise | 418 | # stickyport - on full urlS port is set back to 80 otherwise |
411 | $cmd = "$command -f stickyport -u /redir_external -t 5 -s redirected"; | 419 | $cmd = "$command -f stickyport -u /redir_external -t 5 -s redirected"; |
420 | alarm(2); | ||
412 | eval { | 421 | eval { |
413 | local $SIG{ALRM} = sub { die "alarm\n" }; | 422 | local $SIG{ALRM} = sub { die "alarm\n" }; |
414 | alarm(2); | ||
415 | $result = NPTest->testCmd( $cmd ); | 423 | $result = NPTest->testCmd( $cmd ); |
416 | alarm(0); }; | 424 | }; |
417 | isnt( $@, "alarm\n", $cmd ); | 425 | isnt( $@, "alarm\n", $cmd ); |
426 | alarm(0); | ||
418 | is( $result->return_code, 0, $cmd ); | 427 | is( $result->return_code, 0, $cmd ); |
419 | 428 | ||
420 | # Let's hope there won't be any web server on :80 returning "redirected"! | 429 | # Let's hope there won't be any web server on :80 returning "redirected"! |
421 | $cmd = "$command -f sticky -u /redir_external -t 5 -s redirected"; | 430 | $cmd = "$command -f sticky -u /redir_external -t 5 -s redirected"; |
431 | alarm(2); | ||
422 | eval { | 432 | eval { |
423 | local $SIG{ALRM} = sub { die "alarm\n" }; | 433 | local $SIG{ALRM} = sub { die "alarm\n" }; |
424 | alarm(2); | ||
425 | $result = NPTest->testCmd( $cmd ); | 434 | $result = NPTest->testCmd( $cmd ); |
426 | alarm(0); }; | 435 | }; |
427 | isnt( $@, "alarm\n", $cmd ); | 436 | isnt( $@, "alarm\n", $cmd ); |
437 | alarm(0); | ||
428 | isnt( $result->return_code, 0, $cmd ); | 438 | isnt( $result->return_code, 0, $cmd ); |
429 | 439 | ||
430 | # Test an external address - timeout | 440 | # Test an external address - timeout |