diff options
Diffstat (limited to 'plugins/t')
-rw-r--r-- | plugins/t/check_smtp.t | 55 |
1 files changed, 37 insertions, 18 deletions
diff --git a/plugins/t/check_smtp.t b/plugins/t/check_smtp.t index 3bf32ec..0046a58 100644 --- a/plugins/t/check_smtp.t +++ b/plugins/t/check_smtp.t | |||
@@ -6,29 +6,48 @@ | |||
6 | # | 6 | # |
7 | 7 | ||
8 | use strict; | 8 | use strict; |
9 | use Test; | 9 | use Test::More; |
10 | use NPTest; | 10 | use NPTest; |
11 | 11 | ||
12 | use vars qw($tests); | 12 | my $host_tcp_smtp = getTestParameter( "NP_HOST_TCP_SMTP", |
13 | BEGIN {$tests = 5; plan tests => $tests} | 13 | "A host providing an SMTP Service (a mail server)", "mailhost"); |
14 | 14 | ||
15 | my $host_tcp_smtp = getTestParameter( "host_tcp_smtp", "NP_HOST_TCP_SMTP", "mailhost", | 15 | my $host_nonresponsive = getTestParameter( "NP_HOST_NONRESPONSIVE", |
16 | "A host providing an STMP Service (a mail server)"); | 16 | "The hostname of system not responsive to network requests", "10.0.0.1" ); |
17 | 17 | ||
18 | my $host_nonresponsive = getTestParameter( "host_nonresponsive", "NP_HOST_NONRESPONSIVE", "10.0.0.1", | 18 | my $hostname_invalid = getTestParameter( "NP_HOSTNAME_INVALID", |
19 | "The hostname of system not responsive to network requests" ); | 19 | "An invalid (not known to DNS) hostname", "nosuchhost" ); |
20 | my $res; | ||
20 | 21 | ||
21 | my $hostname_invalid = getTestParameter( "hostname_invalid", "NP_HOSTNAME_INVALID", "nosuchhost", | 22 | plan tests => 8; |
22 | "An invalid (not known to DNS) hostname" ); | ||
23 | my %exceptions = ( 2 => "No SMTP Server present?" ); | ||
24 | 23 | ||
25 | my $t; | 24 | SKIP: { |
25 | skip "No SMTP server defined", 3 unless $host_tcp_smtp; | ||
26 | $res = NPTest->testCmd( "./check_smtp $host_tcp_smtp" ); | ||
27 | is ($res->return_code, 0, "OK"); | ||
28 | |||
29 | $res = NPTest->testCmd( "./check_smtp -H $host_tcp_smtp -p 25 -w 9 -c 9 -t 10 -e 220" ); | ||
30 | is ($res->return_code, 0, "OK, within 9 second response"); | ||
26 | 31 | ||
27 | $t += checkCmd( "./check_smtp $host_tcp_smtp", 0, undef, %exceptions ); | 32 | $res = NPTest->testCmd( "./check_smtp -H $host_tcp_smtp -p 25 -wt 9 -ct 9 -to 10 -e 220" ); |
28 | $t += checkCmd( "./check_smtp -H $host_tcp_smtp -p 25 -t 1 -w 9 -c 9 -t 10 -e 220", 0, undef, %exceptions ); | 33 | is ($res->return_code, 0, "OK, old syntax"); |
29 | $t += checkCmd( "./check_smtp -H $host_tcp_smtp -p 25 -wt 9 -ct 9 -to 10 -e 220", 0, undef, %exceptions ); | 34 | |
30 | $t += checkCmd( "./check_smtp $host_nonresponsive", 2 ); | 35 | $res = NPTest->testCmd( "./check_smtp -H $host_tcp_smtp -e 221" ); |
31 | $t += checkCmd( "./check_smtp $hostname_invalid", 3 ); | 36 | is ($res->return_code, 1, "WARNING - got correct error when expecting 221 instead of 220" ); |
37 | |||
38 | TODO: { | ||
39 | local $TODO = "Output is over two lines"; | ||
40 | like ( $res->output, qr/^SMTP WARNING/, "Correct error message" ); | ||
41 | } | ||
42 | |||
43 | # SSL connection | ||
44 | $res = NPTest->testCmd( "./check_smtp -H $host_tcp_smtp -p 25 -S" ); | ||
45 | is ($res->return_code, 0, "OK, with STARTTLS" ); | ||
46 | } | ||
47 | |||
48 | $res = NPTest->testCmd( "./check_smtp $host_nonresponsive" ); | ||
49 | is ($res->return_code, 2, "CRITICAL - host non responding" ); | ||
50 | |||
51 | $res = NPTest->testCmd( "./check_smtp $hostname_invalid" ); | ||
52 | is ($res->return_code, 3, "UNKNOWN - hostname invalid" ); | ||
32 | 53 | ||
33 | exit(0) if defined($Test::Harness::VERSION); | ||
34 | exit($tests - $t); | ||