From f25b3cb61e518297101ec74f79ed5738945d117e Mon Sep 17 00:00:00 2001 From: Steve Kemp Date: Tue, 5 Feb 2013 17:22:17 +0000 Subject: Fixed. --HG-- rename : lib/custodian/protocoltest/opensmtprelay.rb => lib/custodian/protocoltest/smtprelay.rb --- lib/custodian/protocoltest/opensmtprelay.rb | 46 ------------------------ lib/custodian/protocoltest/smtprelay.rb | 54 +++++++++++++++++++++++++++++ lib/custodian/protocoltests.rb | 1 + 3 files changed, 55 insertions(+), 46 deletions(-) delete mode 100644 lib/custodian/protocoltest/opensmtprelay.rb create mode 100644 lib/custodian/protocoltest/smtprelay.rb (limited to 'lib/custodian') diff --git a/lib/custodian/protocoltest/opensmtprelay.rb b/lib/custodian/protocoltest/opensmtprelay.rb deleted file mode 100644 index 87caafb..0000000 --- a/lib/custodian/protocoltest/opensmtprelay.rb +++ /dev/null @@ -1,46 +0,0 @@ -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 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 diff --git a/lib/custodian/protocoltests.rb b/lib/custodian/protocoltests.rb index b3f96e0..7ba77e0 100644 --- a/lib/custodian/protocoltests.rb +++ b/lib/custodian/protocoltests.rb @@ -22,6 +22,7 @@ require 'custodian/protocoltest/redis' require 'custodian/protocoltest/rsync' require 'custodian/protocoltest/ssh' require 'custodian/protocoltest/smtp' +require 'custodian/protocoltest/smtprelay.rb' require 'custodian/protocoltest/telnet' -- cgit v1.2.1