diff options
-rwxr-xr-x | plugins/tests/check_curl.t | 80 |
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 | ||
22 | my $common_tests = 70; | 22 | my $common_tests = 70; |
23 | my $virtual_port_tests = 8; | ||
24 | my $ssl_only_tests = 8; | 23 | my $ssl_only_tests = 8; |
25 | # Check that all dependent modules are available | 24 | # Check that all dependent modules are available |
26 | eval "use HTTP::Daemon 6.01;"; | 25 | eval "use HTTP::Daemon 6.01;"; |
@@ -33,11 +32,36 @@ eval { | |||
33 | my $plugin = 'check_http'; | 32 | my $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) | ||
36 | my $advanced_checks = 12; | ||
37 | my $use_advanced_checks = 0; | ||
38 | my $required_version = '7.49.0'; | ||
39 | my $virtual_host = 'www.somefunnyhost.com'; | ||
40 | my $virtual_port = 42; | ||
41 | my $curl_version = ''; | ||
42 | open (my $fh, '-|', "./$plugin --version") or die; | ||
43 | while (<$fh>) { | ||
44 | if (m{libcurl/([\d.]+)\s}) { | ||
45 | $curl_version = $1; | ||
46 | last; | ||
47 | } | ||
48 | } | ||
49 | close ($fh); | ||
50 | if ($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 | |||
36 | if ($@) { | 60 | if ($@) { |
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 | ||
219 | my $cmd; | 243 | my $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 ); | ||
225 | is( $result->return_code, 0, $cmd); | ||
226 | like( $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 ); | ||
231 | is( $result->return_code, 0, $cmd); | ||
232 | like( $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 | ||
246 | SKIP: { | ||
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 | ||
234 | SKIP: { | 269 | SKIP: { |
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 | |||
250 | sub run_common_tests { | 292 | sub run_common_tests { |
251 | my ($opts) = @_; | 293 | my ($opts) = @_; |
252 | my $command = $opts->{command}; | 294 | my $command = $opts->{command}; |