aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Sven Nierlein <sven@nierlein.org> 2017-05-04 23:19:51 +0200
committerGravatar GitHub <noreply@github.com> 2017-05-04 23:19:51 +0200
commitb3d39e605ef7ce7da056721c4e2e140966be3530 (patch)
tree4145f3c9b5a3fd8346001752d3687522a7c56b7f
parentd0e03032f14179c64d1735d6b6fb88c4eeca2b01 (diff)
parent9326543c2e65b986e7537465ee52f0ec44639338 (diff)
downloadmonitoring-plugins-b3d39e605ef7ce7da056721c4e2e140966be3530.tar.gz
Merge pull request #1474 from odenbach/vport
Added tests for virtual port behaviour. Separated from all other test…
-rwxr-xr-xplugins/tests/check_http.t41
1 files changed, 39 insertions, 2 deletions
diff --git a/plugins/tests/check_http.t b/plugins/tests/check_http.t
index 1bc0ecb7..d6d31de1 100755
--- a/plugins/tests/check_http.t
+++ b/plugins/tests/check_http.t
@@ -20,6 +20,7 @@ use FindBin qw($Bin);
$ENV{'LC_TIME'} = "C";
my $common_tests = 70;
+my $virtual_port_tests = 8;
my $ssl_only_tests = 8;
# Check that all dependent modules are available
eval "use HTTP::Daemon 6.01;";
@@ -33,7 +34,7 @@ if ($@) {
plan skip_all => "Missing required module for test: $@";
} else {
if (-x "./check_http") {
- plan tests => $common_tests * 2 + $ssl_only_tests;
+ plan tests => $common_tests * 2 + $ssl_only_tests + $virtual_port_tests;
} else {
plan skip_all => "No check_http compiled";
}
@@ -158,6 +159,11 @@ sub run_server {
$c->send_basic_header;
$c->send_header('foo');
$c->send_crlf;
+ } elsif ($r->url->path eq "/virtual_port") {
+ # return sent Host header
+ $c->send_basic_header;
+ $c->send_crlf;
+ $c->send_response(HTTP::Response->new( 200, 'OK', undef, $r->header ('Host')));
} else {
$c->send_error(HTTP::Status->RC_FORBIDDEN);
}
@@ -207,6 +213,37 @@ SKIP: {
}
+my $cmd;
+# check virtual port behaviour
+#
+# http without virtual port
+$cmd = "$command -p $port_http -u /virtual_port -r ^127.0.0.1:$port_http\$";
+$result = NPTest->testCmd( $cmd );
+is( $result->return_code, 0, $cmd);
+like( $result->output, '/^HTTP OK: HTTP/1.1 200 OK - \d+ bytes in [\d\.]+ second/', "Output correct: ".$result->output );
+
+# http with virtual port
+$cmd = "$command:80 -p $port_http -u /virtual_port -r ^127.0.0.1\$";
+$result = NPTest->testCmd( $cmd );
+is( $result->return_code, 0, $cmd);
+like( $result->output, '/^HTTP OK: HTTP/1.1 200 OK - \d+ bytes in [\d\.]+ second/', "Output correct: ".$result->output );
+
+SKIP: {
+ skip "HTTP::Daemon::SSL not installed", 4 if ! exists $servers->{https};
+ # https without virtual port
+ $cmd = "$command -p $port_https --ssl -u /virtual_port -r ^127.0.0.1:$port_https\$";
+ $result = NPTest->testCmd( $cmd );
+ is( $result->return_code, 0, $cmd);
+ like( $result->output, '/^HTTP OK: HTTP/1.1 200 OK - \d+ bytes in [\d\.]+ second/', "Output correct: ".$result->output );
+
+ # https with virtual port
+ $cmd = "$command:443 -p $port_https --ssl -u /virtual_port -r ^127.0.0.1\$";
+ $result = NPTest->testCmd( $cmd );
+ is( $result->return_code, 0, $cmd);
+ like( $result->output, '/^HTTP OK: HTTP/1.1 200 OK - \d+ bytes in [\d\.]+ second/', "Output correct: ".$result->output );
+}
+
+
sub run_common_tests {
my ($opts) = @_;
my $command = $opts->{command};
@@ -392,7 +429,7 @@ sub run_common_tests {
# Test an external address - timeout
SKIP: {
- skip "This doesn't seems to work all the time", 1 unless ($ENV{HTTP_EXTERNAL});
+ skip "This doesn't seem to work all the time", 1 unless ($ENV{HTTP_EXTERNAL});
$cmd = "$command -f follow -u /redir_external -t 5";
eval {
$result = NPTest->testCmd( $cmd, 2 );