diff options
Diffstat (limited to 'plugins/tests')
-rwxr-xr-x | plugins/tests/check_http.t | 54 |
1 files changed, 51 insertions, 3 deletions
diff --git a/plugins/tests/check_http.t b/plugins/tests/check_http.t index d7f4148..b0df960 100755 --- a/plugins/tests/check_http.t +++ b/plugins/tests/check_http.t | |||
@@ -37,6 +37,9 @@ my $port_http = 50000 + int(rand(1000)); | |||
37 | my $port_https = $port_http + 1; | 37 | my $port_https = $port_http + 1; |
38 | my $port_https_expired = $port_http + 2; | 38 | my $port_https_expired = $port_http + 2; |
39 | 39 | ||
40 | # This array keeps sockets around for implementing timeouts | ||
41 | my @persist; | ||
42 | |||
40 | # Start up all servers | 43 | # Start up all servers |
41 | my @pids; | 44 | my @pids; |
42 | my $pid = fork(); | 45 | my $pid = fork(); |
@@ -93,7 +96,7 @@ if ($pid) { | |||
93 | # Run the same server on http and https | 96 | # Run the same server on http and https |
94 | sub run_server { | 97 | sub run_server { |
95 | my $d = shift; | 98 | my $d = shift; |
96 | while (my $c = $d->accept ) { | 99 | MAINLOOP: while (my $c = $d->accept ) { |
97 | while (my $r = $c->get_request) { | 100 | while (my $r = $c->get_request) { |
98 | if ($r->method eq "GET" and $r->url->path =~ m^/statuscode/(\d+)^) { | 101 | if ($r->method eq "GET" and $r->url->path =~ m^/statuscode/(\d+)^) { |
99 | $c->send_basic_header($1); | 102 | $c->send_basic_header($1); |
@@ -121,10 +124,19 @@ sub run_server { | |||
121 | $c->send_response($r->method.":".$r->content); | 124 | $c->send_response($r->method.":".$r->content); |
122 | } elsif ($r->url->path eq "/redirect") { | 125 | } elsif ($r->url->path eq "/redirect") { |
123 | $c->send_redirect( "/redirect2" ); | 126 | $c->send_redirect( "/redirect2" ); |
127 | } elsif ($r->url->path eq "/redir_external") { | ||
128 | $c->send_redirect( "http://169.254.169.254/redirect2" ); | ||
124 | } elsif ($r->url->path eq "/redirect2") { | 129 | } elsif ($r->url->path eq "/redirect2") { |
125 | $c->send_basic_header; | 130 | $c->send_basic_header; |
126 | $c->send_crlf; | 131 | $c->send_crlf; |
127 | $c->send_response("redirected"); | 132 | $c->send_response("redirected"); |
133 | } elsif ($r->url->path eq "/redir_timeout") { | ||
134 | $c->send_redirect( "/timeout" ); | ||
135 | } elsif ($r->url->path eq "/timeout") { | ||
136 | # Keep $c from being destroyed, but prevent severe leaks | ||
137 | unshift @persist, $c; | ||
138 | delete($persist[1000]); | ||
139 | next MAINLOOP; | ||
128 | } else { | 140 | } else { |
129 | $c->send_error(RC_FORBIDDEN); | 141 | $c->send_error(RC_FORBIDDEN); |
130 | } | 142 | } |
@@ -141,11 +153,11 @@ END { | |||
141 | 153 | ||
142 | if ($ARGV[0] && $ARGV[0] eq "-d") { | 154 | if ($ARGV[0] && $ARGV[0] eq "-d") { |
143 | while (1) { | 155 | while (1) { |
144 | `sleep 100` | 156 | sleep 100; |
145 | } | 157 | } |
146 | } | 158 | } |
147 | 159 | ||
148 | my $common_tests = 51; | 160 | my $common_tests = 55; |
149 | my $ssl_only_tests = 6; | 161 | my $ssl_only_tests = 6; |
150 | if (-x "./check_http") { | 162 | if (-x "./check_http") { |
151 | plan tests => $common_tests * 2 + $ssl_only_tests; | 163 | plan tests => $common_tests * 2 + $ssl_only_tests; |
@@ -315,4 +327,40 @@ sub run_common_tests { | |||
315 | is( $result->return_code, 0, $cmd); | 327 | 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 ); | 328 | like( $result->output, '/^HTTP OK: HTTP/1.1 200 OK - \d+ bytes in [\d\.]+ second/', "Output correct: ".$result->output ); |
317 | 329 | ||
330 | # These tests may block | ||
331 | print "ALRM\n"; | ||
332 | |||
333 | $cmd = "$command -f sticky -u /redir_external -t 5"; | ||
334 | eval { | ||
335 | local $SIG{ALRM} = sub { die "alarm\n" }; | ||
336 | alarm(2); | ||
337 | $result = NPTest->testCmd( $cmd ); | ||
338 | alarm(0); }; | ||
339 | isnt( $@, "alarm\n", $cmd); | ||
340 | |||
341 | # Will this one work everywhere??? | ||
342 | $cmd = "$command -f follow -u /redir_external -t 5"; | ||
343 | eval { | ||
344 | local $SIG{ALRM} = sub { die "alarm\n" }; | ||
345 | alarm(2); | ||
346 | $result = NPTest->testCmd( $cmd ); | ||
347 | alarm(0); }; | ||
348 | is( $@, "alarm\n", $cmd); | ||
349 | |||
350 | $cmd = "$command -u /timeout -t 5"; | ||
351 | eval { | ||
352 | local $SIG{ALRM} = sub { die "alarm\n" }; | ||
353 | alarm(2); | ||
354 | $result = NPTest->testCmd( $cmd ); | ||
355 | alarm(0); }; | ||
356 | is( $@, "alarm\n", $cmd); | ||
357 | |||
358 | $cmd = "$command -f follow -u /redir_timeout -t 2"; | ||
359 | eval { | ||
360 | local $SIG{ALRM} = sub { die "alarm\n" }; | ||
361 | alarm(5); | ||
362 | $result = NPTest->testCmd( $cmd ); | ||
363 | alarm(0); }; | ||
364 | isnt( $@, "alarm\n", $cmd); | ||
365 | |||
318 | } | 366 | } |