diff options
Diffstat (limited to 'plugins/tests/check_http.t')
-rwxr-xr-x | plugins/tests/check_http.t | 392 |
1 files changed, 280 insertions, 112 deletions
diff --git a/plugins/tests/check_http.t b/plugins/tests/check_http.t index e72d243a..6078b274 100755 --- a/plugins/tests/check_http.t +++ b/plugins/tests/check_http.t | |||
@@ -3,22 +3,20 @@ | |||
3 | # Test check_http by having an actual HTTP server running | 3 | # Test check_http by having an actual HTTP server running |
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 | # ./certs/generate-certs.sh |
7 | # Country Name (2 letter code) [AU]:UK | ||
8 | # State or Province Name (full name) [Some-State]:Derbyshire | ||
9 | # Locality Name (eg, city) []:Belper | ||
10 | # Organization Name (eg, company) [Internet Widgits Pty Ltd]:Monitoring Plugins | ||
11 | # Organizational Unit Name (eg, section) []: | ||
12 | # Common Name (eg, YOUR name) []:Ton Voon | ||
13 | # Email Address []:tonvoon@mac.com | ||
14 | 7 | ||
15 | use strict; | 8 | use strict; |
16 | use Test::More; | 9 | use Test::More; |
17 | use NPTest; | 10 | use NPTest; |
18 | use FindBin qw($Bin); | 11 | use FindBin qw($Bin); |
12 | use IO::Socket::INET; | ||
19 | 13 | ||
20 | my $common_tests = 70; | 14 | $ENV{'LC_TIME'} = "C"; |
21 | my $ssl_only_tests = 8; | 15 | |
16 | my $common_tests = 71; | ||
17 | my $virtual_port_tests = 8; | ||
18 | my $ssl_only_tests = 12; | ||
19 | my $chunked_encoding_special_tests = 1; | ||
22 | # Check that all dependent modules are available | 20 | # Check that all dependent modules are available |
23 | eval "use HTTP::Daemon 6.01;"; | 21 | eval "use HTTP::Daemon 6.01;"; |
24 | plan skip_all => 'HTTP::Daemon >= 6.01 required' if $@; | 22 | plan skip_all => 'HTTP::Daemon >= 6.01 required' if $@; |
@@ -27,13 +25,16 @@ eval { | |||
27 | require HTTP::Response; | 25 | require HTTP::Response; |
28 | }; | 26 | }; |
29 | 27 | ||
28 | my $plugin = 'check_http'; | ||
29 | $plugin = 'check_curl' if $0 =~ m/check_curl/mx; | ||
30 | |||
30 | if ($@) { | 31 | if ($@) { |
31 | plan skip_all => "Missing required module for test: $@"; | 32 | plan skip_all => "Missing required module for test: $@"; |
32 | } else { | 33 | } else { |
33 | if (-x "./check_http") { | 34 | if (-x "./$plugin") { |
34 | plan tests => $common_tests * 2 + $ssl_only_tests; | 35 | plan tests => $common_tests * 2 + $ssl_only_tests + $virtual_port_tests + $chunked_encoding_special_tests; |
35 | } else { | 36 | } else { |
36 | plan skip_all => "No check_http compiled"; | 37 | plan skip_all => "No $plugin compiled"; |
37 | } | 38 | } |
38 | } | 39 | } |
39 | 40 | ||
@@ -51,119 +52,217 @@ $HTTP::Daemon::VERSION = "1.00"; | |||
51 | my $port_http = 50000 + int(rand(1000)); | 52 | my $port_http = 50000 + int(rand(1000)); |
52 | my $port_https = $port_http + 1; | 53 | my $port_https = $port_http + 1; |
53 | my $port_https_expired = $port_http + 2; | 54 | my $port_https_expired = $port_http + 2; |
55 | my $port_https_clientcert = $port_http + 3; | ||
56 | my $port_hacked_http = $port_http + 4; | ||
54 | 57 | ||
55 | # This array keeps sockets around for implementing timeouts | 58 | # This array keeps sockets around for implementing timeouts |
56 | my @persist; | 59 | my @persist; |
57 | 60 | ||
58 | # Start up all servers | 61 | # Start up all servers |
59 | my @pids; | 62 | my @pids; |
60 | my $pid = fork(); | 63 | # Fork a HTTP server |
61 | if ($pid) { | 64 | my $pid = fork; |
62 | # Parent | 65 | defined $pid or die "Failed to fork"; |
63 | push @pids, $pid; | 66 | if (!$pid) { |
64 | if (exists $servers->{https}) { | 67 | undef @pids; |
65 | # Fork a normal HTTPS server | ||
66 | $pid = fork(); | ||
67 | if ($pid) { | ||
68 | # Parent | ||
69 | push @pids, $pid; | ||
70 | # Fork an expired cert server | ||
71 | $pid = fork(); | ||
72 | if ($pid) { | ||
73 | push @pids, $pid; | ||
74 | } else { | ||
75 | my $d = HTTP::Daemon::SSL->new( | ||
76 | LocalPort => $port_https_expired, | ||
77 | LocalAddr => "127.0.0.1", | ||
78 | SSL_cert_file => "$Bin/certs/expired-cert.pem", | ||
79 | SSL_key_file => "$Bin/certs/expired-key.pem", | ||
80 | ) || die; | ||
81 | print "Please contact https expired at: <URL:", $d->url, ">\n"; | ||
82 | run_server( $d ); | ||
83 | exit; | ||
84 | } | ||
85 | } else { | ||
86 | my $d = HTTP::Daemon::SSL->new( | ||
87 | LocalPort => $port_https, | ||
88 | LocalAddr => "127.0.0.1", | ||
89 | SSL_cert_file => "$Bin/certs/server-cert.pem", | ||
90 | SSL_key_file => "$Bin/certs/server-key.pem", | ||
91 | ) || die; | ||
92 | print "Please contact https at: <URL:", $d->url, ">\n"; | ||
93 | run_server( $d ); | ||
94 | exit; | ||
95 | } | ||
96 | } | ||
97 | # give our webservers some time to startup | ||
98 | sleep(1); | ||
99 | } else { | ||
100 | # Child | ||
101 | #print "child\n"; | ||
102 | my $d = HTTP::Daemon->new( | 68 | my $d = HTTP::Daemon->new( |
103 | LocalPort => $port_http, | 69 | LocalPort => $port_http, |
104 | LocalAddr => "127.0.0.1", | 70 | LocalAddr => "127.0.0.1", |
105 | ) || die; | 71 | ) || die; |
106 | print "Please contact http at: <URL:", $d->url, ">\n"; | 72 | print "Please contact http at: <URL:", $d->url, ">\n"; |
107 | run_server( $d ); | 73 | run_server( $d ); |
108 | exit; | 74 | die "webserver stopped"; |
75 | } | ||
76 | push @pids, $pid; | ||
77 | |||
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 | ||
91 | ); | ||
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"; | ||
97 | } | ||
98 | push @pids, $pid; | ||
99 | |||
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"; | ||
117 | } | ||
118 | push @pids, $pid; | ||
119 | |||
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"; | ||
136 | } | ||
137 | push @pids, $pid; | ||
138 | |||
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"; | ||
157 | } | ||
158 | push @pids, $pid; | ||
109 | } | 159 | } |
110 | 160 | ||
161 | # give our webservers some time to startup | ||
162 | sleep(3); | ||
163 | |||
111 | # Run the same server on http and https | 164 | # Run the same server on http and https |
112 | sub run_server { | 165 | sub run_server { |
113 | my $d = shift; | 166 | my $d = shift; |
114 | MAINLOOP: while (my $c = $d->accept ) { | 167 | while (1) { |
115 | while (my $r = $c->get_request) { | 168 | MAINLOOP: while (my $c = $d->accept) { |
116 | if ($r->method eq "GET" and $r->url->path =~ m^/statuscode/(\d+)^) { | 169 | while (my $r = $c->get_request) { |
117 | $c->send_basic_header($1); | 170 | if ($r->method eq "GET" and $r->url->path =~ m^/statuscode/(\d+)^) { |
118 | $c->send_crlf; | 171 | $c->send_basic_header($1); |
119 | } elsif ($r->method eq "GET" and $r->url->path =~ m^/file/(.*)^) { | 172 | $c->send_crlf; |
120 | $c->send_basic_header; | 173 | } elsif ($r->method eq "GET" and $r->url->path =~ m^/file/(.*)^) { |
121 | $c->send_crlf; | 174 | $c->send_basic_header; |
122 | $c->send_file_response("$Bin/var/$1"); | 175 | $c->send_crlf; |
123 | } elsif ($r->method eq "GET" and $r->url->path eq "/slow") { | 176 | $c->send_file_response("$Bin/var/$1"); |
124 | $c->send_basic_header; | 177 | } elsif ($r->method eq "GET" and $r->url->path eq "/slow") { |
125 | $c->send_crlf; | 178 | $c->send_basic_header; |
126 | sleep 1; | 179 | $c->send_crlf; |
127 | $c->send_response("slow"); | 180 | sleep 1; |
128 | } elsif ($r->url->path eq "/method") { | 181 | $c->send_response("slow"); |
129 | if ($r->method eq "DELETE") { | 182 | } elsif ($r->url->path eq "/method") { |
130 | $c->send_error(HTTP::Status->RC_METHOD_NOT_ALLOWED); | 183 | if ($r->method eq "DELETE") { |
131 | } elsif ($r->method eq "foo") { | 184 | $c->send_error(HTTP::Status->RC_METHOD_NOT_ALLOWED); |
132 | $c->send_error(HTTP::Status->RC_NOT_IMPLEMENTED); | 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); | ||
189 | } | ||
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 | })); | ||
133 | } else { | 226 | } else { |
134 | $c->send_status_line(200, $r->method); | 227 | $c->send_error(HTTP::Status->RC_FORBIDDEN); |
135 | } | 228 | } |
136 | } elsif ($r->url->path eq "/postdata") { | 229 | $c->close; |
137 | $c->send_basic_header; | ||
138 | $c->send_crlf; | ||
139 | $c->send_response($r->method.":".$r->content); | ||
140 | } elsif ($r->url->path eq "/redirect") { | ||
141 | $c->send_redirect( "/redirect2" ); | ||
142 | } elsif ($r->url->path eq "/redir_external") { | ||
143 | $c->send_redirect(($d->isa('HTTP::Daemon::SSL') ? "https" : "http") . "://169.254.169.254/redirect2" ); | ||
144 | } elsif ($r->url->path eq "/redirect2") { | ||
145 | $c->send_basic_header; | ||
146 | $c->send_crlf; | ||
147 | $c->send_response(HTTP::Response->new( 200, 'OK', undef, 'redirected' )); | ||
148 | } elsif ($r->url->path eq "/redir_timeout") { | ||
149 | $c->send_redirect( "/timeout" ); | ||
150 | } elsif ($r->url->path eq "/timeout") { | ||
151 | # Keep $c from being destroyed, but prevent severe leaks | ||
152 | unshift @persist, $c; | ||
153 | delete($persist[1000]); | ||
154 | next MAINLOOP; | ||
155 | } elsif ($r->url->path eq "/header_check") { | ||
156 | $c->send_basic_header; | ||
157 | $c->send_header('foo'); | ||
158 | $c->send_crlf; | ||
159 | } else { | ||
160 | $c->send_error(HTTP::Status->RC_FORBIDDEN); | ||
161 | } | 230 | } |
162 | $c->close; | ||
163 | } | 231 | } |
164 | } | 232 | } |
165 | } | 233 | } |
166 | 234 | ||
235 | sub run_hacked_http_server { | ||
236 | my $socket = shift; | ||
237 | |||
238 | # auto-flush on socket | ||
239 | $| = 1; | ||
240 | |||
241 | |||
242 | while(1) | ||
243 | { | ||
244 | # waiting for a new client connection | ||
245 | my $client_socket = $socket->accept(); | ||
246 | |||
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"; | ||
251 | |||
252 | # read up to 1024 characters from the connected client | ||
253 | my $data = ""; | ||
254 | $client_socket->recv($data, 1024); | ||
255 | print "received data: $data"; | ||
256 | |||
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); | ||
260 | |||
261 | # notify client that response has been sent | ||
262 | shutdown($client_socket, 1); | ||
263 | } | ||
264 | } | ||
265 | |||
167 | END { | 266 | END { |
168 | foreach my $pid (@pids) { | 267 | foreach my $pid (@pids) { |
169 | if ($pid) { print "Killing $pid\n"; kill "INT", $pid } | 268 | if ($pid) { print "Killing $pid\n"; kill "INT", $pid } |
@@ -177,34 +276,85 @@ if ($ARGV[0] && $ARGV[0] eq "-d") { | |||
177 | } | 276 | } |
178 | 277 | ||
179 | my $result; | 278 | my $result; |
180 | my $command = "./check_http -H 127.0.0.1"; | 279 | my $command = "./$plugin -H 127.0.0.1"; |
181 | 280 | ||
281 | run_chunked_encoding_special_test( {command => "$command -p $port_hacked_http"}); | ||
182 | run_common_tests( { command => "$command -p $port_http" } ); | 282 | run_common_tests( { command => "$command -p $port_http" } ); |
183 | SKIP: { | 283 | SKIP: { |
184 | skip "HTTP::Daemon::SSL not installed", $common_tests + $ssl_only_tests if ! exists $servers->{https}; | 284 | skip "HTTP::Daemon::SSL not installed", $common_tests + $ssl_only_tests if ! exists $servers->{https}; |
185 | run_common_tests( { command => "$command -p $port_https", ssl => 1 } ); | 285 | run_common_tests( { command => "$command -p $port_https", ssl => 1 } ); |
186 | 286 | ||
287 | my $expiry = "Thu Nov 28 21:02:11 2030 +0000"; | ||
288 | |||
187 | $result = NPTest->testCmd( "$command -p $port_https -S -C 14" ); | 289 | $result = NPTest->testCmd( "$command -p $port_https -S -C 14" ); |
188 | is( $result->return_code, 0, "$command -p $port_https -S -C 14" ); | 290 | is( $result->return_code, 0, "$command -p $port_https -S -C 14" ); |
189 | is( $result->output, 'OK - Certificate \'Ton Voon\' will expire on Sun Mar 3 21:41:28 2019.', "output ok" ); | 291 | is( $result->output, "OK - Certificate 'Monitoring Plugins' will expire on $expiry.", "output ok" ); |
190 | 292 | ||
191 | $result = NPTest->testCmd( "$command -p $port_https -S -C 14000" ); | 293 | $result = NPTest->testCmd( "$command -p $port_https -S -C 14000" ); |
192 | is( $result->return_code, 1, "$command -p $port_https -S -C 14000" ); | 294 | is( $result->return_code, 1, "$command -p $port_https -S -C 14000" ); |
193 | like( $result->output, '/WARNING - Certificate \'Ton Voon\' expires in \d+ day\(s\) \(Sun Mar 3 21:41:28 2019\)./', "output ok" ); | 295 | like( $result->output, '/WARNING - Certificate \'Monitoring Plugins\' expires in \d+ day\(s\) \(' . quotemeta($expiry) . '\)./', "output ok" ); |
194 | 296 | ||
195 | # Expired cert tests | 297 | # Expired cert tests |
196 | $result = NPTest->testCmd( "$command -p $port_https -S -C 13960,14000" ); | 298 | $result = NPTest->testCmd( "$command -p $port_https -S -C 13960,14000" ); |
197 | is( $result->return_code, 2, "$command -p $port_https -S -C 13960,14000" ); | 299 | is( $result->return_code, 2, "$command -p $port_https -S -C 13960,14000" ); |
198 | like( $result->output, '/CRITICAL - Certificate \'Ton Voon\' expires in \d+ day\(s\) \(Sun Mar 3 21:41:28 2019\)./', "output ok" ); | 300 | like( $result->output, '/CRITICAL - Certificate \'Monitoring Plugins\' expires in \d+ day\(s\) \(' . quotemeta($expiry) . '\)./', "output ok" ); |
199 | 301 | ||
200 | $result = NPTest->testCmd( "$command -p $port_https_expired -S -C 7" ); | 302 | $result = NPTest->testCmd( "$command -p $port_https_expired -S -C 7" ); |
201 | is( $result->return_code, 2, "$command -p $port_https_expired -S -C 7" ); | 303 | is( $result->return_code, 2, "$command -p $port_https_expired -S -C 7" ); |
202 | is( $result->output, | 304 | is( $result->output, |
203 | 'CRITICAL - Certificate \'Ton Voon\' expired on Thu Mar 5 00:13:16 2009.', | 305 | 'CRITICAL - Certificate \'Monitoring Plugins\' expired on Wed Jan 2 12:00:00 2008 +0000.', |
204 | "output ok" ); | 306 | "output ok" ); |
205 | 307 | ||
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 ); | ||
317 | |||
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 ); | ||
325 | } | ||
326 | |||
327 | my $cmd; | ||
328 | # check virtual port behaviour | ||
329 | # | ||
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 ); | ||
335 | |||
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 ); | ||
341 | |||
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 ); | ||
349 | |||
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 ); | ||
206 | } | 355 | } |
207 | 356 | ||
357 | |||
208 | sub run_common_tests { | 358 | sub run_common_tests { |
209 | my ($opts) = @_; | 359 | my ($opts) = @_; |
210 | my $command = $opts->{command}; | 360 | my $command = $opts->{command}; |
@@ -370,27 +520,29 @@ sub run_common_tests { | |||
370 | 520 | ||
371 | # stickyport - on full urlS port is set back to 80 otherwise | 521 | # stickyport - on full urlS port is set back to 80 otherwise |
372 | $cmd = "$command -f stickyport -u /redir_external -t 5 -s redirected"; | 522 | $cmd = "$command -f stickyport -u /redir_external -t 5 -s redirected"; |
523 | alarm(2); | ||
373 | eval { | 524 | eval { |
374 | local $SIG{ALRM} = sub { die "alarm\n" }; | 525 | local $SIG{ALRM} = sub { die "alarm\n" }; |
375 | alarm(2); | ||
376 | $result = NPTest->testCmd( $cmd ); | 526 | $result = NPTest->testCmd( $cmd ); |
377 | alarm(0); }; | 527 | }; |
378 | isnt( $@, "alarm\n", $cmd ); | 528 | isnt( $@, "alarm\n", $cmd ); |
529 | alarm(0); | ||
379 | is( $result->return_code, 0, $cmd ); | 530 | is( $result->return_code, 0, $cmd ); |
380 | 531 | ||
381 | # Let's hope there won't be any web server on :80 returning "redirected"! | 532 | # Let's hope there won't be any web server on :80 returning "redirected"! |
382 | $cmd = "$command -f sticky -u /redir_external -t 5 -s redirected"; | 533 | $cmd = "$command -f sticky -u /redir_external -t 5 -s redirected"; |
534 | alarm(2); | ||
383 | eval { | 535 | eval { |
384 | local $SIG{ALRM} = sub { die "alarm\n" }; | 536 | local $SIG{ALRM} = sub { die "alarm\n" }; |
385 | alarm(2); | ||
386 | $result = NPTest->testCmd( $cmd ); | 537 | $result = NPTest->testCmd( $cmd ); |
387 | alarm(0); }; | 538 | }; |
388 | isnt( $@, "alarm\n", $cmd ); | 539 | isnt( $@, "alarm\n", $cmd ); |
540 | alarm(0); | ||
389 | isnt( $result->return_code, 0, $cmd ); | 541 | isnt( $result->return_code, 0, $cmd ); |
390 | 542 | ||
391 | # Test an external address - timeout | 543 | # Test an external address - timeout |
392 | SKIP: { | 544 | SKIP: { |
393 | skip "This doesn't seems to work all the time", 1 unless ($ENV{HTTP_EXTERNAL}); | 545 | skip "This doesn't seem to work all the time", 1 unless ($ENV{HTTP_EXTERNAL}); |
394 | $cmd = "$command -f follow -u /redir_external -t 5"; | 546 | $cmd = "$command -f follow -u /redir_external -t 5"; |
395 | eval { | 547 | eval { |
396 | $result = NPTest->testCmd( $cmd, 2 ); | 548 | $result = NPTest->testCmd( $cmd, 2 ); |
@@ -410,4 +562,20 @@ sub run_common_tests { | |||
410 | }; | 562 | }; |
411 | is( $@, "", $cmd ); | 563 | is( $@, "", $cmd ); |
412 | 564 | ||
565 | $cmd = "$command -u /chunked -s 'chunkedencodingtest' -d 'Transfer-Encoding: chunked'"; | ||
566 | eval { | ||
567 | $result = NPTest->testCmd( $cmd, 5 ); | ||
568 | }; | ||
569 | is( $@, "", $cmd ); | ||
570 | } | ||
571 | |||
572 | sub run_chunked_encoding_special_test { | ||
573 | my ($opts) = @_; | ||
574 | my $command = $opts->{command}; | ||
575 | |||
576 | $cmd = "$command -u / -s 'ChunkedEncodingSpecialTest'"; | ||
577 | eval { | ||
578 | $result = NPTest->testCmd( $cmd, 5 ); | ||
579 | }; | ||
580 | is( $@, "", $cmd ); | ||
413 | } | 581 | } |