summaryrefslogtreecommitdiff
path: root/lib/custodian/protocoltest/ping.rb
diff options
context:
space:
mode:
authorSteve Kemp <steve@steve.org.uk>2012-11-22 06:49:21 +0000
committerSteve Kemp <steve@steve.org.uk>2012-11-22 06:49:21 +0000
commitb6043eb5abc3b54d48ef1ed41f65ae71d427c588 (patch)
tree8b4d9feb4403c842af29451de35aa5f94836d70b /lib/custodian/protocoltest/ping.rb
parent8e349f739803b3eaa8e196e257c92f90850c1296 (diff)
Moved tests into a namespace.
Diffstat (limited to 'lib/custodian/protocoltest/ping.rb')
-rw-r--r--lib/custodian/protocoltest/ping.rb155
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