diff options
author | Ton Voon <tonvoon@macbook.local> | 2009-03-06 00:24:38 +0000 |
---|---|---|
committer | Ton Voon <tonvoon@macbook.local> | 2009-03-06 00:24:38 +0000 |
commit | 674841e279cc1bdbcb5c84c9b26377b156aee76b (patch) | |
tree | 2f16f4762151d36226aa13dd813fa75c6ae6a9f8 /plugins/tests/check_http.t | |
parent | 0e5a9df13507452637403c31e51c525dbed33f4d (diff) | |
download | monitoring-plugins-674841e279cc1bdbcb5c84c9b26377b156aee76b.tar.gz |
Create expired cert for testing purposes. Updated tests to check
expired and unexpired certificates
Diffstat (limited to 'plugins/tests/check_http.t')
-rwxr-xr-x | plugins/tests/check_http.t | 66 |
1 files changed, 56 insertions, 10 deletions
diff --git a/plugins/tests/check_http.t b/plugins/tests/check_http.t index 20078c20..d221463b 100755 --- a/plugins/tests/check_http.t +++ b/plugins/tests/check_http.t | |||
@@ -2,6 +2,16 @@ | |||
2 | # | 2 | # |
3 | # Test check_http by having an actual HTTP server running | 3 | # Test check_http by having an actual HTTP server running |
4 | # | 4 | # |
5 | # To create the https server certificate: | ||
6 | # openssl req -new -x509 -keyout server-key.pem -out server-cert.pem -days 3650 -nodes | ||
7 | # Country Name (2 letter code) [AU]:UK | ||
8 | # State or Province Name (full name) [Some-State]:Derbyshire | ||
9 | # Locality Name (eg, city) []:Belper | ||
10 | # Organization Name (eg, company) [Internet Widgits Pty Ltd]:Nagios Plugins | ||
11 | # Organizational Unit Name (eg, section) []: | ||
12 | # Common Name (eg, YOUR name) []:Ton Voon | ||
13 | # Email Address []:tonvoon@mac.com | ||
14 | |||
5 | 15 | ||
6 | use strict; | 16 | use strict; |
7 | use Test::More; | 17 | use Test::More; |
@@ -25,17 +35,35 @@ $HTTP::Daemon::VERSION = "1.00"; | |||
25 | 35 | ||
26 | my $port_http = 50000 + int(rand(1000)); | 36 | my $port_http = 50000 + int(rand(1000)); |
27 | my $port_https = $port_http + 1; | 37 | my $port_https = $port_http + 1; |
38 | my $port_https_expired = $port_http + 2; | ||
28 | 39 | ||
29 | # Start up both servers | 40 | # Start up all servers |
30 | my $pid_https; | 41 | my @pids; |
31 | my $pid_http = fork(); | 42 | my $pid = fork(); |
32 | if ($pid_http) { | 43 | if ($pid) { |
33 | # Parent | 44 | # Parent |
45 | push @pids, $pid; | ||
34 | if (exists $servers->{https}) { | 46 | if (exists $servers->{https}) { |
35 | # Fork another server | 47 | # Fork a normal HTTPS server |
36 | $pid_https = fork(); | 48 | $pid = fork(); |
37 | if ($pid_https) { | 49 | if ($pid) { |
38 | # Parent | 50 | # Parent |
51 | push @pids, $pid; | ||
52 | # Fork an expired cert server | ||
53 | $pid = fork(); | ||
54 | if ($pid) { | ||
55 | push @pids, $pid; | ||
56 | } else { | ||
57 | my $d = HTTP::Daemon::SSL->new( | ||
58 | LocalPort => $port_https_expired, | ||
59 | LocalAddr => "127.0.0.1", | ||
60 | SSL_cert_file => "$Bin/certs/expired-cert.pem", | ||
61 | SSL_key_file => "$Bin/certs/expired-key.pem", | ||
62 | ) || die; | ||
63 | print "Please contact https expired at: <URL:", $d->url, ">\n"; | ||
64 | run_server( $d ); | ||
65 | exit; | ||
66 | } | ||
39 | } else { | 67 | } else { |
40 | my $d = HTTP::Daemon::SSL->new( | 68 | my $d = HTTP::Daemon::SSL->new( |
41 | LocalPort => $port_https, | 69 | LocalPort => $port_https, |
@@ -106,7 +134,7 @@ sub run_server { | |||
106 | } | 134 | } |
107 | 135 | ||
108 | END { | 136 | END { |
109 | foreach my $pid ($pid_http, $pid_https) { | 137 | foreach my $pid (@pids) { |
110 | if ($pid) { print "Killing $pid\n"; kill "INT", $pid } | 138 | if ($pid) { print "Killing $pid\n"; kill "INT", $pid } |
111 | } | 139 | } |
112 | }; | 140 | }; |
@@ -116,8 +144,9 @@ if ($ARGV[0] && $ARGV[0] eq "-d") { | |||
116 | } | 144 | } |
117 | 145 | ||
118 | my $common_tests = 47; | 146 | my $common_tests = 47; |
147 | my $ssl_only_tests = 6; | ||
119 | if (-x "./check_http") { | 148 | if (-x "./check_http") { |
120 | plan tests => $common_tests * 2; | 149 | plan tests => $common_tests * 2 + $ssl_only_tests; |
121 | } else { | 150 | } else { |
122 | plan skip_all => "No check_http compiled"; | 151 | plan skip_all => "No check_http compiled"; |
123 | } | 152 | } |
@@ -127,8 +156,25 @@ my $command = "./check_http -H 127.0.0.1"; | |||
127 | 156 | ||
128 | run_common_tests( { command => "$command -p $port_http" } ); | 157 | run_common_tests( { command => "$command -p $port_http" } ); |
129 | SKIP: { | 158 | SKIP: { |
130 | skip "HTTP::Daemon::SSL not installed", $common_tests if ! exists $servers->{https}; | 159 | skip "HTTP::Daemon::SSL not installed", $common_tests + $ssl_only_tests if ! exists $servers->{https}; |
131 | run_common_tests( { command => "$command -p $port_https", ssl => 1 } ); | 160 | run_common_tests( { command => "$command -p $port_https", ssl => 1 } ); |
161 | |||
162 | $result = NPTest->testCmd( "$command -p $port_https -S -C 14" ); | ||
163 | is( $result->return_code, 0, "$command -p $port_https -S -C 14" ); | ||
164 | is( $result->output, 'OK - Certificate will expire on 03/03/2019 21:41.', "output ok" ); | ||
165 | |||
166 | $result = NPTest->testCmd( "$command -p $port_https -S -C 14000" ); | ||
167 | is( $result->return_code, 1, "$command -p $port_https -S -C 14000" ); | ||
168 | like( $result->output, '/WARNING - Certificate expires in \d+ day\(s\) \(03/03/2019 21:41\)./', "output ok" ); | ||
169 | |||
170 | |||
171 | # Expired cert tests | ||
172 | $result = NPTest->testCmd( "$command -p $port_https_expired -S -C 7" ); | ||
173 | is( $result->return_code, 2, "$command -p $port_https_expired -S -C 7" ); | ||
174 | is( $result->output, | ||
175 | 'CRITICAL - Certificate expired on 03/05/2009 00:13.', | ||
176 | "output ok" ); | ||
177 | |||
132 | } | 178 | } |
133 | 179 | ||
134 | sub run_common_tests { | 180 | sub run_common_tests { |