From 325b65727351368d725ea8b7d1e0922cd94bd58f Mon Sep 17 00:00:00 2001 From: "john.hackett@bytemark.co.uk" Date: Tue, 5 Feb 2013 17:08:44 +0000 Subject: Adding (currently broken) open smtp relay check for steve to look at. --- lib/custodian/protocoltest/opensmtprelay.rb | 46 +++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 lib/custodian/protocoltest/opensmtprelay.rb (limited to 'lib/custodian') diff --git a/lib/custodian/protocoltest/opensmtprelay.rb b/lib/custodian/protocoltest/opensmtprelay.rb new file mode 100644 index 0000000..87caafb --- /dev/null +++ b/lib/custodian/protocoltest/opensmtprelay.rb @@ -0,0 +1,46 @@ +require 'net/smtp' + +module Custodian + module ProtocolTest + class OpenSMTPRelayTest < TestFactory + # 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. + def run_test # this requires love, just trying to get it to run for now.. + + @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 "open-smtp-relay" + end + end +end -- cgit v1.2.1