summaryrefslogtreecommitdiffstats
path: root/plugins/tests/check_curl.t
diff options
context:
space:
mode:
authorRincewindsHat <12514511+RincewindsHat@users.noreply.github.com>2021-12-02 15:42:05 (GMT)
committerGitHub <noreply@github.com>2021-12-02 15:42:05 (GMT)
commit911e44045d7291f5ede22739fd176ef55dd3de4a (patch)
treecf36b95a4a964b03d6ecf75770ced2cb3a2ac3a9 /plugins/tests/check_curl.t
parent8294af907bd8482a86df749f562b7ec09e3faeed (diff)
parented7cdf82a42f16532801ea4f118870ce9a130fcf (diff)
downloadmonitoring-plugins-911e44045d7291f5ede22739fd176ef55dd3de4a.tar.gz
Merge branch 'master' into fix/shellcheckrefs/pull/1459/head
Diffstat (limited to 'plugins/tests/check_curl.t')
-rwxr-xr-xplugins/tests/check_curl.t509
1 files changed, 509 insertions, 0 deletions
diff --git a/plugins/tests/check_curl.t b/plugins/tests/check_curl.t
new file mode 100755
index 0000000..29cb03f
--- /dev/null
+++ b/plugins/tests/check_curl.t
@@ -0,0 +1,509 @@
1#! /usr/bin/perl -w -I ..
2#
3# Test check_http by having an actual HTTP server running
4#
5# To create the https server certificate:
6# openssl req -new -x509 -keyout server-key.pem -out server-cert.pem -days 3650 -nodes
7# to create a new expired certificate:
8# faketime '2008-01-01 12:00:00' openssl req -new -x509 -keyout expired-key.pem -out expired-cert.pem -days 1 -nodes
9# Country Name (2 letter code) [AU]:DE
10# State or Province Name (full name) [Some-State]:Bavaria
11# Locality Name (eg, city) []:Munich
12# Organization Name (eg, company) [Internet Widgits Pty Ltd]:Monitoring Plugins
13# Organizational Unit Name (eg, section) []:
14# Common Name (e.g. server FQDN or YOUR name) []:Monitoring Plugins
15# Email Address []:devel@monitoring-plugins.org
16
17use strict;
18use Test::More;
19use NPTest;
20use FindBin qw($Bin);
21
22$ENV{'LC_TIME'} = "C";
23
24my $common_tests = 72;
25my $ssl_only_tests = 8;
26# Check that all dependent modules are available
27eval "use HTTP::Daemon 6.01;";
28plan skip_all => 'HTTP::Daemon >= 6.01 required' if $@;
29eval {
30 require HTTP::Status;
31 require HTTP::Response;
32};
33
34my $plugin = 'check_http';
35$plugin = 'check_curl' if $0 =~ m/check_curl/mx;
36
37# look for libcurl version to see if some advanced checks are possible (>= 7.49.0)
38my $advanced_checks = 12;
39my $use_advanced_checks = 0;
40my $required_version = '7.49.0';
41my $virtual_host = 'www.somefunnyhost.com';
42my $virtual_port = 42;
43my $curl_version = '';
44open (my $fh, '-|', "./$plugin --version") or die;
45while (<$fh>) {
46 if (m{libcurl/([\d.]+)\s}) {
47 $curl_version = $1;
48 last;
49 }
50}
51close ($fh);
52if ($curl_version) {
53 my ($major, $minor, $release) = split (/\./, $curl_version);
54 my ($req_major, $req_minor, $req_release) = split (/\./, $required_version);
55 my $check = ($major <=> $req_major or $minor <=> $req_minor or $release <=> $req_release);
56 if ($check >= 0) {
57 $use_advanced_checks = 1;
58 print "Found libcurl $major.$minor.$release. Using advanced checks\n";
59 }
60}
61
62if ($@) {
63 plan skip_all => "Missing required module for test: $@";
64} else {
65 if (-x "./$plugin") {
66 plan tests => $common_tests * 2 + $ssl_only_tests + $advanced_checks;
67 } else {
68 plan skip_all => "No $plugin compiled";
69 }
70}
71
72my $servers = { http => 0 }; # HTTP::Daemon should always be available
73eval { require HTTP::Daemon::SSL };
74if ($@) {
75 diag "Cannot load HTTP::Daemon::SSL: $@";
76} else {
77 $servers->{https} = 0;
78}
79
80# set a fixed version, so the header size doesn't vary
81$HTTP::Daemon::VERSION = "1.00";
82
83my $port_http = 50000 + int(rand(1000));
84my $port_https = $port_http + 1;
85my $port_https_expired = $port_http + 2;
86
87# This array keeps sockets around for implementing timeouts
88my @persist;
89
90# Start up all servers
91my @pids;
92my $pid = fork();
93if ($pid) {
94 # Parent
95 push @pids, $pid;
96 if (exists $servers->{https}) {
97 # Fork a normal HTTPS server
98 $pid = fork();
99 if ($pid) {
100 # Parent
101 push @pids, $pid;
102 # Fork an expired cert server
103 $pid = fork();
104 if ($pid) {
105 push @pids, $pid;
106 } else {
107 my $d = HTTP::Daemon::SSL->new(
108 LocalPort => $port_https_expired,
109 LocalAddr => "127.0.0.1",
110 SSL_cert_file => "$Bin/certs/expired-cert.pem",
111 SSL_key_file => "$Bin/certs/expired-key.pem",
112 ) || die;
113 print "Please contact https expired at: <URL:", $d->url, ">\n";
114 run_server( $d );
115 exit;
116 }
117 } else {
118 my $d = HTTP::Daemon::SSL->new(
119 LocalPort => $port_https,
120 LocalAddr => "127.0.0.1",
121 SSL_cert_file => "$Bin/certs/server-cert.pem",
122 SSL_key_file => "$Bin/certs/server-key.pem",
123 ) || die;
124 print "Please contact https at: <URL:", $d->url, ">\n";
125 run_server( $d );
126 exit;
127 }
128 }
129} else {
130 # Child
131 #print "child\n";
132 my $d = HTTP::Daemon->new(
133 LocalPort => $port_http,
134 LocalAddr => "127.0.0.1",
135 ) || die;
136 print "Please contact http at: <URL:", $d->url, ">\n";
137 run_server( $d );
138 exit;
139}
140
141# give our webservers some time to startup
142sleep(3);
143
144# Run the same server on http and https
145sub run_server {
146 my $d = shift;
147 MAINLOOP: while (my $c = $d->accept ) {
148 while (my $r = $c->get_request) {
149 if ($r->method eq "GET" and $r->url->path =~ m^/statuscode/(\d+)^) {
150 $c->send_basic_header($1);
151 $c->send_crlf;
152 } elsif ($r->method eq "GET" and $r->url->path =~ m^/file/(.*)^) {
153 $c->send_basic_header;
154 $c->send_crlf;
155 $c->send_file_response("$Bin/var/$1");
156 } elsif ($r->method eq "GET" and $r->url->path eq "/slow") {
157 $c->send_basic_header;
158 $c->send_crlf;
159 sleep 1;
160 $c->send_response("slow");
161 } elsif ($r->url->path eq "/method") {
162 if ($r->method eq "DELETE") {
163 $c->send_error(HTTP::Status->RC_METHOD_NOT_ALLOWED);
164 } elsif ($r->method eq "foo") {
165 $c->send_error(HTTP::Status->RC_NOT_IMPLEMENTED);
166 } else {
167 $c->send_status_line(200, $r->method);
168 }
169 } elsif ($r->url->path eq "/postdata") {
170 $c->send_basic_header;
171 $c->send_crlf;
172 $c->send_response($r->method.":".$r->content);
173 } elsif ($r->url->path eq "/redirect") {
174 $c->send_redirect( "/redirect2" );
175 } elsif ($r->url->path eq "/redir_external") {
176 $c->send_redirect(($d->isa('HTTP::Daemon::SSL') ? "https" : "http") . "://169.254.169.254/redirect2" );
177 } elsif ($r->url->path eq "/redirect2") {
178 $c->send_basic_header;
179 $c->send_crlf;
180 $c->send_response(HTTP::Response->new( 200, 'OK', undef, 'redirected' ));
181 } elsif ($r->url->path eq "/redir_timeout") {
182 $c->send_redirect( "/timeout" );
183 } elsif ($r->url->path eq "/timeout") {
184 # Keep $c from being destroyed, but prevent severe leaks
185 unshift @persist, $c;
186 delete($persist[1000]);
187 next MAINLOOP;
188 } elsif ($r->url->path eq "/header_check") {
189 $c->send_basic_header;
190 $c->send_header('foo');
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;
198 } elsif ($r->url->path eq "/virtual_port") {
199 # return sent Host header
200 $c->send_basic_header;
201 $c->send_crlf;
202 $c->send_response(HTTP::Response->new( 200, 'OK', undef, $r->header ('Host')));
203 } else {
204 $c->send_error(HTTP::Status->RC_FORBIDDEN);
205 }
206 $c->close;
207 }
208 }
209}
210
211END {
212 foreach my $pid (@pids) {
213 if ($pid) { print "Killing $pid\n"; kill "INT", $pid }
214 }
215};
216
217if ($ARGV[0] && $ARGV[0] eq "-d") {
218 while (1) {
219 sleep 100;
220 }
221}
222
223my $result;
224my $command = "./$plugin -H 127.0.0.1";
225
226run_common_tests( { command => "$command -p $port_http" } );
227SKIP: {
228 skip "HTTP::Daemon::SSL not installed", $common_tests + $ssl_only_tests if ! exists $servers->{https};
229 run_common_tests( { command => "$command -p $port_https", ssl => 1 } );
230
231 $result = NPTest->testCmd( "$command -p $port_https -S -C 14" );
232 is( $result->return_code, 0, "$command -p $port_https -S -C 14" );
233 is( $result->output, "OK - Certificate 'Monitoring Plugins' will expire on Fri Feb 16 15:31:44 2029 +0000.", "output ok" );
234
235 $result = NPTest->testCmd( "$command -p $port_https -S -C 14000" );
236 is( $result->return_code, 1, "$command -p $port_https -S -C 14000" );
237 like( $result->output, '/WARNING - Certificate \'Monitoring Plugins\' expires in \d+ day\(s\) \(Fri Feb 16 15:31:44 2029 \+0000\)./', "output ok" );
238
239 # Expired cert tests
240 $result = NPTest->testCmd( "$command -p $port_https -S -C 13960,14000" );
241 is( $result->return_code, 2, "$command -p $port_https -S -C 13960,14000" );
242 like( $result->output, '/CRITICAL - Certificate \'Monitoring Plugins\' expires in \d+ day\(s\) \(Fri Feb 16 15:31:44 2029 \+0000\)./', "output ok" );
243
244 $result = NPTest->testCmd( "$command -p $port_https_expired -S -C 7" );
245 is( $result->return_code, 2, "$command -p $port_https_expired -S -C 7" );
246 is( $result->output,
247 'CRITICAL - Certificate \'Monitoring Plugins\' expired on Wed Jan 2 11:00:26 2008 +0000.',
248 "output ok" );
249
250}
251
252my $cmd;
253
254# advanced checks with virtual hostname and virtual port
255SKIP: {
256 skip "libcurl version is smaller than $required_version", 6 unless $use_advanced_checks;
257
258 # http without virtual port
259 $cmd = "./$plugin -H $virtual_host -I 127.0.0.1 -p $port_http -u /virtual_port -r ^$virtual_host:$port_http\$";
260 $result = NPTest->testCmd( $cmd );
261 is( $result->return_code, 0, $cmd);
262 like( $result->output, '/^HTTP OK: HTTP/1.1 200 OK - \d+ bytes in [\d\.]+ second/', "Output correct: ".$result->output );
263
264 # http with virtual port (!= 80)
265 $cmd = "./$plugin -H $virtual_host:$virtual_port -I 127.0.0.1 -p $port_http -u /virtual_port -r ^$virtual_host:$virtual_port\$";
266 $result = NPTest->testCmd( $cmd );
267 is( $result->return_code, 0, $cmd);
268 like( $result->output, '/^HTTP OK: HTTP/1.1 200 OK - \d+ bytes in [\d\.]+ second/', "Output correct: ".$result->output );
269
270 # http with virtual port (80)
271 $cmd = "./$plugin -H $virtual_host:80 -I 127.0.0.1 -p $port_http -u /virtual_port -r ^$virtual_host\$";
272 $result = NPTest->testCmd( $cmd );
273 is( $result->return_code, 0, $cmd);
274 like( $result->output, '/^HTTP OK: HTTP/1.1 200 OK - \d+ bytes in [\d\.]+ second/', "Output correct: ".$result->output );
275}
276
277# and the same for SSL
278SKIP: {
279 skip "libcurl version is smaller than $required_version and/or HTTP::Daemon::SSL not installed", 6 if ! exists $servers->{https} or not $use_advanced_checks;
280 # https without virtual port
281 $cmd = "./$plugin -H $virtual_host -I 127.0.0.1 -p $port_https --ssl -u /virtual_port -r ^$virtual_host:$port_https\$";
282 $result = NPTest->testCmd( $cmd );
283 is( $result->return_code, 0, $cmd);
284 like( $result->output, '/^HTTP OK: HTTP/1.1 200 OK - \d+ bytes in [\d\.]+ second/', "Output correct: ".$result->output );
285
286 # https with virtual port (!= 443)
287 $cmd = "./$plugin -H $virtual_host:$virtual_port -I 127.0.0.1 -p $port_https --ssl -u /virtual_port -r ^$virtual_host:$virtual_port\$";
288 $result = NPTest->testCmd( $cmd );
289 is( $result->return_code, 0, $cmd);
290 like( $result->output, '/^HTTP OK: HTTP/1.1 200 OK - \d+ bytes in [\d\.]+ second/', "Output correct: ".$result->output );
291
292 # https with virtual port (443)
293 $cmd = "./$plugin -H $virtual_host:443 -I 127.0.0.1 -p $port_https --ssl -u /virtual_port -r ^$virtual_host\$";
294 $result = NPTest->testCmd( $cmd );
295 is( $result->return_code, 0, $cmd);
296 like( $result->output, '/^HTTP OK: HTTP/1.1 200 OK - \d+ bytes in [\d\.]+ second/', "Output correct: ".$result->output );
297}
298
299
300sub run_common_tests {
301 my ($opts) = @_;
302 my $command = $opts->{command};
303 if ($opts->{ssl}) {
304 $command .= " --ssl";
305 }
306
307 $result = NPTest->testCmd( "$command -u /file/root" );
308 is( $result->return_code, 0, "/file/root");
309 like( $result->output, '/^HTTP OK: HTTP/1.1 200 OK - 274 bytes in [\d\.]+ second/', "Output correct" );
310
311 $result = NPTest->testCmd( "$command -u /file/root -s Root" );
312 is( $result->return_code, 0, "/file/root search for string");
313 like( $result->output, '/^HTTP OK: HTTP/1.1 200 OK - 274 bytes in [\d\.]+ second/', "Output correct" );
314
315 $result = NPTest->testCmd( "$command -u /file/root -s NonRoot" );
316 is( $result->return_code, 2, "Missing string check");
317 like( $result->output, qr%^HTTP CRITICAL: HTTP/1\.1 200 OK - string 'NonRoot' not found on 'https?://127\.0\.0\.1:\d+/file/root'%, "Shows search string and location");
318
319 $result = NPTest->testCmd( "$command -u /file/root -s NonRootWithOver30charsAndMoreFunThanAWetFish" );
320 is( $result->return_code, 2, "Missing string check");
321 like( $result->output, qr%HTTP CRITICAL: HTTP/1\.1 200 OK - string 'NonRootWithOver30charsAndM...' not found on 'https?://127\.0\.0\.1:\d+/file/root'%, "Shows search string and location");
322
323 $result = NPTest->testCmd( "$command -u /header_check -d foo" );
324 is( $result->return_code, 0, "header_check search for string");
325 like( $result->output, '/^HTTP OK: HTTP/1.1 200 OK - 96 bytes in [\d\.]+ second/', "Output correct" );
326
327 $result = NPTest->testCmd( "$command -u /header_check -d bar" );
328 is( $result->return_code, 2, "Missing header string check");
329 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");
330
331 $result = NPTest->testCmd( "$command -u /header_broken_check" );
332 is( $result->return_code, 0, "header_check search for string");
333 like( $result->output, '/^HTTP OK: HTTP/1.1 200 OK - 138 bytes in [\d\.]+ second/', "Output correct" );
334
335 my $cmd;
336 $cmd = "$command -u /slow";
337 $result = NPTest->testCmd( $cmd );
338 is( $result->return_code, 0, "$cmd");
339 like( $result->output, '/^HTTP OK: HTTP/1.1 200 OK - \d+ bytes in [\d\.]+ second/', "Output correct: ".$result->output );
340 $result->output =~ /in ([\d\.]+) second/;
341 cmp_ok( $1, ">", 1, "Time is > 1 second" );
342
343 $cmd = "$command -u /statuscode/200";
344 $result = NPTest->testCmd( $cmd );
345 is( $result->return_code, 0, $cmd);
346 like( $result->output, '/^HTTP OK: HTTP/1.1 200 OK - \d+ bytes in [\d\.]+ second/', "Output correct: ".$result->output );
347
348 $cmd = "$command -u /statuscode/200 -e 200";
349 $result = NPTest->testCmd( $cmd );
350 is( $result->return_code, 0, $cmd);
351 like( $result->output, '/^HTTP OK: HTTP/1.1 200 OK - Status line output matched "200" - \d+ bytes in [\d\.]+ second/', "Output correct: ".$result->output );
352
353 $cmd = "$command -u /statuscode/201";
354 $result = NPTest->testCmd( $cmd );
355 is( $result->return_code, 0, $cmd);
356 like( $result->output, '/^HTTP OK: HTTP/1.1 201 Created - \d+ bytes in [\d\.]+ second /', "Output correct: ".$result->output );
357
358 $cmd = "$command -u /statuscode/201 -e 201";
359 $result = NPTest->testCmd( $cmd );
360 is( $result->return_code, 0, $cmd);
361 like( $result->output, '/^HTTP OK: HTTP/1.1 201 Created - Status line output matched "201" - \d+ bytes in [\d\.]+ second /', "Output correct: ".$result->output );
362
363 $cmd = "$command -u /statuscode/201 -e 200";
364 $result = NPTest->testCmd( $cmd );
365 is( $result->return_code, 2, $cmd);
366 like( $result->output, '/^HTTP CRITICAL - Invalid HTTP response received from host on port \d+: HTTP/1.1 201 Created/', "Output correct: ".$result->output );
367
368 $cmd = "$command -u /statuscode/200 -e 200,201,202";
369 $result = NPTest->testCmd( $cmd );
370 is( $result->return_code, 0, $cmd);
371 like( $result->output, '/^HTTP OK: HTTP/1.1 200 OK - Status line output matched "200,201,202" - \d+ bytes in [\d\.]+ second/', "Output correct: ".$result->output );
372
373 $cmd = "$command -u /statuscode/201 -e 200,201,202";
374 $result = NPTest->testCmd( $cmd );
375 is( $result->return_code, 0, $cmd);
376 like( $result->output, '/^HTTP OK: HTTP/1.1 201 Created - Status line output matched "200,201,202" - \d+ bytes in [\d\.]+ second/', "Output correct: ".$result->output );
377
378 $cmd = "$command -u /statuscode/203 -e 200,201,202";
379 $result = NPTest->testCmd( $cmd );
380 is( $result->return_code, 2, $cmd);
381 like( $result->output, '/^HTTP CRITICAL - Invalid HTTP response received from host on port (\d+): HTTP/1.1 203 Non-Authoritative Information/', "Output correct: ".$result->output );
382
383 $cmd = "$command -j HEAD -u /method";
384 $result = NPTest->testCmd( $cmd );
385 is( $result->return_code, 0, $cmd);
386 like( $result->output, '/^HTTP OK: HTTP/1.1 200 HEAD - \d+ bytes in [\d\.]+ second/', "Output correct: ".$result->output );
387
388 $cmd = "$command -j POST -u /method";
389 $result = NPTest->testCmd( $cmd );
390 is( $result->return_code, 0, $cmd);
391 like( $result->output, '/^HTTP OK: HTTP/1.1 200 POST - \d+ bytes in [\d\.]+ second/', "Output correct: ".$result->output );
392
393 $cmd = "$command -j GET -u /method";
394 $result = NPTest->testCmd( $cmd );
395 is( $result->return_code, 0, $cmd);
396 like( $result->output, '/^HTTP OK: HTTP/1.1 200 GET - \d+ bytes in [\d\.]+ second/', "Output correct: ".$result->output );
397
398 $cmd = "$command -u /method";
399 $result = NPTest->testCmd( $cmd );
400 is( $result->return_code, 0, $cmd);
401 like( $result->output, '/^HTTP OK: HTTP/1.1 200 GET - \d+ bytes in [\d\.]+ second/', "Output correct: ".$result->output );
402
403 $cmd = "$command -P foo -u /method";
404 $result = NPTest->testCmd( $cmd );
405 is( $result->return_code, 0, $cmd);
406 like( $result->output, '/^HTTP OK: HTTP/1.1 200 POST - \d+ bytes in [\d\.]+ second/', "Output correct: ".$result->output );
407
408 $cmd = "$command -j DELETE -u /method";
409 $result = NPTest->testCmd( $cmd );
410 is( $result->return_code, 1, $cmd);
411 like( $result->output, '/^HTTP WARNING: HTTP/1.1 405 Method Not Allowed/', "Output correct: ".$result->output );
412
413 $cmd = "$command -j foo -u /method";
414 $result = NPTest->testCmd( $cmd );
415 is( $result->return_code, 2, $cmd);
416 like( $result->output, '/^HTTP CRITICAL: HTTP/1.1 501 Not Implemented/', "Output correct: ".$result->output );
417
418 $cmd = "$command -P stufftoinclude -u /postdata -s POST:stufftoinclude";
419 $result = NPTest->testCmd( $cmd );
420 is( $result->return_code, 0, $cmd);
421 like( $result->output, '/^HTTP OK: HTTP/1.1 200 OK - \d+ bytes in [\d\.]+ second/', "Output correct: ".$result->output );
422
423 $cmd = "$command -j PUT -P stufftoinclude -u /postdata -s PUT:stufftoinclude";
424 $result = NPTest->testCmd( $cmd );
425 is( $result->return_code, 0, $cmd);
426 like( $result->output, '/^HTTP OK: HTTP/1.1 200 OK - \d+ bytes in [\d\.]+ second/', "Output correct: ".$result->output );
427
428 # To confirm that the free doesn't segfault
429 $cmd = "$command -P stufftoinclude -j PUT -u /postdata -s PUT:stufftoinclude";
430 $result = NPTest->testCmd( $cmd );
431 is( $result->return_code, 0, $cmd);
432 like( $result->output, '/^HTTP OK: HTTP/1.1 200 OK - \d+ bytes in [\d\.]+ second/', "Output correct: ".$result->output );
433
434 $cmd = "$command -u /redirect";
435 $result = NPTest->testCmd( $cmd );
436 is( $result->return_code, 0, $cmd);
437 like( $result->output, '/^HTTP OK: HTTP/1.1 301 Moved Permanently - \d+ bytes in [\d\.]+ second/', "Output correct: ".$result->output );
438
439 $cmd = "$command -f follow -u /redirect";
440 $result = NPTest->testCmd( $cmd );
441 is( $result->return_code, 0, $cmd);
442 like( $result->output, '/^HTTP OK: HTTP/1.1 200 OK - \d+ bytes in [\d\.]+ second/', "Output correct: ".$result->output );
443
444 $cmd = "$command -u /redirect -k 'follow: me'";
445 $result = NPTest->testCmd( $cmd );
446 is( $result->return_code, 0, $cmd);
447 like( $result->output, '/^HTTP OK: HTTP/1.1 301 Moved Permanently - \d+ bytes in [\d\.]+ second/', "Output correct: ".$result->output );
448
449 $cmd = "$command -f follow -u /redirect -k 'follow: me'";
450 $result = NPTest->testCmd( $cmd );
451 is( $result->return_code, 0, $cmd);
452 like( $result->output, '/^HTTP OK: HTTP/1.1 200 OK - \d+ bytes in [\d\.]+ second/', "Output correct: ".$result->output );
453
454 $cmd = "$command -f sticky -u /redirect -k 'follow: me'";
455 $result = NPTest->testCmd( $cmd );
456 is( $result->return_code, 0, $cmd);
457 like( $result->output, '/^HTTP OK: HTTP/1.1 200 OK - \d+ bytes in [\d\.]+ second/', "Output correct: ".$result->output );
458
459 $cmd = "$command -f stickyport -u /redirect -k 'follow: me'";
460 $result = NPTest->testCmd( $cmd );
461 is( $result->return_code, 0, $cmd);
462 like( $result->output, '/^HTTP OK: HTTP/1.1 200 OK - \d+ bytes in [\d\.]+ second/', "Output correct: ".$result->output );
463
464 # These tests may block
465 print "ALRM\n";
466
467 # stickyport - on full urlS port is set back to 80 otherwise
468 $cmd = "$command -f stickyport -u /redir_external -t 5 -s redirected";
469 eval {
470 local $SIG{ALRM} = sub { die "alarm\n" };
471 alarm(2);
472 $result = NPTest->testCmd( $cmd );
473 alarm(0); };
474 isnt( $@, "alarm\n", $cmd );
475 is( $result->return_code, 0, $cmd );
476
477 # Let's hope there won't be any web server on :80 returning "redirected"!
478 $cmd = "$command -f sticky -u /redir_external -t 5 -s redirected";
479 eval {
480 local $SIG{ALRM} = sub { die "alarm\n" };
481 alarm(2);
482 $result = NPTest->testCmd( $cmd );
483 alarm(0); };
484 isnt( $@, "alarm\n", $cmd );
485 isnt( $result->return_code, 0, $cmd );
486
487 # Test an external address - timeout
488 SKIP: {
489 skip "This doesn't seem to work all the time", 1 unless ($ENV{HTTP_EXTERNAL});
490 $cmd = "$command -f follow -u /redir_external -t 5";
491 eval {
492 $result = NPTest->testCmd( $cmd, 2 );
493 };
494 like( $@, "/timeout in command: $cmd/", $cmd );
495 }
496
497 $cmd = "$command -u /timeout -t 5";
498 eval {
499 $result = NPTest->testCmd( $cmd, 2 );
500 };
501 like( $@, "/timeout in command: $cmd/", $cmd );
502
503 $cmd = "$command -f follow -u /redir_timeout -t 2";
504 eval {
505 $result = NPTest->testCmd( $cmd, 5 );
506 };
507 is( $@, "", $cmd );
508
509}