summaryrefslogtreecommitdiffstats
path: root/plugins/tests/check_http.t
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/tests/check_http.t')
-rwxr-xr-xplugins/tests/check_http.t29
1 files changed, 17 insertions, 12 deletions
diff --git a/plugins/tests/check_http.t b/plugins/tests/check_http.t
index d6d31de..2f051fa 100755
--- a/plugins/tests/check_http.t
+++ b/plugins/tests/check_http.t
@@ -4,13 +4,15 @@
4# 4#
5# To create the https server certificate: 5# To create the https server certificate:
6# openssl req -new -x509 -keyout server-key.pem -out server-cert.pem -days 3650 -nodes 6# openssl req -new -x509 -keyout server-key.pem -out server-cert.pem -days 3650 -nodes
7# Country Name (2 letter code) [AU]:UK 7# to create a new expired certificate:
8# State or Province Name (full name) [Some-State]:Derbyshire 8# faketime '2008-01-01 12:00:00' openssl req -new -x509 -keyout expired-key.pem -out expired-cert.pem -days 1 -nodes
9# Locality Name (eg, city) []:Belper 9# Country Name (2 letter code) [AU]:DE
10# State or Province Name (full name) [Some-State]:Bavaria
11# Locality Name (eg, city) []:Munich
10# Organization Name (eg, company) [Internet Widgits Pty Ltd]:Monitoring Plugins 12# Organization Name (eg, company) [Internet Widgits Pty Ltd]:Monitoring Plugins
11# Organizational Unit Name (eg, section) []: 13# Organizational Unit Name (eg, section) []:
12# Common Name (eg, YOUR name) []:Ton Voon 14# Common Name (e.g. server FQDN or YOUR name) []:Monitoring Plugins
13# Email Address []:tonvoon@mac.com 15# Email Address []:devel@monitoring-plugins.org
14 16
15use strict; 17use strict;
16use Test::More; 18use Test::More;
@@ -30,13 +32,16 @@ eval {
30 require HTTP::Response; 32 require HTTP::Response;
31}; 33};
32 34
35my $plugin = 'check_http';
36$plugin = 'check_curl' if $0 =~ m/check_curl/mx;
37
33if ($@) { 38if ($@) {
34 plan skip_all => "Missing required module for test: $@"; 39 plan skip_all => "Missing required module for test: $@";
35} else { 40} else {
36 if (-x "./check_http") { 41 if (-x "./$plugin") {
37 plan tests => $common_tests * 2 + $ssl_only_tests + $virtual_port_tests; 42 plan tests => $common_tests * 2 + $ssl_only_tests + $virtual_port_tests;
38 } else { 43 } else {
39 plan skip_all => "No check_http compiled"; 44 plan skip_all => "No $plugin compiled";
40 } 45 }
41} 46}
42 47
@@ -185,7 +190,7 @@ if ($ARGV[0] && $ARGV[0] eq "-d") {
185} 190}
186 191
187my $result; 192my $result;
188my $command = "./check_http -H 127.0.0.1"; 193my $command = "./$plugin -H 127.0.0.1";
189 194
190run_common_tests( { command => "$command -p $port_http" } ); 195run_common_tests( { command => "$command -p $port_http" } );
191SKIP: { 196SKIP: {
@@ -194,21 +199,21 @@ SKIP: {
194 199
195 $result = NPTest->testCmd( "$command -p $port_https -S -C 14" ); 200 $result = NPTest->testCmd( "$command -p $port_https -S -C 14" );
196 is( $result->return_code, 0, "$command -p $port_https -S -C 14" ); 201 is( $result->return_code, 0, "$command -p $port_https -S -C 14" );
197 is( $result->output, 'OK - Certificate \'Ton Voon\' will expire on Sun Mar 3 21:41:28 2019 +0000.', "output ok" ); 202 is( $result->output, "OK - Certificate 'Monitoring Plugins' will expire on Fri Feb 16 15:31:44 2029 +0000.", "output ok" );
198 203
199 $result = NPTest->testCmd( "$command -p $port_https -S -C 14000" ); 204 $result = NPTest->testCmd( "$command -p $port_https -S -C 14000" );
200 is( $result->return_code, 1, "$command -p $port_https -S -C 14000" ); 205 is( $result->return_code, 1, "$command -p $port_https -S -C 14000" );
201 like( $result->output, '/WARNING - Certificate \'Ton Voon\' expires in \d+ day\(s\) \(Sun Mar 3 21:41:28 2019 \+0000\)./', "output ok" ); 206 like( $result->output, '/WARNING - Certificate \'Monitoring Plugins\' expires in \d+ day\(s\) \(Fri Feb 16 15:31:44 2029 \+0000\)./', "output ok" );
202 207
203 # Expired cert tests 208 # Expired cert tests
204 $result = NPTest->testCmd( "$command -p $port_https -S -C 13960,14000" ); 209 $result = NPTest->testCmd( "$command -p $port_https -S -C 13960,14000" );
205 is( $result->return_code, 2, "$command -p $port_https -S -C 13960,14000" ); 210 is( $result->return_code, 2, "$command -p $port_https -S -C 13960,14000" );
206 like( $result->output, '/CRITICAL - Certificate \'Ton Voon\' expires in \d+ day\(s\) \(Sun Mar 3 21:41:28 2019 \+0000\)./', "output ok" ); 211 like( $result->output, '/CRITICAL - Certificate \'Monitoring Plugins\' expires in \d+ day\(s\) \(Fri Feb 16 15:31:44 2029 \+0000\)./', "output ok" );
207 212
208 $result = NPTest->testCmd( "$command -p $port_https_expired -S -C 7" ); 213 $result = NPTest->testCmd( "$command -p $port_https_expired -S -C 7" );
209 is( $result->return_code, 2, "$command -p $port_https_expired -S -C 7" ); 214 is( $result->return_code, 2, "$command -p $port_https_expired -S -C 7" );
210 is( $result->output, 215 is( $result->output,
211 'CRITICAL - Certificate \'Ton Voon\' expired on Thu Mar 5 00:13:16 2009 +0000.', 216 'CRITICAL - Certificate \'Monitoring Plugins\' expired on Wed Jan 2 11:00:26 2008 +0000.',
212 "output ok" ); 217 "output ok" );
213 218
214} 219}