diff options
author | Andreas Baumann <mail@andreasbaumann.cc> | 2017-05-05 08:42:54 +0200 |
---|---|---|
committer | Sven Nierlein <sven@nierlein.de> | 2018-10-22 16:30:31 +0200 |
commit | 28a4c7076a3115d30aeb3b3b5e5bde715692e4a7 (patch) | |
tree | 227f7eab51af0dc55d9f47197ce6e4288c86c121 /plugins/tests | |
parent | f0cebd5153d759fe663488a1750fcbe0f5e680a1 (diff) | |
download | monitoring-plugins-28a4c7076a3115d30aeb3b3b5e5bde715692e4a7.tar.gz |
synched tests/check_http.t test changes (virtualhost) into tests/check_curl.t
Diffstat (limited to 'plugins/tests')
-rwxr-xr-x | plugins/tests/check_curl.t | 41 |
1 files changed, 39 insertions, 2 deletions
diff --git a/plugins/tests/check_curl.t b/plugins/tests/check_curl.t index 702edb87..28dacd0d 100755 --- a/plugins/tests/check_curl.t +++ b/plugins/tests/check_curl.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;"; @@ -36,7 +37,7 @@ if ($@) { plan skip_all => "Missing required module for test: $@"; } else { if (-x "./$plugin") { - plan tests => $common_tests * 2 + $ssl_only_tests; + plan tests => $common_tests * 2 + $ssl_only_tests + $virtual_port_tests; } else { plan skip_all => "No $plugin compiled"; } @@ -161,6 +162,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); } @@ -210,6 +216,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}; @@ -395,7 +432,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 ); |