check_smtp.t 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. #! /usr/bin/perl -w -I ..
  2. #
  3. # Simple Mail Transfer Protocol (SMTP) Test via check_smtp
  4. #
  5. # $Id$
  6. #
  7. use strict;
  8. use Test::More;
  9. use NPTest;
  10. my $host_tcp_smtp = getTestParameter( "NP_HOST_TCP_SMTP",
  11. "A host providing an SMTP Service (a mail server)", "mailhost");
  12. my $host_nonresponsive = getTestParameter( "NP_HOST_NONRESPONSIVE",
  13. "The hostname of system not responsive to network requests", "10.0.0.1" );
  14. my $hostname_invalid = getTestParameter( "NP_HOSTNAME_INVALID",
  15. "An invalid (not known to DNS) hostname", "nosuchhost" );
  16. my $res;
  17. plan tests => 8;
  18. SKIP: {
  19. skip "No SMTP server defined", 3 unless $host_tcp_smtp;
  20. $res = NPTest->testCmd( "./check_smtp $host_tcp_smtp" );
  21. is ($res->return_code, 0, "OK");
  22. $res = NPTest->testCmd( "./check_smtp -H $host_tcp_smtp -p 25 -w 9 -c 9 -t 10 -e 220" );
  23. is ($res->return_code, 0, "OK, within 9 second response");
  24. $res = NPTest->testCmd( "./check_smtp -H $host_tcp_smtp -p 25 -wt 9 -ct 9 -to 10 -e 220" );
  25. is ($res->return_code, 0, "OK, old syntax");
  26. $res = NPTest->testCmd( "./check_smtp -H $host_tcp_smtp -e 221" );
  27. is ($res->return_code, 1, "WARNING - got correct error when expecting 221 instead of 220" );
  28. TODO: {
  29. local $TODO = "Output is over two lines";
  30. like ( $res->output, qr/^SMTP WARNING/, "Correct error message" );
  31. }
  32. # SSL connection
  33. $res = NPTest->testCmd( "./check_smtp -H $host_tcp_smtp -p 25 -S" );
  34. is ($res->return_code, 0, "OK, with STARTTLS" );
  35. }
  36. $res = NPTest->testCmd( "./check_smtp $host_nonresponsive" );
  37. is ($res->return_code, 2, "CRITICAL - host non responding" );
  38. $res = NPTest->testCmd( "./check_smtp $hostname_invalid" );
  39. is ($res->return_code, 3, "UNKNOWN - hostname invalid" );