summaryrefslogtreecommitdiffstats
path: root/plugins/tests/check_curl.t
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/tests/check_curl.t')
-rwxr-xr-xplugins/tests/check_curl.t50
1 files changed, 39 insertions, 11 deletions
diff --git a/plugins/tests/check_curl.t b/plugins/tests/check_curl.t
index 1afbe4b..72f2b7c 100755
--- a/plugins/tests/check_curl.t
+++ b/plugins/tests/check_curl.t
@@ -21,7 +21,7 @@ use FindBin qw($Bin);
21 21
22$ENV{'LC_TIME'} = "C"; 22$ENV{'LC_TIME'} = "C";
23 23
24my $common_tests = 70; 24my $common_tests = 73;
25my $ssl_only_tests = 8; 25my $ssl_only_tests = 8;
26# Check that all dependent modules are available 26# Check that all dependent modules are available
27eval "use HTTP::Daemon 6.01;"; 27eval "use HTTP::Daemon 6.01;";
@@ -126,8 +126,6 @@ if ($pid) {
126 exit; 126 exit;
127 } 127 }
128 } 128 }
129 # give our webservers some time to startup
130 sleep(1);
131} else { 129} else {
132 # Child 130 # Child
133 #print "child\n"; 131 #print "child\n";
@@ -140,6 +138,9 @@ if ($pid) {
140 exit; 138 exit;
141} 139}
142 140
141# give our webservers some time to startup
142sleep(3);
143
143# Run the same server on http and https 144# Run the same server on http and https
144sub run_server { 145sub run_server {
145 my $d = shift; 146 my $d = shift;
@@ -188,11 +189,25 @@ sub run_server {
188 $c->send_basic_header; 189 $c->send_basic_header;
189 $c->send_header('foo'); 190 $c->send_header('foo');
190 $c->send_crlf; 191 $c->send_crlf;
192 } elsif ($r->url->path eq "/header_broken_check") {
193 $c->send_basic_header;
194 $c->send_header('foo');
195 print $c "Test1:: broken\n";
196 print $c " Test2: leading whitespace\n";
197 $c->send_crlf;
191 } elsif ($r->url->path eq "/virtual_port") { 198 } elsif ($r->url->path eq "/virtual_port") {
192 # return sent Host header 199 # return sent Host header
193 $c->send_basic_header; 200 $c->send_basic_header;
194 $c->send_crlf; 201 $c->send_crlf;
195 $c->send_response(HTTP::Response->new( 200, 'OK', undef, $r->header ('Host'))); 202 $c->send_response(HTTP::Response->new( 200, 'OK', undef, $r->header ('Host')));
203 } elsif ($r->url->path eq "/chunked") {
204 my $chunks = ["chunked", "encoding", "test\n"];
205 $c->send_response(HTTP::Response->new( 200, 'OK', undef, sub {
206 my $chunk = shift @{$chunks};
207 return unless $chunk;
208 sleep(1);
209 return($chunk);
210 }));
196 } else { 211 } else {
197 $c->send_error(HTTP::Status->RC_FORBIDDEN); 212 $c->send_error(HTTP::Status->RC_FORBIDDEN);
198 } 213 }
@@ -221,23 +236,25 @@ SKIP: {
221 skip "HTTP::Daemon::SSL not installed", $common_tests + $ssl_only_tests if ! exists $servers->{https}; 236 skip "HTTP::Daemon::SSL not installed", $common_tests + $ssl_only_tests if ! exists $servers->{https};
222 run_common_tests( { command => "$command -p $port_https", ssl => 1 } ); 237 run_common_tests( { command => "$command -p $port_https", ssl => 1 } );
223 238
239 my $expiry = "Thu Nov 28 21:02:11 2030 +0000";
240
224 $result = NPTest->testCmd( "$command -p $port_https -S -C 14" ); 241 $result = NPTest->testCmd( "$command -p $port_https -S -C 14" );
225 is( $result->return_code, 0, "$command -p $port_https -S -C 14" ); 242 is( $result->return_code, 0, "$command -p $port_https -S -C 14" );
226 is( $result->output, "OK - Certificate 'Monitoring Plugins' will expire on Fri Feb 16 15:31:44 2029 +0000.", "output ok" ); 243 is( $result->output, "OK - Certificate 'Monitoring Plugins' will expire on $expiry.", "output ok" );
227 244
228 $result = NPTest->testCmd( "$command -p $port_https -S -C 14000" ); 245 $result = NPTest->testCmd( "$command -p $port_https -S -C 14000" );
229 is( $result->return_code, 1, "$command -p $port_https -S -C 14000" ); 246 is( $result->return_code, 1, "$command -p $port_https -S -C 14000" );
230 like( $result->output, '/WARNING - Certificate \'Monitoring Plugins\' expires in \d+ day\(s\) \(Fri Feb 16 15:31:44 2029 \+0000\)./', "output ok" ); 247 like( $result->output, '/WARNING - Certificate \'Monitoring Plugins\' expires in \d+ day\(s\) \(' . quotemeta($expiry) . '\)./', "output ok" );
231 248
232 # Expired cert tests 249 # Expired cert tests
233 $result = NPTest->testCmd( "$command -p $port_https -S -C 13960,14000" ); 250 $result = NPTest->testCmd( "$command -p $port_https -S -C 13960,14000" );
234 is( $result->return_code, 2, "$command -p $port_https -S -C 13960,14000" ); 251 is( $result->return_code, 2, "$command -p $port_https -S -C 13960,14000" );
235 like( $result->output, '/CRITICAL - Certificate \'Monitoring Plugins\' expires in \d+ day\(s\) \(Fri Feb 16 15:31:44 2029 \+0000\)./', "output ok" ); 252 like( $result->output, '/CRITICAL - Certificate \'Monitoring Plugins\' expires in \d+ day\(s\) \(' . quotemeta($expiry) . '\)./', "output ok" );
236 253
237 $result = NPTest->testCmd( "$command -p $port_https_expired -S -C 7" ); 254 $result = NPTest->testCmd( "$command -p $port_https_expired -S -C 7" );
238 is( $result->return_code, 2, "$command -p $port_https_expired -S -C 7" ); 255 is( $result->return_code, 2, "$command -p $port_https_expired -S -C 7" );
239 is( $result->output, 256 is( $result->output,
240 'CRITICAL - Certificate \'Monitoring Plugins\' expired on Wed Jan 2 11:00:26 2008 +0000.', 257 'CRITICAL - Certificate \'Monitoring Plugins\' expired on Wed Jan 2 12:00:00 2008 +0000.',
241 "output ok" ); 258 "output ok" );
242 259
243} 260}
@@ -247,7 +264,7 @@ my $cmd;
247# advanced checks with virtual hostname and virtual port 264# advanced checks with virtual hostname and virtual port
248SKIP: { 265SKIP: {
249 skip "libcurl version is smaller than $required_version", 6 unless $use_advanced_checks; 266 skip "libcurl version is smaller than $required_version", 6 unless $use_advanced_checks;
250 267
251 # http without virtual port 268 # http without virtual port
252 $cmd = "./$plugin -H $virtual_host -I 127.0.0.1 -p $port_http -u /virtual_port -r ^$virtual_host:$port_http\$"; 269 $cmd = "./$plugin -H $virtual_host -I 127.0.0.1 -p $port_http -u /virtual_port -r ^$virtual_host:$port_http\$";
253 $result = NPTest->testCmd( $cmd ); 270 $result = NPTest->testCmd( $cmd );
@@ -259,7 +276,7 @@ SKIP: {
259 $result = NPTest->testCmd( $cmd ); 276 $result = NPTest->testCmd( $cmd );
260 is( $result->return_code, 0, $cmd); 277 is( $result->return_code, 0, $cmd);
261 like( $result->output, '/^HTTP OK: HTTP/1.1 200 OK - \d+ bytes in [\d\.]+ second/', "Output correct: ".$result->output ); 278 like( $result->output, '/^HTTP OK: HTTP/1.1 200 OK - \d+ bytes in [\d\.]+ second/', "Output correct: ".$result->output );
262 279
263 # http with virtual port (80) 280 # http with virtual port (80)
264 $cmd = "./$plugin -H $virtual_host:80 -I 127.0.0.1 -p $port_http -u /virtual_port -r ^$virtual_host\$"; 281 $cmd = "./$plugin -H $virtual_host:80 -I 127.0.0.1 -p $port_http -u /virtual_port -r ^$virtual_host\$";
265 $result = NPTest->testCmd( $cmd ); 282 $result = NPTest->testCmd( $cmd );
@@ -321,6 +338,10 @@ sub run_common_tests {
321 is( $result->return_code, 2, "Missing header string check"); 338 is( $result->return_code, 2, "Missing header string check");
322 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"); 339 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");
323 340
341 $result = NPTest->testCmd( "$command -u /header_broken_check" );
342 is( $result->return_code, 0, "header_check search for string");
343 like( $result->output, '/^HTTP OK: HTTP/1.1 200 OK - 138 bytes in [\d\.]+ second/', "Output correct" );
344
324 my $cmd; 345 my $cmd;
325 $cmd = "$command -u /slow"; 346 $cmd = "$command -u /slow";
326 $result = NPTest->testCmd( $cmd ); 347 $result = NPTest->testCmd( $cmd );
@@ -459,7 +480,8 @@ sub run_common_tests {
459 local $SIG{ALRM} = sub { die "alarm\n" }; 480 local $SIG{ALRM} = sub { die "alarm\n" };
460 alarm(2); 481 alarm(2);
461 $result = NPTest->testCmd( $cmd ); 482 $result = NPTest->testCmd( $cmd );
462 alarm(0); }; 483 };
484 alarm(0);
463 isnt( $@, "alarm\n", $cmd ); 485 isnt( $@, "alarm\n", $cmd );
464 is( $result->return_code, 0, $cmd ); 486 is( $result->return_code, 0, $cmd );
465 487
@@ -469,7 +491,8 @@ sub run_common_tests {
469 local $SIG{ALRM} = sub { die "alarm\n" }; 491 local $SIG{ALRM} = sub { die "alarm\n" };
470 alarm(2); 492 alarm(2);
471 $result = NPTest->testCmd( $cmd ); 493 $result = NPTest->testCmd( $cmd );
472 alarm(0); }; 494 };
495 alarm(0);
473 isnt( $@, "alarm\n", $cmd ); 496 isnt( $@, "alarm\n", $cmd );
474 isnt( $result->return_code, 0, $cmd ); 497 isnt( $result->return_code, 0, $cmd );
475 498
@@ -495,4 +518,9 @@ sub run_common_tests {
495 }; 518 };
496 is( $@, "", $cmd ); 519 is( $@, "", $cmd );
497 520
521 $cmd = "$command -u /chunked -s 'chunkedencodingtest' -d 'Transfer-Encoding: chunked'";
522 eval {
523 $result = NPTest->testCmd( $cmd, 5 );
524 };
525 is( $@, "", $cmd );
498} 526}