diff options
author | Steve Kemp <steve@steve.org.uk> | 2012-11-22 06:49:21 +0000 |
---|---|---|
committer | Steve Kemp <steve@steve.org.uk> | 2012-11-22 06:49:21 +0000 |
commit | c796e1fd3c4b6c659255b3a814662d4377836ed0 (patch) | |
tree | 8b4d9feb4403c842af29451de35aa5f94836d70b /lib/custodian/protocoltest/ping.rb | |
parent | 3ac252151c374e067425dd7efe355bd76ba122d1 (diff) |
Moved tests into a namespace.
Diffstat (limited to 'lib/custodian/protocoltest/ping.rb')
-rw-r--r-- | lib/custodian/protocoltest/ping.rb | 155 |
1 files changed, 80 insertions, 75 deletions
diff --git a/lib/custodian/protocoltest/ping.rb b/lib/custodian/protocoltest/ping.rb index cd8490d..765540c 100644 --- a/lib/custodian/protocoltest/ping.rb +++ b/lib/custodian/protocoltest/ping.rb @@ -11,119 +11,124 @@ require 'custodian/testfactory.rb' ### # # -class PINGTest < TestFactory +module Custodian + module ProtocolTest + class PINGTest < TestFactory - # - # The line from which we were constructed. - # - attr_reader :line + # + # The line from which we were constructed. + # + attr_reader :line - # - # The host to test against. - # - attr_reader :host + # + # The host to test against. + # + attr_reader :host - # - # Constructor - # - def initialize( line ) - # - # Save the line - # - @line = line + # + # Constructor + # + def initialize( line ) - # - # Save the host - # - @host = line.split( /\s+/)[0] - end + # + # Save the line + # + @line = line + # + # Save the host + # + @host = line.split( /\s+/)[0] + end - # - # Helper for development. - # - def to_s - "ping-test - #{@host}." - end + # + # Helper for development. + # + def to_s + "ping-test - #{@host}." + end - # - # Convert this class to JSON such that it may be serialized. - # - def to_json - hash = { :line => @line } - hash.to_json - end + # + # Convert this class to JSON such that it may be serialized. + # + def to_json + hash = { :line => @line } + hash.to_json + end - # - # Run the test. - # - def run_test - # - # Find the binary we're going to invoke. - # - binary = nil - binary = "/usr/bin/multi-ping" if ( File.exists?( "/usr/bin/multi-ping" ) ) + # + # Run the test. + # + def run_test - if ( binary.nil? ) - @error = "Failed to find '/usr/bin/multi-ping'" - return false - end + # + # Find the binary we're going to invoke. + # + binary = nil + binary = "/usr/bin/multi-ping" if ( File.exists?( "/usr/bin/multi-ping" ) ) + if ( binary.nil? ) + @error = "Failed to find '/usr/bin/multi-ping'" + return false + end - # - # Sanity check the hostname for ping-tests, to - # avoid this security hole: - # - # $(/tmp/exploit.sh) must run ping .. - # - if ( @host !~ /^([a-zA-Z0-9:\-\.]+)$/ ) - @error = "Invalid hostname for ping-test: #{@host}" - return false - end + # + # Sanity check the hostname for ping-tests, to + # avoid this security hole: + # + # $(/tmp/exploit.sh) must run ping .. + # + if ( @host !~ /^([a-zA-Z0-9:\-\.]+)$/ ) + @error = "Invalid hostname for ping-test: #{@host}" + return false + end - # - # Run the test. - # - if ( system( "#{binary} #{host}" ) == true ) - return true - else - @error = "Ping failed." - return false - end - end + # + # Run the test. + # + if ( system( "#{binary} #{host}" ) == true ) + return true + else + @error = "Ping failed." + return false + end + end - # - # If the test fails then report the error. - # - def error - @error - end + + # + # If the test fails then report the error. + # + def error + @error + end - register_test_type "ping" + register_test_type "ping" + end + end end |