summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSteve Kemp <steve@steve.org.uk>2013-02-25 16:48:29 +0000
committerSteve Kemp <steve@steve.org.uk>2013-02-25 16:48:29 +0000
commitbdd05645109ae2d9575d0603c62cd3ca44f78a97 (patch)
treeba5e17f9e72d4e1c37dab0720517154a6c499dd6
parenta30f26743b2eb4b23f08b78e8ae540fadc88fa6b (diff)
Added open HTTP-proxy test.
-rw-r--r--lib/custodian/protocoltest/openproxy.rb142
-rw-r--r--lib/custodian/protocoltests.rb1
2 files changed, 143 insertions, 0 deletions
diff --git a/lib/custodian/protocoltest/openproxy.rb b/lib/custodian/protocoltest/openproxy.rb
new file mode 100644
index 0000000..cb4371d
--- /dev/null
+++ b/lib/custodian/protocoltest/openproxy.rb
@@ -0,0 +1,142 @@
+require 'uri'
+
+
+#
+# The open-proxy test.
+#
+# This object is instantiated if the parser sees a line such as:
+#
+###
+### foo.vm.bytemark.co.uk must not run openproxy otherwise 'insecurity'.
+###
+#
+#
+module Custodian
+
+ module ProtocolTest
+
+
+ class OpenProxyTest < TestFactory
+
+ #
+ # The line from which we were constructed.
+ #
+ attr_reader :line
+
+
+ #
+ # Constructor
+ #
+ def initialize( line )
+
+ #
+ # Save the line
+ #
+ @line = line
+
+ #
+ # Save the target
+ #
+ @host = line.split( /\s+/)[0]
+
+ #
+ # Is this test inverted?
+ #
+ if ( line =~ /must\s+not\s+run\s+/ )
+ @inverted = true
+ else
+ @inverted = false
+ end
+ end
+
+
+ #
+ # Allow this test to be serialized.
+ #
+ def to_s
+ @line
+ end
+
+
+
+ #
+ # Run the test.
+ #
+ def run_test
+
+ # Reset state, in case we've previously run.
+ @error = nil
+
+ begin
+ require 'rubygems'
+ require 'curb'
+ rescue LoadError
+ @error = "The required rubygem 'curb' was not found."
+ return false
+ end
+
+ begin
+ timeout( 20 ) do
+ begin
+ c = Curl::Easy.new()
+ c.follow_location = true
+ c.max_redirects = 10
+ c.ssl_verify_host = false
+ c.proxy_url = @host
+ c.proxy_tunnel = true
+ c.url = "http://google.com/"
+ c.ssl_verify_peer = false
+ c.timeout = 20
+ c.perform
+ @status = c.response_code
+ @content = c.body_str
+ rescue Curl::Err::SSLCACertificateError => x
+ @error = "SSL-Validation error"
+ return false
+ rescue Curl::Err::TimeoutError
+ @error = "Timed out fetching page."
+ return false
+ rescue Curl::Err::TooManyRedirectsError
+ @error = "Too many redirections (more than 10)"
+ return false
+ rescue => x
+ @error = "Exception: #{x}"
+ return false
+ end
+ end
+ rescue Timeout::Error => e
+ @error = "Timed out during fetch."
+ return false
+ end
+
+ #
+ # A this point we've either had an exception, or we've
+ # got a result.
+ #
+ if ( @status.to_i == 200 )
+ return true
+ else
+ @error = "Proxy fetch of http://google.com/ via #{@host} failed"
+ return false
+ end
+ end
+
+
+
+ #
+ # If the test fails then report the error.
+ #
+ def error
+ @error
+ end
+
+
+
+
+ register_test_type "openproxy"
+
+
+
+ end
+ end
+end
diff --git a/lib/custodian/protocoltests.rb b/lib/custodian/protocoltests.rb
index 7ba77e0..da599c9 100644
--- a/lib/custodian/protocoltests.rb
+++ b/lib/custodian/protocoltests.rb
@@ -20,6 +20,7 @@ require 'custodian/protocoltest/ping'
require 'custodian/protocoltest/pop3'
require 'custodian/protocoltest/redis'
require 'custodian/protocoltest/rsync'
+require 'custodian/protocoltest/openproxy'
require 'custodian/protocoltest/ssh'
require 'custodian/protocoltest/smtp'
require 'custodian/protocoltest/smtprelay.rb'