summaryrefslogtreecommitdiff
path: root/lib/custodian/protocoltest/smtprelay.rb
diff options
context:
space:
mode:
authorSteve Kemp <steve@steve.org.uk>2013-02-05 17:22:17 +0000
committerSteve Kemp <steve@steve.org.uk>2013-02-05 17:22:17 +0000
commita740f2da418f792d3a119420490ce67fad5c1d18 (patch)
tree804dfb82d0e0b322faba139da66664421111fdb3 /lib/custodian/protocoltest/smtprelay.rb
parentabc793d9b983b8392672d42faea2d1ac2e8f758b (diff)
Fixed.
Diffstat (limited to 'lib/custodian/protocoltest/smtprelay.rb')
-rw-r--r--lib/custodian/protocoltest/smtprelay.rb54
1 files changed, 54 insertions, 0 deletions
diff --git a/lib/custodian/protocoltest/smtprelay.rb b/lib/custodian/protocoltest/smtprelay.rb
new file mode 100644
index 0000000..868ccf6
--- /dev/null
+++ b/lib/custodian/protocoltest/smtprelay.rb
@@ -0,0 +1,54 @@
+require 'net/smtp'
+
+
+
+module Custodian
+
+ module ProtocolTest
+
+ class RelayTest < TCPTest
+
+ # save away state from the configuration line.
+ def initialize( line )
+ @line = line
+ @host = line.split( /\s+/)[0]
+
+ if ( line =~ /must\s+not\s+run\s+/ )
+ @inverted = true
+ else
+ @inverted = false
+ end
+ end
+
+
+ # run the test for open relays of SMTP protocol - return true on success.
+ # false on fail.
+ # this requires love, just trying to get it to run for now..
+ def run_test
+ @error = nil # for if we've run the test before
+ message = "This is a test for OPEN SMTP relays."
+
+ begin
+ Net::SMTP.start(@host,25) do |smtp|
+ smtp.send_message message, "foo@bar.com", "foo@bar.com"
+ @error = "Sent message, that's bad."
+ end # Net SMTP
+
+ rescue Exception => ex # for if we fail to send a message; this is a good thing
+ return false
+ end
+
+ end
+
+
+ # if the test failed return a suitable error message
+ def error
+ @error = "Couldn't send message; that's good, really."
+ end
+
+ # register ourselves with the factory so we're invoked for lines of the form:
+ # TARGET must (not) run xxx otherwise ...
+ register_test_type "smtprelay"
+ end
+ end
+end