summaryrefslogtreecommitdiffstats
path: root/plugins/tests/check_curl.t
diff options
context:
space:
mode:
authorAndreas Baumann <mail@andreasbaumann.cc>2017-05-05 06:42:54 (GMT)
committerSven Nierlein <sven@nierlein.de>2018-10-22 14:30:31 (GMT)
commit28a4c7076a3115d30aeb3b3b5e5bde715692e4a7 (patch)
tree227f7eab51af0dc55d9f47197ce6e4288c86c121 /plugins/tests/check_curl.t
parentf0cebd5153d759fe663488a1750fcbe0f5e680a1 (diff)
downloadmonitoring-plugins-28a4c7076a3115d30aeb3b3b5e5bde715692e4a7.tar.gz
synched tests/check_http.t test changes (virtualhost) into tests/check_curl.t
Diffstat (limited to 'plugins/tests/check_curl.t')
-rwxr-xr-xplugins/tests/check_curl.t41
1 files changed, 39 insertions, 2 deletions
diff --git a/plugins/tests/check_curl.t b/plugins/tests/check_curl.t
index 702edb8..28dacd0 100755
--- a/plugins/tests/check_curl.t
+++ b/plugins/tests/check_curl.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;";
@@ -36,7 +37,7 @@ if ($@) {
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 "./$plugin") {
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 );