summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSteve Kemp <steve@steve.org.uk>2015-04-16 16:14:06 +0100
committerSteve Kemp <steve@steve.org.uk>2015-04-16 16:14:06 +0100
commit91713ef347d49dca7de7dd9360d42763dd961894 (patch)
tree99f8d3e0ff368cc7bb863cdf7910ffcc629774d4
parent1b9654c79d6bd8e24134ddeef4bf44580a726178 (diff)
Updated test-handler for new API.
This update consists of two changes: * No longer return "true" or "false" instead return "TEST_FAILED", or "TEST_SUCCEEDED". * Removed the testing of test-inversion from the class, now it lives in the base-class where it should have done all along.
-rw-r--r--lib/custodian/protocoltest/dns.rb20
-rw-r--r--lib/custodian/protocoltest/dnsbl.rb18
-rw-r--r--lib/custodian/protocoltest/ftp.rb9
-rw-r--r--lib/custodian/protocoltest/http.rb21
-rw-r--r--lib/custodian/protocoltest/imap.rb10
-rw-r--r--lib/custodian/protocoltest/jabber.rb9
-rw-r--r--lib/custodian/protocoltest/ldap.rb19
-rw-r--r--lib/custodian/protocoltest/mx.rb19
-rw-r--r--lib/custodian/protocoltest/mysql.rb11
-rw-r--r--lib/custodian/protocoltest/named.rb9
-rw-r--r--lib/custodian/protocoltest/openproxy.rb21
-rw-r--r--lib/custodian/protocoltest/ping.rb21
-rw-r--r--lib/custodian/protocoltest/pop3.rb11
-rw-r--r--lib/custodian/protocoltest/postgresql.rb11
-rw-r--r--lib/custodian/protocoltest/redis.rb11
-rw-r--r--lib/custodian/protocoltest/rsync.rb10
-rw-r--r--lib/custodian/protocoltest/smtp.rb9
-rw-r--r--lib/custodian/protocoltest/ssh.rb11
-rw-r--r--lib/custodian/protocoltest/ssl.rb14
-rw-r--r--lib/custodian/protocoltest/tcp.rb24
-rw-r--r--lib/custodian/protocoltest/telnet.rb9
21 files changed, 58 insertions, 239 deletions
diff --git a/lib/custodian/protocoltest/dns.rb b/lib/custodian/protocoltest/dns.rb
index 4685029..b7e75c0 100644
--- a/lib/custodian/protocoltest/dns.rb
+++ b/lib/custodian/protocoltest/dns.rb
@@ -1,4 +1,5 @@
require 'custodian/settings'
+require 'custodian/testfactory'
require 'custodian/util/dns'
require 'resolv'
@@ -44,15 +45,6 @@ module Custodian
#
@line = line
- #
- # Is this test inverted?
- #
- if line =~ /must\s+not\s+run\s+/
- @inverted = true
- else
- @inverted = false
- end
-
if line =~ /for\s+([^\s]+)\sresolving\s([A-Z]+)\s+as\s'([^']+)'/
@resolve_name = $1.dup
@resolve_type = $2.dup
@@ -107,7 +99,7 @@ module Custodian
# Do the lookup
#
results = resolve_via(@host, resolve_type, resolve_name, period)
- return false if results.nil?
+ return Custodian::TestResult::TEST_FAILED if results.nil?
#
# OK we have an array of results. If every one of the expected
@@ -116,9 +108,15 @@ module Custodian
if !(results - @resolve_expected).empty? or !(@resolve_expected - results).empty?
@error = "DNS server *#{@host}* (#{@server_ip}) returned the wrong records for @#{resolve_name} IN #{resolve_type}@.\n\nWe expected '#{resolve_expected.join(',')}', but we received '#{results.join(',')}'\n"
+ return Custodian::TestResult::TEST_FAILED
end
- @error.nil?
+ #
+ # We were valid.
+ #
+ @error = ''
+ Custodian::TestResult::TEST_PASSED
+
end
diff --git a/lib/custodian/protocoltest/dnsbl.rb b/lib/custodian/protocoltest/dnsbl.rb
index a16de0a..0e1459d 100644
--- a/lib/custodian/protocoltest/dnsbl.rb
+++ b/lib/custodian/protocoltest/dnsbl.rb
@@ -42,14 +42,6 @@ module Custodian
@zones = 'zen.spamhaus.org'
end
- #
- # Is this test inverted?
- #
- if line =~ /must\s+not\s+run\s+/
- @inverted = true
- else
- @inverted = false
- end
end
@@ -58,7 +50,7 @@ module Custodian
# Allow this test to be serialized.
#
def to_s
- @line
+ @line
end
@@ -89,16 +81,16 @@ module Custodian
if (!result.nil?) && (result.length > 0)
@error = "IP #{@host} listed in blacklist #{zone}. Lookup of #{name} lead to result: #{result}"
- return true
+ return Custodian::TestResult::TEST_PASSED
end
else
- @error = "#{@host} wasn't an IP address"
- return true
+ @error = "#{@host} wasn't an IP address"
+ return Custodian::TestResult::TEST_PASSED
end
end
- false
+ Custodian::TestResult::TEST_FAILED
end
diff --git a/lib/custodian/protocoltest/ftp.rb b/lib/custodian/protocoltest/ftp.rb
index e3c192d..de3de78 100644
--- a/lib/custodian/protocoltest/ftp.rb
+++ b/lib/custodian/protocoltest/ftp.rb
@@ -37,15 +37,6 @@ module Custodian
end
#
- # Is this test inverted?
- #
- if line =~ /must\s+not\s+run\s+/
- @inverted = true
- else
- @inverted = false
- end
-
- #
# Save the port
#
if line =~ /on\s+([0-9]+)/
diff --git a/lib/custodian/protocoltest/http.rb b/lib/custodian/protocoltest/http.rb
index 9ce1980..997f2f9 100644
--- a/lib/custodian/protocoltest/http.rb
+++ b/lib/custodian/protocoltest/http.rb
@@ -1,5 +1,7 @@
require 'custodian/settings'
+require 'custodian/testfactory'
+
require 'timeout'
require 'uri'
@@ -97,15 +99,6 @@ module Custodian
#
- # Is this test inverted?
- #
- if line =~ /must\s+not\s+run\s+/
- @inverted = true
- else
- @inverted = false
- end
-
- #
# Expected status
#
if line =~ /with status ([0-9]+)/
@@ -203,7 +196,7 @@ module Custodian
require 'curb'
rescue LoadError
@error = "The required rubygem 'curb' was not found."
- return false
+ return Custodian::TestResult::TEST_FAILED
end
#
@@ -309,8 +302,8 @@ module Custodian
end
if content.is_a?(String) and
- expected_content.is_a?(String) and
- content !~ /#{expected_content}/i
+ expected_content.is_a?(String) and
+ content !~ /#{expected_content}/i
errors << "#{protocol_msg}: The response did not contain our expected text '#{expected_content}'."
end
end
@@ -325,13 +318,13 @@ module Custodian
errors << "Host header was overridden as Host: #{@host_override}"
end
@error = errors.join("\n")
- return false
+ return Custodian::TestResult::TEST_FAILED
end
#
# All done.
#
- true
+ Custodian::TestResult::TEST_PASSED
end
#
diff --git a/lib/custodian/protocoltest/imap.rb b/lib/custodian/protocoltest/imap.rb
index 5f6ba25..2c7079e 100644
--- a/lib/custodian/protocoltest/imap.rb
+++ b/lib/custodian/protocoltest/imap.rb
@@ -36,16 +36,6 @@ module Custodian
#
- # Is this test inverted?
- #
- if line =~ /must\s+not\s+run\s+/
- @inverted = true
- else
- @inverted = false
- end
-
-
- #
# Save the port
#
if line =~ /on\s+([0-9]+)/
diff --git a/lib/custodian/protocoltest/jabber.rb b/lib/custodian/protocoltest/jabber.rb
index ab881de..19fc2a4 100644
--- a/lib/custodian/protocoltest/jabber.rb
+++ b/lib/custodian/protocoltest/jabber.rb
@@ -35,15 +35,6 @@ module Custodian
@host = line.split(/\s+/)[0]
#
- # Is this test inverted?
- #
- if line =~ /must\s+not\s+run\s+/
- @inverted = true
- else
- @inverted = false
- end
-
- #
# Save the port
#
if line =~ /on\s+([0-9]+)/
diff --git a/lib/custodian/protocoltest/ldap.rb b/lib/custodian/protocoltest/ldap.rb
index c7429a6..7f8091e 100644
--- a/lib/custodian/protocoltest/ldap.rb
+++ b/lib/custodian/protocoltest/ldap.rb
@@ -55,15 +55,6 @@ module Custodian
end
#
- # Is this test inverted?
- #
- if line =~ /must\s+not\s+run\s+/
- @inverted = true
- else
- @inverted = false
- end
-
- #
# Save the port
#
if line =~ /on\s+([0-9]+)/
@@ -94,7 +85,7 @@ module Custodian
require 'ldap'
rescue LoadError
@error = 'LDAP library not available - test disabled'
- return false
+ return Custodian::TestResult::TEST_FAILED
end
# reset the error, in case we were previously executed.
@@ -122,18 +113,18 @@ module Custodian
puts "We found an LDAP result #{entry.vals('cn')}"
}
ldap.unbind
- return true
+ return Custodian::TestResult::TEST_PASSED
else
@error = "failed to bind to LDAP server '#{@host}' with username '#{@ldap_user}' and password '#{@ldap_pass}'"
- return false
+ return Custodian::TestResult::TEST_FAILED
end
rescue LDAP::ResultError => ex
@error = "LDAP exception: #{ex} when talking to LDAP server '#{@host}' with username '#{@ldap_user}' and password '#{@ldap_pass}'"
- return false
+ return Custodian::TestResult::TEST_FAILED
end
@error = "LDAP server test failed against '#{@host}' with username '#{@ldap_user}' and password '#{@ldap_pass}'"
- false
+ Custodian::TestResult::TEST_FAILED
end
diff --git a/lib/custodian/protocoltest/mx.rb b/lib/custodian/protocoltest/mx.rb
index 3770686..cd5e58e 100644
--- a/lib/custodian/protocoltest/mx.rb
+++ b/lib/custodian/protocoltest/mx.rb
@@ -1,4 +1,5 @@
-require 'custodian/protocoltest/tcp'
+require 'custodian/settings'
+require 'custodian/testfactory'
#
# The MX (DNS + smtp) test.
@@ -28,12 +29,6 @@ module Custodian
# The main domain we're querying
@host = line.split(/\s+/)[0]
- if line =~ /must\s+not\s+run\s+/
- @inverted = true
- else
- @inverted = false
- end
-
end
@@ -78,7 +73,7 @@ module Custodian
end
rescue Timeout::Error => e
@error = "Timed-out performing DNS lookups: #{e}"
- return nil
+ return Custodian::TestResult::TEST_FAILED
end
#
@@ -92,7 +87,7 @@ module Custodian
#
if mx.empty? then
@error = "Failed to perform DNS lookup of MX record(s) for host #{@host}"
- return false
+ return Custodian::TestResult::TEST_FAILED
end
@@ -130,7 +125,7 @@ module Custodian
error += "Error connecting to #{backend}:25. "
end
end
- rescue Timeout::Error => ex
+ rescue Timeout::Error => _ex
# Timeout
failed += 1
error += "Timeout connecting to #{backend}:25. "
@@ -142,9 +137,9 @@ module Custodian
#
if failed > 0
@error = "There are #{mx.size} hosts running as MX-servers for domain #{@host} - #{passed}:OK #{failed}:FAILED - #{error}"
- return false
+ return Custodian::TestResult::TEST_FAILED
else
- return true
+ return Custodian::TestResult::TEST_PASSED
end
end
diff --git a/lib/custodian/protocoltest/mysql.rb b/lib/custodian/protocoltest/mysql.rb
index 152c53f..e462dc4 100644
--- a/lib/custodian/protocoltest/mysql.rb
+++ b/lib/custodian/protocoltest/mysql.rb
@@ -34,17 +34,6 @@ module Custodian
#
@host = line.split(/\s+/)[0]
-
- #
- # Is this test inverted?
- #
- if line =~ /must\s+not\s+run\s+/
- @inverted = true
- else
- @inverted = false
- end
-
-
#
# Save the port
#
diff --git a/lib/custodian/protocoltest/named.rb b/lib/custodian/protocoltest/named.rb
index bb87e85..6738383 100644
--- a/lib/custodian/protocoltest/named.rb
+++ b/lib/custodian/protocoltest/named.rb
@@ -35,15 +35,6 @@ module Custodian
@host = line.split(/\s+/)[0]
#
- # Is this test inverted?
- #
- if line =~ /must\s+not\s+run\s+/
- @inverted = true
- else
- @inverted = false
- end
-
- #
# Save the port
#
if line =~ /on\s+([0-9]+)/
diff --git a/lib/custodian/protocoltest/openproxy.rb b/lib/custodian/protocoltest/openproxy.rb
index 07f608f..d3acfaa 100644
--- a/lib/custodian/protocoltest/openproxy.rb
+++ b/lib/custodian/protocoltest/openproxy.rb
@@ -1,5 +1,6 @@
-
require 'custodian/settings'
+require 'custodian/testfactory'
+
require 'uri'
@@ -41,14 +42,6 @@ module Custodian
#
@host = line.split(/\s+/)[0]
- #
- # Is this test inverted?
- #
- if line =~ /must\s+not\s+run\s+/
- @inverted = true
- else
- @inverted = false
- end
end
@@ -112,9 +105,9 @@ module Custodian
return false
end
end
- rescue Timeout::Error => e
+ rescue Timeout::Error => _e
@error = 'Timed out during fetch.'
- return false
+ return Custodian::TestResult::TEST_FAILED
end
#
@@ -122,10 +115,10 @@ module Custodian
# got a result.
#
if (@status.to_i == 200)
- return true
+ return Custodian::TestResult::TEST_PASSED
else
- @error = "Proxy fetch of http://google.com/ via #{@host} failed"
- return false
+ @error = "Proxy fetch of http://google.com/ via #{@host} failed"
+ return Custodian::TestResult::TEST_FAILED
end
end
diff --git a/lib/custodian/protocoltest/ping.rb b/lib/custodian/protocoltest/ping.rb
index 7622fb5..075f8db 100644
--- a/lib/custodian/protocoltest/ping.rb
+++ b/lib/custodian/protocoltest/ping.rb
@@ -1,3 +1,4 @@
+require 'custodian/settings'
require 'custodian/testfactory'
@@ -38,14 +39,6 @@ module Custodian
#
@host = line.split(/\s+/)[0]
- #
- # Is this test inverted?
- #
- if line =~ /must\s+not\s+run\s+/
- @inverted = true
- else
- @inverted = false
- end
end
@@ -75,7 +68,7 @@ module Custodian
if binary.nil?
@error = "Failed to find '/usr/bin/multi-ping'"
- return false
+ return Custodian::TestResult::TEST_FAILED
end
@@ -87,7 +80,7 @@ module Custodian
#
if @host !~ /^([a-zA-Z0-9:\-\.]+)$/
@error = "Invalid hostname for ping-test: #{@host}"
- return false
+ return Custodian::TestResult::TEST_FAILED
end
@@ -152,7 +145,7 @@ module Custodian
end
rescue Timeout::Error => e
@error = "Timed-out performing DNS lookups: #{e}"
- return nil
+ return Custodian::TestResult::TEST_FAILED
end
@@ -161,7 +154,7 @@ module Custodian
#
if ips.empty?
@error = "#{@host} failed to resolve to either IPv4 or IPv6"
- return false
+ return Custodian::TestResult::TEST_FAILED
end
@@ -173,7 +166,7 @@ module Custodian
ips.each do |ip|
if (system(binary, ip) != true)
@error = "Ping failed for #{ip} - from #{@host} "
- return false
+ return Custodian::TestResult::TEST_FAILED
end
end
@@ -184,7 +177,7 @@ module Custodian
# So by the time we reach here we know that all the addresses
# were pingable.
#
- true
+ Custodian::TestResult::TEST_PASSED
end
diff --git a/lib/custodian/protocoltest/pop3.rb b/lib/custodian/protocoltest/pop3.rb
index 2429c79..c66555d 100644
--- a/lib/custodian/protocoltest/pop3.rb
+++ b/lib/custodian/protocoltest/pop3.rb
@@ -34,17 +34,6 @@ module Custodian
#
@host = line.split(/\s+/)[0]
-
- #
- # Is this test inverted?
- #
- if line =~ /must\s+not\s+run\s+/
- @inverted = true
- else
- @inverted = false
- end
-
-
#
# Save the port
#
diff --git a/lib/custodian/protocoltest/postgresql.rb b/lib/custodian/protocoltest/postgresql.rb
index d88d131..85baa76 100644
--- a/lib/custodian/protocoltest/postgresql.rb
+++ b/lib/custodian/protocoltest/postgresql.rb
@@ -34,17 +34,6 @@ module Custodian
#
@host = line.split(/\s+/)[0]
-
- #
- # Is this test inverted?
- #
- if line =~ /must\s+not\s+run\s+/
- @inverted = true
- else
- @inverted = false
- end
-
-
#
# Save the port
#
diff --git a/lib/custodian/protocoltest/redis.rb b/lib/custodian/protocoltest/redis.rb
index 88ac67a..75ff15b 100644
--- a/lib/custodian/protocoltest/redis.rb
+++ b/lib/custodian/protocoltest/redis.rb
@@ -34,17 +34,6 @@ module Custodian
#
@host = line.split(/\s+/)[0]
-
- #
- # Is this test inverted?
- #
- if line =~ /must\s+not\s+run\s+/
- @inverted = true
- else
- @inverted = false
- end
-
-
#
# Save the port
#
diff --git a/lib/custodian/protocoltest/rsync.rb b/lib/custodian/protocoltest/rsync.rb
index 1a52b03..ec91429 100644
--- a/lib/custodian/protocoltest/rsync.rb
+++ b/lib/custodian/protocoltest/rsync.rb
@@ -38,16 +38,6 @@ module Custodian
end
#
- # Is this test inverted?
- #
- if line =~ /must\s+not\s+run\s+/
- @inverted = true
- else
- @inverted = false
- end
-
-
- #
# Save the port
#
if line =~ /on\s+([0-9]+)/
diff --git a/lib/custodian/protocoltest/smtp.rb b/lib/custodian/protocoltest/smtp.rb
index 6968ae9..e724c14 100644
--- a/lib/custodian/protocoltest/smtp.rb
+++ b/lib/custodian/protocoltest/smtp.rb
@@ -35,15 +35,6 @@ module Custodian
@host = line.split(/\s+/)[0]
#
- # Is this test inverted?
- #
- if line =~ /must\s+not\s+run\s+/
- @inverted = true
- else
- @inverted = false
- end
-
- #
# Save the port
#
if line =~ /on\s+([0-9]+)/
diff --git a/lib/custodian/protocoltest/ssh.rb b/lib/custodian/protocoltest/ssh.rb
index feb50f2..e68a93f 100644
--- a/lib/custodian/protocoltest/ssh.rb
+++ b/lib/custodian/protocoltest/ssh.rb
@@ -35,17 +35,6 @@ module Custodian
#
@host = line.split(/\s+/)[0]
-
- #
- # Is this test inverted?
- #
- if line =~ /must\s+not\s+run\s+/
- @inverted = true
- else
- @inverted = false
- end
-
-
#
# Save the port
#
diff --git a/lib/custodian/protocoltest/ssl.rb b/lib/custodian/protocoltest/ssl.rb
index f2baf67..cc36652 100644
--- a/lib/custodian/protocoltest/ssl.rb
+++ b/lib/custodian/protocoltest/ssl.rb
@@ -162,7 +162,7 @@ class SSLCheck
# Setup a hostname for SNI-purposes.
begin
s.hostname = uri.host
- rescue NoMethodError => err
+ rescue NoMethodError => _err
# SNI isn't possible, as the SSL library is too old.
end
@@ -391,7 +391,7 @@ module Custodian
# If the line disables us then return early
#
if @line =~ /no_ssl_check/
- return true
+ return Custodian::TestResult::TEST_PASSED
end
@@ -405,7 +405,7 @@ module Custodian
#
if hour < 10 || hour > 17
puts("Outside office hours - Not running SSL-Verification of #{@host}")
- return true
+ return Custodian::TestResult::TEST_SKIPPED
end
#
@@ -413,7 +413,7 @@ module Custodian
#
if ! @host =~ /^https:\/\//
puts('Not an SSL URL')
- return true
+ return Custodian::TestResult::TEST_SKIPPED
end
s = SSLCheck.new(@host)
@@ -421,15 +421,15 @@ module Custodian
if true == result
puts("SSL Verification succeeded for #{@host}")
- return true
+ return Custodian::TestResult::TEST_PASSED
elsif result.nil?
puts("SSL Verification returned no result (timeout?) #{@host}")
- return true
+ return Custodian::TestResult::TEST_PASSED
else
puts("SSL Verification for #{@host} has failed.")
@error = "SSL Verification for #{@host} failed: "
@error += s.errors.join("\n")
- return false
+ return Custodian::TestResult::TEST_FAILED
end
end
diff --git a/lib/custodian/protocoltest/tcp.rb b/lib/custodian/protocoltest/tcp.rb
index 1747f3f..684452b 100644
--- a/lib/custodian/protocoltest/tcp.rb
+++ b/lib/custodian/protocoltest/tcp.rb
@@ -40,13 +40,6 @@ module Custodian
#
attr_reader :port
-
- #
- # Is this test inverted?
- #
- attr_reader :inverted
-
-
#
# The banner to look for, may be nil.
#
@@ -73,15 +66,6 @@ module Custodian
@host = line.split(/\s+/)[0]
#
- # Is this test inverted?
- #
- if line =~ /must\s+not\s+run\s+/
- @inverted = true
- else
- @inverted = false
- end
-
- #
# Save the port
#
if line =~ /on\s+([0-9]+)/
@@ -213,7 +197,7 @@ module Custodian
end
rescue Timeout::Error => e
@error = "Timed-out performing DNS lookups: #{e}"
- return nil
+ return Custodian::TestResult::TEST_FAILED
end
@@ -222,7 +206,7 @@ module Custodian
#
if ips.empty?
@error = "#{@host} failed to resolve to either IPv4 or IPv6"
- return false
+ return Custodian::TestResult::TEST_FAILED
end
@@ -234,7 +218,7 @@ module Custodian
ips.each do |ip|
if !run_test_internal_real(ip, port, banner, do_read)
- return false
+ return Custodian::TestResult::TEST_FAILED
#
# @error will be already set.
#
@@ -246,7 +230,7 @@ module Custodian
# All was OK
#
@error = nil
- true
+ Custodian::TestResult::TEST_PASSED
end
diff --git a/lib/custodian/protocoltest/telnet.rb b/lib/custodian/protocoltest/telnet.rb
index 229b02d..032117d 100644
--- a/lib/custodian/protocoltest/telnet.rb
+++ b/lib/custodian/protocoltest/telnet.rb
@@ -35,15 +35,6 @@ module Custodian
@host = line.split(/\s+/)[0]
#
- # Is this test inverted?
- #
- if line =~ /must\s+not\s+run\s+/
- @inverted = true
- else
- @inverted = false
- end
-
- #
# Save the port
#
if line =~ /on\s+([0-9]+)/