summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rwxr-xr-xplugins/tests/check_curl.t80
1 files changed, 61 insertions, 19 deletions
diff --git a/plugins/tests/check_curl.t b/plugins/tests/check_curl.t
index 28dacd0..e182623 100755
--- a/plugins/tests/check_curl.t
+++ b/plugins/tests/check_curl.t
@@ -20,7 +20,6 @@ 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;
24my $ssl_only_tests = 8; 23my $ssl_only_tests = 8;
25# Check that all dependent modules are available 24# Check that all dependent modules are available
26eval "use HTTP::Daemon 6.01;"; 25eval "use HTTP::Daemon 6.01;";
@@ -33,11 +32,36 @@ eval {
33my $plugin = 'check_http'; 32my $plugin = 'check_http';
34$plugin = 'check_curl' if $0 =~ m/check_curl/mx; 33$plugin = 'check_curl' if $0 =~ m/check_curl/mx;
35 34
35# look for libcurl version to see if some advanced checks are possible (>= 7.49.0)
36my $advanced_checks = 12;
37my $use_advanced_checks = 0;
38my $required_version = '7.49.0';
39my $virtual_host = 'www.somefunnyhost.com';
40my $virtual_port = 42;
41my $curl_version = '';
42open (my $fh, '-|', "./$plugin --version") or die;
43while (<$fh>) {
44 if (m{libcurl/([\d.]+)\s}) {
45 $curl_version = $1;
46 last;
47 }
48}
49close ($fh);
50if ($curl_version) {
51 my ($major, $minor, $release) = split (/\./, $curl_version);
52 my ($req_major, $req_minor, $req_release) = split (/\./, $required_version);
53 my $check = ($major <=> $req_major or $minor <=> $req_minor or $release <=> $req_release);
54 if ($check >= 0) {
55 $use_advanced_checks = 1;
56 print "Found libcurl $major.$minor.$release. Using advanced checks\n";
57 }
58}
59
36if ($@) { 60if ($@) {
37 plan skip_all => "Missing required module for test: $@"; 61 plan skip_all => "Missing required module for test: $@";
38} else { 62} else {
39 if (-x "./$plugin") { 63 if (-x "./$plugin") {
40 plan tests => $common_tests * 2 + $ssl_only_tests + $virtual_port_tests; 64 plan tests => $common_tests * 2 + $ssl_only_tests + $advanced_checks;
41 } else { 65 } else {
42 plan skip_all => "No $plugin compiled"; 66 plan skip_all => "No $plugin compiled";
43 } 67 }
@@ -217,36 +241,54 @@ SKIP: {
217} 241}
218 242
219my $cmd; 243my $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 244
245# advanced checks with virtual hostname and virtual port
246SKIP: {
247 skip "libcurl version is smaller than $required_version", 6 unless $use_advanced_checks;
248
249 # http without virtual port
250 $cmd = "./$plugin -H $virtual_host -I 127.0.0.1 -p $port_http -u /virtual_port -r ^$virtual_host:$port_http\$";
251 $result = NPTest->testCmd( $cmd );
252 is( $result->return_code, 0, $cmd);
253 like( $result->output, '/^HTTP OK: HTTP/1.1 200 OK - \d+ bytes in [\d\.]+ second/', "Output correct: ".$result->output );
254
255 # http with virtual port (!= 80)
256 $cmd = "./$plugin -H $virtual_host:$virtual_port -I 127.0.0.1 -p $port_http -u /virtual_port -r ^$virtual_host:$virtual_port\$";
257 $result = NPTest->testCmd( $cmd );
258 is( $result->return_code, 0, $cmd);
259 like( $result->output, '/^HTTP OK: HTTP/1.1 200 OK - \d+ bytes in [\d\.]+ second/', "Output correct: ".$result->output );
260
261 # http with virtual port (80)
262 $cmd = "./$plugin -H $virtual_host:80 -I 127.0.0.1 -p $port_http -u /virtual_port -r ^$virtual_host\$";
263 $result = NPTest->testCmd( $cmd );
264 is( $result->return_code, 0, $cmd);
265 like( $result->output, '/^HTTP OK: HTTP/1.1 200 OK - \d+ bytes in [\d\.]+ second/', "Output correct: ".$result->output );
266}
267
268# and the same for SSL
234SKIP: { 269SKIP: {
235 skip "HTTP::Daemon::SSL not installed", 4 if ! exists $servers->{https}; 270 skip "libcurl version is smaller than $required_version and/or HTTP::Daemon::SSL not installed", 6 if ! exists $servers->{https} or not $use_advanced_checks;
236 # https without virtual port 271 # https without virtual port
237 $cmd = "$command -p $port_https --ssl -u /virtual_port -r ^127.0.0.1:$port_https\$"; 272 $cmd = "./$plugin -H $virtual_host -I 127.0.0.1 -p $port_https --ssl -u /virtual_port -r ^$virtual_host:$port_https\$";
273 $result = NPTest->testCmd( $cmd );
274 is( $result->return_code, 0, $cmd);
275 like( $result->output, '/^HTTP OK: HTTP/1.1 200 OK - \d+ bytes in [\d\.]+ second/', "Output correct: ".$result->output );
276
277 # https with virtual port (!= 443)
278 $cmd = "./$plugin -H $virtual_host:$virtual_port -I 127.0.0.1 -p $port_https --ssl -u /virtual_port -r ^$virtual_host:$virtual_port\$";
238 $result = NPTest->testCmd( $cmd ); 279 $result = NPTest->testCmd( $cmd );
239 is( $result->return_code, 0, $cmd); 280 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 ); 281 like( $result->output, '/^HTTP OK: HTTP/1.1 200 OK - \d+ bytes in [\d\.]+ second/', "Output correct: ".$result->output );
241 282
242 # https with virtual port 283 # https with virtual port (443)
243 $cmd = "$command:443 -p $port_https --ssl -u /virtual_port -r ^127.0.0.1\$"; 284 $cmd = "./$plugin -H $virtual_host:443 -I 127.0.0.1 -p $port_https --ssl -u /virtual_port -r ^$virtual_host\$";
244 $result = NPTest->testCmd( $cmd ); 285 $result = NPTest->testCmd( $cmd );
245 is( $result->return_code, 0, $cmd); 286 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 ); 287 like( $result->output, '/^HTTP OK: HTTP/1.1 200 OK - \d+ bytes in [\d\.]+ second/', "Output correct: ".$result->output );
247} 288}
248 289
249 290
291
250sub run_common_tests { 292sub run_common_tests {
251 my ($opts) = @_; 293 my ($opts) = @_;
252 my $command = $opts->{command}; 294 my $command = $opts->{command};