summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndreas Baumann <mail@andreasbaumann.cc>2017-05-05 06:38:44 (GMT)
committerAndreas Baumann <mail@andreasbaumann.cc>2017-05-05 06:38:44 (GMT)
commit6faf1ae2d0d3a58aecbabd527125790f5d564e2b (patch)
treeaf0ffb0eca36a12a7077b2b1cae62eb76d75338f
parent55aeb1a5267dfc474446435c63a65acb2be7b3cd (diff)
parentb3d39e605ef7ce7da056721c4e2e140966be3530 (diff)
downloadmonitoring-plugins-6faf1ae.tar.gz
Merge branch 'master' into feature_check_curl
-rwxr-xr-xplugins/tests/check_http.t43
1 files changed, 40 insertions, 3 deletions
diff --git a/plugins/tests/check_http.t b/plugins/tests/check_http.t
index dd56706..c9e6595 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
22my $common_tests = 70; 22my $common_tests = 70;
23my $virtual_port_tests = 8;
23my $ssl_only_tests = 8; 24my $ssl_only_tests = 8;
24# Check that all dependent modules are available 25# Check that all dependent modules are available
25eval "use HTTP::Daemon 6.01;"; 26eval "use HTTP::Daemon 6.01;";
@@ -35,8 +36,8 @@ $plugin = 'check_curl' if $0 =~ m/check_curl/mx;
35if ($@) { 36if ($@) {
36 plan skip_all => "Missing required module for test: $@"; 37 plan skip_all => "Missing required module for test: $@";
37} else { 38} else {
38 if (-x "./$plugin") { 39 if (-x "./check_http") {
39 plan tests => $common_tests * 2 + $ssl_only_tests; 40 plan tests => $common_tests * 2 + $ssl_only_tests + $virtual_port_tests;
40 } else { 41 } else {
41 plan skip_all => "No $plugin compiled"; 42 plan skip_all => "No $plugin compiled";
42 } 43 }
@@ -161,6 +162,11 @@ sub run_server {
161 $c->send_basic_header; 162 $c->send_basic_header;
162 $c->send_header('foo'); 163 $c->send_header('foo');
163 $c->send_crlf; 164 $c->send_crlf;
165 } elsif ($r->url->path eq "/virtual_port") {
166 # return sent Host header
167 $c->send_basic_header;
168 $c->send_crlf;
169 $c->send_response(HTTP::Response->new( 200, 'OK', undef, $r->header ('Host')));
164 } else { 170 } else {
165 $c->send_error(HTTP::Status->RC_FORBIDDEN); 171 $c->send_error(HTTP::Status->RC_FORBIDDEN);
166 } 172 }
@@ -210,6 +216,37 @@ SKIP: {
210 216
211} 217}
212 218
219my $cmd;
220# check virtual port behaviour
221#
222# http without virtual port
223$cmd = "$command -p $port_http -u /virtual_port -r ^127.0.0.1:$port_http\$";
224$result = NPTest->testCmd( $cmd );
225is( $result->return_code, 0, $cmd);
226like( $result->output, '/^HTTP OK: HTTP/1.1 200 OK - \d+ bytes in [\d\.]+ second/', "Output correct: ".$result->output );
227
228# http with virtual port
229$cmd = "$command:80 -p $port_http -u /virtual_port -r ^127.0.0.1\$";
230$result = NPTest->testCmd( $cmd );
231is( $result->return_code, 0, $cmd);
232like( $result->output, '/^HTTP OK: HTTP/1.1 200 OK - \d+ bytes in [\d\.]+ second/', "Output correct: ".$result->output );
233
234SKIP: {
235 skip "HTTP::Daemon::SSL not installed", 4 if ! exists $servers->{https};
236 # https without virtual port
237 $cmd = "$command -p $port_https --ssl -u /virtual_port -r ^127.0.0.1:$port_https\$";
238 $result = NPTest->testCmd( $cmd );
239 is( $result->return_code, 0, $cmd);
240 like( $result->output, '/^HTTP OK: HTTP/1.1 200 OK - \d+ bytes in [\d\.]+ second/', "Output correct: ".$result->output );
241
242 # https with virtual port
243 $cmd = "$command:443 -p $port_https --ssl -u /virtual_port -r ^127.0.0.1\$";
244 $result = NPTest->testCmd( $cmd );
245 is( $result->return_code, 0, $cmd);
246 like( $result->output, '/^HTTP OK: HTTP/1.1 200 OK - \d+ bytes in [\d\.]+ second/', "Output correct: ".$result->output );
247}
248
249
213sub run_common_tests { 250sub run_common_tests {
214 my ($opts) = @_; 251 my ($opts) = @_;
215 my $command = $opts->{command}; 252 my $command = $opts->{command};
@@ -395,7 +432,7 @@ sub run_common_tests {
395 432
396 # Test an external address - timeout 433 # Test an external address - timeout
397 SKIP: { 434 SKIP: {
398 skip "This doesn't seems to work all the time", 1 unless ($ENV{HTTP_EXTERNAL}); 435 skip "This doesn't seem to work all the time", 1 unless ($ENV{HTTP_EXTERNAL});
399 $cmd = "$command -f follow -u /redir_external -t 5"; 436 $cmd = "$command -f follow -u /redir_external -t 5";
400 eval { 437 eval {
401 $result = NPTest->testCmd( $cmd, 2 ); 438 $result = NPTest->testCmd( $cmd, 2 );