diff options
author | Christopher Odenbach <odenbach@uni-paderborn.de> | 2017-03-26 20:36:58 (GMT) |
---|---|---|
committer | Christopher Odenbach <odenbach@uni-paderborn.de> | 2017-03-26 20:36:58 (GMT) |
commit | 9326543c2e65b986e7537465ee52f0ec44639338 (patch) | |
tree | dc7ef3b1d588f7296e0b79ce702a8b19ea8d6158 /plugins | |
parent | 8306e76c327a1ed5cf68f1842873e40ad57b3b30 (diff) | |
download | monitoring-plugins-9326543c2e65b986e7537465ee52f0ec44639338.tar.gz |
Added tests for virtual port behaviour. Separated from all other tests this time.refs/pull/1474/head
Diffstat (limited to 'plugins')
-rwxr-xr-x | plugins/tests/check_http.t | 41 |
1 files changed, 39 insertions, 2 deletions
diff --git a/plugins/tests/check_http.t b/plugins/tests/check_http.t index 1bc0ecb..d6d31de 100755 --- a/plugins/tests/check_http.t +++ b/plugins/tests/check_http.t | |||
@@ -20,6 +20,7 @@ use FindBin qw($Bin); | |||
20 | $ENV{'LC_TIME'} = "C"; | 20 | $ENV{'LC_TIME'} = "C"; |
21 | 21 | ||
22 | my $common_tests = 70; | 22 | my $common_tests = 70; |
23 | my $virtual_port_tests = 8; | ||
23 | my $ssl_only_tests = 8; | 24 | my $ssl_only_tests = 8; |
24 | # Check that all dependent modules are available | 25 | # Check that all dependent modules are available |
25 | eval "use HTTP::Daemon 6.01;"; | 26 | eval "use HTTP::Daemon 6.01;"; |
@@ -33,7 +34,7 @@ if ($@) { | |||
33 | plan skip_all => "Missing required module for test: $@"; | 34 | plan skip_all => "Missing required module for test: $@"; |
34 | } else { | 35 | } else { |
35 | if (-x "./check_http") { | 36 | if (-x "./check_http") { |
36 | plan tests => $common_tests * 2 + $ssl_only_tests; | 37 | plan tests => $common_tests * 2 + $ssl_only_tests + $virtual_port_tests; |
37 | } else { | 38 | } else { |
38 | plan skip_all => "No check_http compiled"; | 39 | plan skip_all => "No check_http compiled"; |
39 | } | 40 | } |
@@ -158,6 +159,11 @@ sub run_server { | |||
158 | $c->send_basic_header; | 159 | $c->send_basic_header; |
159 | $c->send_header('foo'); | 160 | $c->send_header('foo'); |
160 | $c->send_crlf; | 161 | $c->send_crlf; |
162 | } elsif ($r->url->path eq "/virtual_port") { | ||
163 | # return sent Host header | ||
164 | $c->send_basic_header; | ||
165 | $c->send_crlf; | ||
166 | $c->send_response(HTTP::Response->new( 200, 'OK', undef, $r->header ('Host'))); | ||
161 | } else { | 167 | } else { |
162 | $c->send_error(HTTP::Status->RC_FORBIDDEN); | 168 | $c->send_error(HTTP::Status->RC_FORBIDDEN); |
163 | } | 169 | } |
@@ -207,6 +213,37 @@ SKIP: { | |||
207 | 213 | ||
208 | } | 214 | } |
209 | 215 | ||
216 | my $cmd; | ||
217 | # check virtual port behaviour | ||
218 | # | ||
219 | # http without virtual port | ||
220 | $cmd = "$command -p $port_http -u /virtual_port -r ^127.0.0.1:$port_http\$"; | ||
221 | $result = NPTest->testCmd( $cmd ); | ||
222 | is( $result->return_code, 0, $cmd); | ||
223 | like( $result->output, '/^HTTP OK: HTTP/1.1 200 OK - \d+ bytes in [\d\.]+ second/', "Output correct: ".$result->output ); | ||
224 | |||
225 | # http with virtual port | ||
226 | $cmd = "$command:80 -p $port_http -u /virtual_port -r ^127.0.0.1\$"; | ||
227 | $result = NPTest->testCmd( $cmd ); | ||
228 | is( $result->return_code, 0, $cmd); | ||
229 | like( $result->output, '/^HTTP OK: HTTP/1.1 200 OK - \d+ bytes in [\d\.]+ second/', "Output correct: ".$result->output ); | ||
230 | |||
231 | SKIP: { | ||
232 | skip "HTTP::Daemon::SSL not installed", 4 if ! exists $servers->{https}; | ||
233 | # https without virtual port | ||
234 | $cmd = "$command -p $port_https --ssl -u /virtual_port -r ^127.0.0.1:$port_https\$"; | ||
235 | $result = NPTest->testCmd( $cmd ); | ||
236 | is( $result->return_code, 0, $cmd); | ||
237 | like( $result->output, '/^HTTP OK: HTTP/1.1 200 OK - \d+ bytes in [\d\.]+ second/', "Output correct: ".$result->output ); | ||
238 | |||
239 | # https with virtual port | ||
240 | $cmd = "$command:443 -p $port_https --ssl -u /virtual_port -r ^127.0.0.1\$"; | ||
241 | $result = NPTest->testCmd( $cmd ); | ||
242 | is( $result->return_code, 0, $cmd); | ||
243 | like( $result->output, '/^HTTP OK: HTTP/1.1 200 OK - \d+ bytes in [\d\.]+ second/', "Output correct: ".$result->output ); | ||
244 | } | ||
245 | |||
246 | |||
210 | sub run_common_tests { | 247 | sub run_common_tests { |
211 | my ($opts) = @_; | 248 | my ($opts) = @_; |
212 | my $command = $opts->{command}; | 249 | my $command = $opts->{command}; |
@@ -392,7 +429,7 @@ sub run_common_tests { | |||
392 | 429 | ||
393 | # Test an external address - timeout | 430 | # Test an external address - timeout |
394 | SKIP: { | 431 | SKIP: { |
395 | skip "This doesn't seems to work all the time", 1 unless ($ENV{HTTP_EXTERNAL}); | 432 | skip "This doesn't seem to work all the time", 1 unless ($ENV{HTTP_EXTERNAL}); |
396 | $cmd = "$command -f follow -u /redir_external -t 5"; | 433 | $cmd = "$command -f follow -u /redir_external -t 5"; |
397 | eval { | 434 | eval { |
398 | $result = NPTest->testCmd( $cmd, 2 ); | 435 | $result = NPTest->testCmd( $cmd, 2 ); |