Code

Fixed buffer overflow in check_ntp/check_ntp_peer (#1999319, Ubuntu #291265)
[nagiosplug.git] / plugins / t / check_smtp.t
1 #! /usr/bin/perl -w -I ..
2 #
3 # Simple Mail Transfer Protocol (SMTP) Test via check_smtp
4 #
5 # $Id$
6 #
8 use strict;
9 use Test::More;
10 use NPTest;
12 my $host_tcp_smtp      = getTestParameter( "NP_HOST_TCP_SMTP", 
13                                            "A host providing an SMTP Service (a mail server)", "mailhost");
14 my $host_tcp_smtp_tls  = getTestParameter( "NP_HOST_TCP_SMTP_TLS",
15                                            "A host providing SMTP with TLS", $host_tcp_smtp);
16 my $host_tcp_smtp_notls = getTestParameter( "NP_HOST_TCP_SMTP_NOTLS",
17                                            "A host providing SMTP without TLS", "");
19 my $host_nonresponsive = getTestParameter( "NP_HOST_NONRESPONSIVE", 
20                                            "The hostname of system not responsive to network requests", "10.0.0.1" );
22 my $hostname_invalid   = getTestParameter( "NP_HOSTNAME_INVALID",   
23                                            "An invalid (not known to DNS) hostname", "nosuchhost" );
24 my $res;
26 plan tests => 10;
28 SKIP: {
29         skip "No SMTP server defined", 4 unless $host_tcp_smtp;
30         $res = NPTest->testCmd( "./check_smtp $host_tcp_smtp" );
31         is ($res->return_code, 0, "OK");
32         
33         $res = NPTest->testCmd( "./check_smtp -H $host_tcp_smtp -p 25 -w 9 -c 9 -t 10 -e 220" );
34         is ($res->return_code, 0, "OK, within 9 second response");
36         $res = NPTest->testCmd( "./check_smtp -H $host_tcp_smtp -p 25 -wt 9 -ct 9 -to 10 -e 220" );
37         is ($res->return_code, 0, "OK, old syntax");
39         $res = NPTest->testCmd( "./check_smtp -H $host_tcp_smtp -e 221" );
40         is ($res->return_code, 1, "WARNING - got correct error when expecting 221 instead of 220" );
42         TODO: {
43                 local $TODO = "Output is over two lines";
44                 like ( $res->output, qr/^SMTP WARNING/, "Correct error message" );
45         }
46 }
48 SKIP: {
49         skip "No SMTP server with TLS defined", 1 unless $host_tcp_smtp_tls;
50         # SSL connection for TLS
51         $res = NPTest->testCmd( "./check_smtp -H $host_tcp_smtp_tls -p 25 -S" );
52         is ($res->return_code, 0, "OK, with STARTTLS" );
53 }
55 SKIP: {
56         skip "No SMTP server without TLS defined", 2 unless $host_tcp_smtp_notls;
57         $res = NPTest->testCmd( "./check_smtp -H $host_tcp_smtp_notls -p 25 -S" );
58         is ($res->return_code, 1, "OK, got warning from server without TLS");
59         is ($res->output, "WARNING - TLS not supported by server", "Right error message" );
60 }
62 $res = NPTest->testCmd( "./check_smtp $host_nonresponsive" );
63 is ($res->return_code, 2, "CRITICAL - host non responding" );
65 $res = NPTest->testCmd( "./check_smtp $hostname_invalid" );
66 is ($res->return_code, 3, "UNKNOWN - hostname invalid" );