4
0

check_smtp.t 2.3 KB

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