Merge pull request #2008 from waja/2.4.0
[monitoring-plugins.git] / plugins / tests / check_http.t
blob6078b274566da6957a90bef4977952e67ed4eb93
1 #! /usr/bin/perl -w -I ..
3 # Test check_http by having an actual HTTP server running
5 # To create the https server certificate:
6 # ./certs/generate-certs.sh
8 use strict;
9 use Test::More;
10 use NPTest;
11 use FindBin qw($Bin);
12 use IO::Socket::INET;
14 $ENV{'LC_TIME'} = "C";
16 my $common_tests = 71;
17 my $virtual_port_tests = 8;
18 my $ssl_only_tests = 12;
19 my $chunked_encoding_special_tests = 1;
20 # Check that all dependent modules are available
21 eval "use HTTP::Daemon 6.01;";
22 plan skip_all => 'HTTP::Daemon >= 6.01 required' if $@;
23 eval {
24 require HTTP::Status;
25 require HTTP::Response;
28 my $plugin = 'check_http';
29 $plugin = 'check_curl' if $0 =~ m/check_curl/mx;
31 if ($@) {
32 plan skip_all => "Missing required module for test: $@";
33 } else {
34 if (-x "./$plugin") {
35 plan tests => $common_tests * 2 + $ssl_only_tests + $virtual_port_tests + $chunked_encoding_special_tests;
36 } else {
37 plan skip_all => "No $plugin compiled";
41 my $servers = { http => 0 }; # HTTP::Daemon should always be available
42 eval { require HTTP::Daemon::SSL };
43 if ($@) {
44 diag "Cannot load HTTP::Daemon::SSL: $@";
45 } else {
46 $servers->{https} = 0;
49 # set a fixed version, so the header size doesn't vary
50 $HTTP::Daemon::VERSION = "1.00";
52 my $port_http = 50000 + int(rand(1000));
53 my $port_https = $port_http + 1;
54 my $port_https_expired = $port_http + 2;
55 my $port_https_clientcert = $port_http + 3;
56 my $port_hacked_http = $port_http + 4;
58 # This array keeps sockets around for implementing timeouts
59 my @persist;
61 # Start up all servers
62 my @pids;
63 # Fork a HTTP server
64 my $pid = fork;
65 defined $pid or die "Failed to fork";
66 if (!$pid) {
67 undef @pids;
68 my $d = HTTP::Daemon->new(
69 LocalPort => $port_http,
70 LocalAddr => "127.0.0.1",
71 ) || die;
72 print "Please contact http at: <URL:", $d->url, ">\n";
73 run_server( $d );
74 die "webserver stopped";
76 push @pids, $pid;
78 # Fork the hacked HTTP server
79 undef $pid;
80 $pid = fork;
81 defined $pid or die "Failed to fork";
82 if (!$pid) {
83 # this is the fork
84 undef @pids;
85 my $socket = new IO::Socket::INET (
86 LocalHost => '0.0.0.0',
87 LocalPort => $port_hacked_http,
88 Proto => 'tcp',
89 Listen => 5,
90 Reuse => 1
92 die "cannot create socket $!n" unless $socket;
93 my $local_sock = $socket->sockport();
94 print "server waiting for client connection on port $local_sock\n";
95 run_hacked_http_server ( $socket );
96 die "hacked http server stopped";
98 push @pids, $pid;
100 if (exists $servers->{https}) {
101 # Fork a normal HTTPS server
102 $pid = fork;
103 defined $pid or die "Failed to fork";
104 if (!$pid) {
105 undef @pids;
106 # closing the connection after -C cert checks make the daemon exit with a sigpipe otherwise
107 local $SIG{'PIPE'} = 'IGNORE';
108 my $d = HTTP::Daemon::SSL->new(
109 LocalPort => $port_https,
110 LocalAddr => "127.0.0.1",
111 SSL_cert_file => "$Bin/certs/server-cert.pem",
112 SSL_key_file => "$Bin/certs/server-key.pem",
113 ) || die;
114 print "Please contact https at: <URL:", $d->url, ">\n";
115 run_server( $d );
116 die "webserver stopped";
118 push @pids, $pid;
120 # Fork an expired cert server
121 $pid = fork;
122 defined $pid or die "Failed to fork";
123 if (!$pid) {
124 undef @pids;
125 # closing the connection after -C cert checks make the daemon exit with a sigpipe otherwise
126 local $SIG{'PIPE'} = 'IGNORE';
127 my $d = HTTP::Daemon::SSL->new(
128 LocalPort => $port_https_expired,
129 LocalAddr => "127.0.0.1",
130 SSL_cert_file => "$Bin/certs/expired-cert.pem",
131 SSL_key_file => "$Bin/certs/expired-key.pem",
132 ) || die;
133 print "Please contact https expired at: <URL:", $d->url, ">\n";
134 run_server( $d );
135 die "webserver stopped";
137 push @pids, $pid;
139 # Fork an client cert expecting server
140 $pid = fork;
141 defined $pid or die "Failed to fork";
142 if (!$pid) {
143 undef @pids;
144 # closing the connection after -C cert checks make the daemon exit with a sigpipe otherwise
145 local $SIG{'PIPE'} = 'IGNORE';
146 my $d = HTTP::Daemon::SSL->new(
147 LocalPort => $port_https_clientcert,
148 LocalAddr => "127.0.0.1",
149 SSL_cert_file => "$Bin/certs/server-cert.pem",
150 SSL_key_file => "$Bin/certs/server-key.pem",
151 SSL_verify_mode => IO::Socket::SSL->SSL_VERIFY_PEER | IO::Socket::SSL->SSL_VERIFY_FAIL_IF_NO_PEER_CERT,
152 SSL_ca_file => "$Bin/certs/clientca-cert.pem",
153 ) || die;
154 print "Please contact https client cert at: <URL:", $d->url, ">\n";
155 run_server( $d );
156 die "webserver stopped";
158 push @pids, $pid;
161 # give our webservers some time to startup
162 sleep(3);
164 # Run the same server on http and https
165 sub run_server {
166 my $d = shift;
167 while (1) {
168 MAINLOOP: while (my $c = $d->accept) {
169 while (my $r = $c->get_request) {
170 if ($r->method eq "GET" and $r->url->path =~ m^/statuscode/(\d+)^) {
171 $c->send_basic_header($1);
172 $c->send_crlf;
173 } elsif ($r->method eq "GET" and $r->url->path =~ m^/file/(.*)^) {
174 $c->send_basic_header;
175 $c->send_crlf;
176 $c->send_file_response("$Bin/var/$1");
177 } elsif ($r->method eq "GET" and $r->url->path eq "/slow") {
178 $c->send_basic_header;
179 $c->send_crlf;
180 sleep 1;
181 $c->send_response("slow");
182 } elsif ($r->url->path eq "/method") {
183 if ($r->method eq "DELETE") {
184 $c->send_error(HTTP::Status->RC_METHOD_NOT_ALLOWED);
185 } elsif ($r->method eq "foo") {
186 $c->send_error(HTTP::Status->RC_NOT_IMPLEMENTED);
187 } else {
188 $c->send_status_line(200, $r->method);
190 } elsif ($r->url->path eq "/postdata") {
191 $c->send_basic_header;
192 $c->send_crlf;
193 $c->send_response($r->method.":".$r->content);
194 } elsif ($r->url->path eq "/redirect") {
195 $c->send_redirect( "/redirect2" );
196 } elsif ($r->url->path eq "/redir_external") {
197 $c->send_redirect(($d->isa('HTTP::Daemon::SSL') ? "https" : "http") . "://169.254.169.254/redirect2" );
198 } elsif ($r->url->path eq "/redirect2") {
199 $c->send_basic_header;
200 $c->send_crlf;
201 $c->send_response(HTTP::Response->new( 200, 'OK', undef, 'redirected' ));
202 } elsif ($r->url->path eq "/redir_timeout") {
203 $c->send_redirect( "/timeout" );
204 } elsif ($r->url->path eq "/timeout") {
205 # Keep $c from being destroyed, but prevent severe leaks
206 unshift @persist, $c;
207 delete($persist[1000]);
208 next MAINLOOP;
209 } elsif ($r->url->path eq "/header_check") {
210 $c->send_basic_header;
211 $c->send_header('foo');
212 $c->send_crlf;
213 } elsif ($r->url->path eq "/virtual_port") {
214 # return sent Host header
215 $c->send_basic_header;
216 $c->send_crlf;
217 $c->send_response(HTTP::Response->new( 200, 'OK', undef, $r->header ('Host')));
218 } elsif ($r->url->path eq "/chunked") {
219 my $chunks = ["chunked", "encoding", "test\n"];
220 $c->send_response(HTTP::Response->new( 200, 'OK', undef, sub {
221 my $chunk = shift @{$chunks};
222 return unless $chunk;
223 sleep(1);
224 return($chunk);
225 }));
226 } else {
227 $c->send_error(HTTP::Status->RC_FORBIDDEN);
229 $c->close;
235 sub run_hacked_http_server {
236 my $socket = shift;
238 # auto-flush on socket
239 $| = 1;
242 while(1)
244 # waiting for a new client connection
245 my $client_socket = $socket->accept();
247 # get information about a newly connected client
248 my $client_address = $client_socket->peerhost();
249 my $client_portn = $client_socket->peerport();
250 print "connection from $client_address:$client_portn";
252 # read up to 1024 characters from the connected client
253 my $data = "";
254 $client_socket->recv($data, 1024);
255 print "received data: $data";
257 # write response data to the connected client
258 $data = "HTTP/1.1 200 OK\r\nTransfer-Encoding: chunked\r\n\r\n0\r\n\r\n";
259 $client_socket->send($data);
261 # notify client that response has been sent
262 shutdown($client_socket, 1);
266 END {
267 foreach my $pid (@pids) {
268 if ($pid) { print "Killing $pid\n"; kill "INT", $pid }
272 if ($ARGV[0] && $ARGV[0] eq "-d") {
273 while (1) {
274 sleep 100;
278 my $result;
279 my $command = "./$plugin -H 127.0.0.1";
281 run_chunked_encoding_special_test( {command => "$command -p $port_hacked_http"});
282 run_common_tests( { command => "$command -p $port_http" } );
283 SKIP: {
284 skip "HTTP::Daemon::SSL not installed", $common_tests + $ssl_only_tests if ! exists $servers->{https};
285 run_common_tests( { command => "$command -p $port_https", ssl => 1 } );
287 my $expiry = "Thu Nov 28 21:02:11 2030 +0000";
289 $result = NPTest->testCmd( "$command -p $port_https -S -C 14" );
290 is( $result->return_code, 0, "$command -p $port_https -S -C 14" );
291 is( $result->output, "OK - Certificate 'Monitoring Plugins' will expire on $expiry.", "output ok" );
293 $result = NPTest->testCmd( "$command -p $port_https -S -C 14000" );
294 is( $result->return_code, 1, "$command -p $port_https -S -C 14000" );
295 like( $result->output, '/WARNING - Certificate \'Monitoring Plugins\' expires in \d+ day\(s\) \(' . quotemeta($expiry) . '\)./', "output ok" );
297 # Expired cert tests
298 $result = NPTest->testCmd( "$command -p $port_https -S -C 13960,14000" );
299 is( $result->return_code, 2, "$command -p $port_https -S -C 13960,14000" );
300 like( $result->output, '/CRITICAL - Certificate \'Monitoring Plugins\' expires in \d+ day\(s\) \(' . quotemeta($expiry) . '\)./', "output ok" );
302 $result = NPTest->testCmd( "$command -p $port_https_expired -S -C 7" );
303 is( $result->return_code, 2, "$command -p $port_https_expired -S -C 7" );
304 is( $result->output,
305 'CRITICAL - Certificate \'Monitoring Plugins\' expired on Wed Jan 2 12:00:00 2008 +0000.',
306 "output ok" );
308 # client cert tests
309 my $cmd;
310 $cmd = "$command -p $port_https_clientcert"
311 . " -J \"$Bin/certs/client-cert.pem\""
312 . " -K \"$Bin/certs/client-key.pem\""
313 . " -u /statuscode/200";
314 $result = NPTest->testCmd($cmd);
315 is( $result->return_code, 0, $cmd);
316 like( $result->output, '/^HTTP OK: HTTP/1.1 200 OK - \d+ bytes in [\d\.]+ second/', "Output correct: ".$result->output );
318 $cmd = "$command -p $port_https_clientcert"
319 . " -J \"$Bin/certs/clientchain-cert.pem\""
320 . " -K \"$Bin/certs/clientchain-key.pem\""
321 . " -u /statuscode/200";
322 $result = NPTest->testCmd($cmd);
323 is( $result->return_code, 0, $cmd);
324 like( $result->output, '/^HTTP OK: HTTP/1.1 200 OK - \d+ bytes in [\d\.]+ second/', "Output correct: ".$result->output );
327 my $cmd;
328 # check virtual port behaviour
330 # http without virtual port
331 $cmd = "$command -p $port_http -u /virtual_port -r ^127.0.0.1:$port_http\$";
332 $result = NPTest->testCmd( $cmd );
333 is( $result->return_code, 0, $cmd);
334 like( $result->output, '/^HTTP OK: HTTP/1.1 200 OK - \d+ bytes in [\d\.]+ second/', "Output correct: ".$result->output );
336 # http with virtual port
337 $cmd = "$command:80 -p $port_http -u /virtual_port -r ^127.0.0.1\$";
338 $result = NPTest->testCmd( $cmd );
339 is( $result->return_code, 0, $cmd);
340 like( $result->output, '/^HTTP OK: HTTP/1.1 200 OK - \d+ bytes in [\d\.]+ second/', "Output correct: ".$result->output );
342 SKIP: {
343 skip "HTTP::Daemon::SSL not installed", 4 if ! exists $servers->{https};
344 # https without virtual port
345 $cmd = "$command -p $port_https --ssl -u /virtual_port -r ^127.0.0.1:$port_https\$";
346 $result = NPTest->testCmd( $cmd );
347 is( $result->return_code, 0, $cmd);
348 like( $result->output, '/^HTTP OK: HTTP/1.1 200 OK - \d+ bytes in [\d\.]+ second/', "Output correct: ".$result->output );
350 # https with virtual port
351 $cmd = "$command:443 -p $port_https --ssl -u /virtual_port -r ^127.0.0.1\$";
352 $result = NPTest->testCmd( $cmd );
353 is( $result->return_code, 0, $cmd);
354 like( $result->output, '/^HTTP OK: HTTP/1.1 200 OK - \d+ bytes in [\d\.]+ second/', "Output correct: ".$result->output );
358 sub run_common_tests {
359 my ($opts) = @_;
360 my $command = $opts->{command};
361 if ($opts->{ssl}) {
362 $command .= " --ssl";
365 $result = NPTest->testCmd( "$command -u /file/root" );
366 is( $result->return_code, 0, "/file/root");
367 like( $result->output, '/^HTTP OK: HTTP/1.1 200 OK - 274 bytes in [\d\.]+ second/', "Output correct" );
369 $result = NPTest->testCmd( "$command -u /file/root -s Root" );
370 is( $result->return_code, 0, "/file/root search for string");
371 like( $result->output, '/^HTTP OK: HTTP/1.1 200 OK - 274 bytes in [\d\.]+ second/', "Output correct" );
373 $result = NPTest->testCmd( "$command -u /file/root -s NonRoot" );
374 is( $result->return_code, 2, "Missing string check");
375 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");
377 $result = NPTest->testCmd( "$command -u /file/root -s NonRootWithOver30charsAndMoreFunThanAWetFish" );
378 is( $result->return_code, 2, "Missing string check");
379 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");
381 $result = NPTest->testCmd( "$command -u /header_check -d foo" );
382 is( $result->return_code, 0, "header_check search for string");
383 like( $result->output, '/^HTTP OK: HTTP/1.1 200 OK - 96 bytes in [\d\.]+ second/', "Output correct" );
385 $result = NPTest->testCmd( "$command -u /header_check -d bar" );
386 is( $result->return_code, 2, "Missing header string check");
387 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");
389 my $cmd;
390 $cmd = "$command -u /slow";
391 $result = NPTest->testCmd( $cmd );
392 is( $result->return_code, 0, "$cmd");
393 like( $result->output, '/^HTTP OK: HTTP/1.1 200 OK - \d+ bytes in [\d\.]+ second/', "Output correct: ".$result->output );
394 $result->output =~ /in ([\d\.]+) second/;
395 cmp_ok( $1, ">", 1, "Time is > 1 second" );
397 $cmd = "$command -u /statuscode/200";
398 $result = NPTest->testCmd( $cmd );
399 is( $result->return_code, 0, $cmd);
400 like( $result->output, '/^HTTP OK: HTTP/1.1 200 OK - \d+ bytes in [\d\.]+ second/', "Output correct: ".$result->output );
402 $cmd = "$command -u /statuscode/200 -e 200";
403 $result = NPTest->testCmd( $cmd );
404 is( $result->return_code, 0, $cmd);
405 like( $result->output, '/^HTTP OK: Status line output matched "200" - \d+ bytes in [\d\.]+ second/', "Output correct: ".$result->output );
407 $cmd = "$command -u /statuscode/201";
408 $result = NPTest->testCmd( $cmd );
409 is( $result->return_code, 0, $cmd);
410 like( $result->output, '/^HTTP OK: HTTP/1.1 201 Created - \d+ bytes in [\d\.]+ second /', "Output correct: ".$result->output );
412 $cmd = "$command -u /statuscode/201 -e 201";
413 $result = NPTest->testCmd( $cmd );
414 is( $result->return_code, 0, $cmd);
415 like( $result->output, '/^HTTP OK: Status line output matched "201" - \d+ bytes in [\d\.]+ second /', "Output correct: ".$result->output );
417 $cmd = "$command -u /statuscode/201 -e 200";
418 $result = NPTest->testCmd( $cmd );
419 is( $result->return_code, 2, $cmd);
420 like( $result->output, '/^HTTP CRITICAL - Invalid HTTP response received from host on port \d+: HTTP/1.1 201 Created/', "Output correct: ".$result->output );
422 $cmd = "$command -u /statuscode/200 -e 200,201,202";
423 $result = NPTest->testCmd( $cmd );
424 is( $result->return_code, 0, $cmd);
425 like( $result->output, '/^HTTP OK: Status line output matched "200,201,202" - \d+ bytes in [\d\.]+ second/', "Output correct: ".$result->output );
427 $cmd = "$command -u /statuscode/201 -e 200,201,202";
428 $result = NPTest->testCmd( $cmd );
429 is( $result->return_code, 0, $cmd);
430 like( $result->output, '/^HTTP OK: Status line output matched "200,201,202" - \d+ bytes in [\d\.]+ second/', "Output correct: ".$result->output );
432 $cmd = "$command -u /statuscode/203 -e 200,201,202";
433 $result = NPTest->testCmd( $cmd );
434 is( $result->return_code, 2, $cmd);
435 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 );
437 $cmd = "$command -j HEAD -u /method";
438 $result = NPTest->testCmd( $cmd );
439 is( $result->return_code, 0, $cmd);
440 like( $result->output, '/^HTTP OK: HTTP/1.1 200 HEAD - \d+ bytes in [\d\.]+ second/', "Output correct: ".$result->output );
442 $cmd = "$command -j POST -u /method";
443 $result = NPTest->testCmd( $cmd );
444 is( $result->return_code, 0, $cmd);
445 like( $result->output, '/^HTTP OK: HTTP/1.1 200 POST - \d+ bytes in [\d\.]+ second/', "Output correct: ".$result->output );
447 $cmd = "$command -j GET -u /method";
448 $result = NPTest->testCmd( $cmd );
449 is( $result->return_code, 0, $cmd);
450 like( $result->output, '/^HTTP OK: HTTP/1.1 200 GET - \d+ bytes in [\d\.]+ second/', "Output correct: ".$result->output );
452 $cmd = "$command -u /method";
453 $result = NPTest->testCmd( $cmd );
454 is( $result->return_code, 0, $cmd);
455 like( $result->output, '/^HTTP OK: HTTP/1.1 200 GET - \d+ bytes in [\d\.]+ second/', "Output correct: ".$result->output );
457 $cmd = "$command -P foo -u /method";
458 $result = NPTest->testCmd( $cmd );
459 is( $result->return_code, 0, $cmd);
460 like( $result->output, '/^HTTP OK: HTTP/1.1 200 POST - \d+ bytes in [\d\.]+ second/', "Output correct: ".$result->output );
462 $cmd = "$command -j DELETE -u /method";
463 $result = NPTest->testCmd( $cmd );
464 is( $result->return_code, 1, $cmd);
465 like( $result->output, '/^HTTP WARNING: HTTP/1.1 405 Method Not Allowed/', "Output correct: ".$result->output );
467 $cmd = "$command -j foo -u /method";
468 $result = NPTest->testCmd( $cmd );
469 is( $result->return_code, 2, $cmd);
470 like( $result->output, '/^HTTP CRITICAL: HTTP/1.1 501 Not Implemented/', "Output correct: ".$result->output );
472 $cmd = "$command -P stufftoinclude -u /postdata -s POST:stufftoinclude";
473 $result = NPTest->testCmd( $cmd );
474 is( $result->return_code, 0, $cmd);
475 like( $result->output, '/^HTTP OK: HTTP/1.1 200 OK - \d+ bytes in [\d\.]+ second/', "Output correct: ".$result->output );
477 $cmd = "$command -j PUT -P stufftoinclude -u /postdata -s PUT:stufftoinclude";
478 $result = NPTest->testCmd( $cmd );
479 is( $result->return_code, 0, $cmd);
480 like( $result->output, '/^HTTP OK: HTTP/1.1 200 OK - \d+ bytes in [\d\.]+ second/', "Output correct: ".$result->output );
482 # To confirm that the free doesn't segfault
483 $cmd = "$command -P stufftoinclude -j PUT -u /postdata -s PUT:stufftoinclude";
484 $result = NPTest->testCmd( $cmd );
485 is( $result->return_code, 0, $cmd);
486 like( $result->output, '/^HTTP OK: HTTP/1.1 200 OK - \d+ bytes in [\d\.]+ second/', "Output correct: ".$result->output );
488 $cmd = "$command -u /redirect";
489 $result = NPTest->testCmd( $cmd );
490 is( $result->return_code, 0, $cmd);
491 like( $result->output, '/^HTTP OK: HTTP/1.1 301 Moved Permanently - \d+ bytes in [\d\.]+ second/', "Output correct: ".$result->output );
493 $cmd = "$command -f follow -u /redirect";
494 $result = NPTest->testCmd( $cmd );
495 is( $result->return_code, 0, $cmd);
496 like( $result->output, '/^HTTP OK: HTTP/1.1 200 OK - \d+ bytes in [\d\.]+ second/', "Output correct: ".$result->output );
498 $cmd = "$command -u /redirect -k 'follow: me'";
499 $result = NPTest->testCmd( $cmd );
500 is( $result->return_code, 0, $cmd);
501 like( $result->output, '/^HTTP OK: HTTP/1.1 301 Moved Permanently - \d+ bytes in [\d\.]+ second/', "Output correct: ".$result->output );
503 $cmd = "$command -f follow -u /redirect -k 'follow: me'";
504 $result = NPTest->testCmd( $cmd );
505 is( $result->return_code, 0, $cmd);
506 like( $result->output, '/^HTTP OK: HTTP/1.1 200 OK - \d+ bytes in [\d\.]+ second/', "Output correct: ".$result->output );
508 $cmd = "$command -f sticky -u /redirect -k 'follow: me'";
509 $result = NPTest->testCmd( $cmd );
510 is( $result->return_code, 0, $cmd);
511 like( $result->output, '/^HTTP OK: HTTP/1.1 200 OK - \d+ bytes in [\d\.]+ second/', "Output correct: ".$result->output );
513 $cmd = "$command -f stickyport -u /redirect -k 'follow: me'";
514 $result = NPTest->testCmd( $cmd );
515 is( $result->return_code, 0, $cmd);
516 like( $result->output, '/^HTTP OK: HTTP/1.1 200 OK - \d+ bytes in [\d\.]+ second/', "Output correct: ".$result->output );
518 # These tests may block
519 print "ALRM\n";
521 # stickyport - on full urlS port is set back to 80 otherwise
522 $cmd = "$command -f stickyport -u /redir_external -t 5 -s redirected";
523 alarm(2);
524 eval {
525 local $SIG{ALRM} = sub { die "alarm\n" };
526 $result = NPTest->testCmd( $cmd );
528 isnt( $@, "alarm\n", $cmd );
529 alarm(0);
530 is( $result->return_code, 0, $cmd );
532 # Let's hope there won't be any web server on :80 returning "redirected"!
533 $cmd = "$command -f sticky -u /redir_external -t 5 -s redirected";
534 alarm(2);
535 eval {
536 local $SIG{ALRM} = sub { die "alarm\n" };
537 $result = NPTest->testCmd( $cmd );
539 isnt( $@, "alarm\n", $cmd );
540 alarm(0);
541 isnt( $result->return_code, 0, $cmd );
543 # Test an external address - timeout
544 SKIP: {
545 skip "This doesn't seem to work all the time", 1 unless ($ENV{HTTP_EXTERNAL});
546 $cmd = "$command -f follow -u /redir_external -t 5";
547 eval {
548 $result = NPTest->testCmd( $cmd, 2 );
550 like( $@, "/timeout in command: $cmd/", $cmd );
553 $cmd = "$command -u /timeout -t 5";
554 eval {
555 $result = NPTest->testCmd( $cmd, 2 );
557 like( $@, "/timeout in command: $cmd/", $cmd );
559 $cmd = "$command -f follow -u /redir_timeout -t 2";
560 eval {
561 $result = NPTest->testCmd( $cmd, 5 );
563 is( $@, "", $cmd );
565 $cmd = "$command -u /chunked -s 'chunkedencodingtest' -d 'Transfer-Encoding: chunked'";
566 eval {
567 $result = NPTest->testCmd( $cmd, 5 );
569 is( $@, "", $cmd );
572 sub run_chunked_encoding_special_test {
573 my ($opts) = @_;
574 my $command = $opts->{command};
576 $cmd = "$command -u / -s 'ChunkedEncodingSpecialTest'";
577 eval {
578 $result = NPTest->testCmd( $cmd, 5 );
580 is( $@, "", $cmd );