check_smtp.t 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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_tcp_smtp_tls = getTestParameter( "NP_HOST_TCP_SMTP_TLS",
  13. "A host providing SMTP with TLS", $host_tcp_smtp);
  14. my $host_tcp_smtp_notls = getTestParameter( "NP_HOST_TCP_SMTP_NOTLS",
  15. "A host providing SMTP without TLS", "");
  16. my $host_nonresponsive = getTestParameter( "NP_HOST_NONRESPONSIVE",
  17. "The hostname of system not responsive to network requests", "10.0.0.1" );
  18. my $hostname_invalid = getTestParameter( "NP_HOSTNAME_INVALID",
  19. "An invalid (not known to DNS) hostname", "nosuchhost" );
  20. my $res;
  21. plan tests => 10;
  22. SKIP: {
  23. skip "No SMTP server defined", 4 unless $host_tcp_smtp;
  24. $res = NPTest->testCmd( "./check_smtp $host_tcp_smtp" );
  25. is ($res->return_code, 0, "OK");
  26. $res = NPTest->testCmd( "./check_smtp -H $host_tcp_smtp -p 25 -w 9 -c 9 -t 10 -e 220" );
  27. is ($res->return_code, 0, "OK, within 9 second response");
  28. $res = NPTest->testCmd( "./check_smtp -H $host_tcp_smtp -p 25 -wt 9 -ct 9 -to 10 -e 220" );
  29. is ($res->return_code, 0, "OK, old syntax");
  30. $res = NPTest->testCmd( "./check_smtp -H $host_tcp_smtp -e 221" );
  31. is ($res->return_code, 1, "WARNING - got correct error when expecting 221 instead of 220" );
  32. TODO: {
  33. local $TODO = "Output is over two lines";
  34. like ( $res->output, qr/^SMTP WARNING/, "Correct error message" );
  35. }
  36. }
  37. SKIP: {
  38. skip "No SMTP server with TLS defined", 1 unless $host_tcp_smtp_tls;
  39. # SSL connection for TLS
  40. $res = NPTest->testCmd( "./check_smtp -H $host_tcp_smtp_tls -p 25 -S" );
  41. is ($res->return_code, 0, "OK, with STARTTLS" );
  42. }
  43. SKIP: {
  44. skip "No SMTP server without TLS defined", 2 unless $host_tcp_smtp_notls;
  45. $res = NPTest->testCmd( "./check_smtp -H $host_tcp_smtp_notls -p 25 -S" );
  46. is ($res->return_code, 1, "OK, got warning from server without TLS");
  47. is ($res->output, "WARNING - TLS not supported by server", "Right error message" );
  48. }
  49. $res = NPTest->testCmd( "./check_smtp $host_nonresponsive" );
  50. is ($res->return_code, 2, "CRITICAL - host non responding" );
  51. $res = NPTest->testCmd( "./check_smtp $hostname_invalid" );
  52. is ($res->return_code, 3, "UNKNOWN - hostname invalid" );