From 12de7cf1aefcd5d567a9e6e2eaa061f2074c8dbb Mon Sep 17 00:00:00 2001 From: Steve Kemp Date: Fri, 22 Apr 2016 21:42:32 +0300 Subject: More updates to silence rubocop style-guides. These warnings were largely whitespace-based. --- .rubocop.yml | 18 ++++++--- lib/custodian/protocoltest/dns.rb | 10 ++--- lib/custodian/protocoltest/dnsbl.rb | 8 ++-- lib/custodian/protocoltest/ftp.rb | 6 +-- lib/custodian/protocoltest/http.rb | 68 +++++++++++++++----------------- lib/custodian/protocoltest/imap.rb | 4 +- lib/custodian/protocoltest/jabber.rb | 4 +- lib/custodian/protocoltest/ldap.rb | 16 ++++---- lib/custodian/protocoltest/mx.rb | 8 ++-- lib/custodian/protocoltest/mysql.rb | 4 +- lib/custodian/protocoltest/named.rb | 4 +- lib/custodian/protocoltest/openproxy.rb | 2 +- lib/custodian/protocoltest/ping.rb | 18 ++++----- lib/custodian/protocoltest/pop3.rb | 4 +- lib/custodian/protocoltest/postgresql.rb | 4 +- lib/custodian/protocoltest/rdp.rb | 4 +- lib/custodian/protocoltest/redis.rb | 4 +- lib/custodian/protocoltest/rsync.rb | 6 +-- lib/custodian/protocoltest/smtp.rb | 4 +- lib/custodian/protocoltest/ssh.rb | 4 +- lib/custodian/protocoltest/ssl.rb | 16 ++++---- lib/custodian/protocoltest/tcp.rb | 38 +++++++++--------- lib/custodian/protocoltest/telnet.rb | 4 +- lib/custodian/protocoltest/tftp.rb | 4 +- 24 files changed, 131 insertions(+), 131 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index 55eea3c..8fcb264 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -90,6 +90,12 @@ Metrics/PerceivedComplexity: Style/AccessorMethodName: Enabled: false +Style/ConditionalAssignment: + Enabled: false + +Style/ParenthesesAroundCondition: + Enabled: false + # Offense count: 1 # Cop supports --auto-correct. Style/Alias: @@ -281,12 +287,6 @@ Style/NegatedIf: Style/Next: Enabled: false -# Offense count: 185 -# Cop supports --auto-correct. -# Configuration parameters: AllowSafeAssignment. -Style/ParenthesesAroundCondition: - Enabled: true - # Offense count: 48 # Cop supports --auto-correct. Style/PerlBackrefs: @@ -302,6 +302,9 @@ Style/PredicateName: Style/RedundantBegin: Enabled: false +Style/RegexpLiteral: + Enabled: false + # Offense count: 20 # Cop supports --auto-correct. # Configuration parameters: AllowMultipleReturnValues. @@ -313,6 +316,9 @@ Style/RedundantReturn: Style/RedundantSelf: Enabled: false +Style/RedundantParentheses: + Enabled: false + # Offense count: 16 # Cop supports --auto-correct. # Configuration parameters: AllowAsExpressionSeparator. diff --git a/lib/custodian/protocoltest/dns.rb b/lib/custodian/protocoltest/dns.rb index b7e75c0..10844db 100644 --- a/lib/custodian/protocoltest/dns.rb +++ b/lib/custodian/protocoltest/dns.rb @@ -45,7 +45,7 @@ module Custodian # @line = line - if line =~ /for\s+([^\s]+)\sresolving\s([A-Z]+)\s+as\s'([^']+)'/ + if line =~ /for\s+([^\s]+)\sresolving\s([A-Z]+)\s+as\s'([^']+)'/ @resolve_name = $1.dup @resolve_type = $2.dup @resolve_expected = $3.dup.downcase.split(/[\s,]+/) @@ -93,20 +93,20 @@ module Custodian # Get the timeout period. # settings = Custodian::Settings.instance - period = settings.timeout + period = settings.timeout # # Do the lookup # - results = resolve_via(@host, resolve_type, resolve_name, period) - return Custodian::TestResult::TEST_FAILED if results.nil? + results = resolve_via(@host, resolve_type, resolve_name, period) + return Custodian::TestResult::TEST_FAILED if results.nil? # # OK we have an array of results. If every one of the expected # results is contained in those results returned then we're good. # - if !(results - @resolve_expected).empty? or !(@resolve_expected - results).empty? + 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 diff --git a/lib/custodian/protocoltest/dnsbl.rb b/lib/custodian/protocoltest/dnsbl.rb index 0e1459d..37dbd74 100644 --- a/lib/custodian/protocoltest/dnsbl.rb +++ b/lib/custodian/protocoltest/dnsbl.rb @@ -36,7 +36,7 @@ module Custodian # # See which blacklist(s) we're testing against. # - if line =~ /via\s+([^\s]+)\s+/ + if line =~ /via\s+([^\s]+)\s+/ @zones = $1.dup else @zones = 'zen.spamhaus.org' @@ -63,7 +63,7 @@ module Custodian def run_test # The error is empty. - @error = nil + @error = nil @zones.split(',').each do |zone| @@ -73,13 +73,13 @@ module Custodian # Given IP 1.2.3.4 we lookup the address of the name # 4.3.2.1.$zone # - if @host =~ /^([0-9]+)\.([0-9]+)\.([0-9]+)\.([0-9]+)$/ + if @host =~ /^([0-9]+)\.([0-9]+)\.([0-9]+)\.([0-9]+)$/ name = "#{$4}.#{$3}.#{$2}.#{$1}.#{zone}" result = Custodian::Util::DNS.hostname_to_ip(name) - if (!result.nil?) && (result.length > 0) + if (!result.nil?) && (!result.empty?) @error = "IP #{@host} listed in blacklist #{zone}. Lookup of #{name} lead to result: #{result}" return Custodian::TestResult::TEST_PASSED end diff --git a/lib/custodian/protocoltest/ftp.rb b/lib/custodian/protocoltest/ftp.rb index de3de78..8061478 100644 --- a/lib/custodian/protocoltest/ftp.rb +++ b/lib/custodian/protocoltest/ftp.rb @@ -31,15 +31,15 @@ module Custodian # # Save the host # - @host = line.split(/\s+/)[0] - if @host =~ /^ftp:\/\/([^\/]+)\/?/ + @host = line.split(/\s+/)[0] + if @host =~ /^ftp:\/\/([^\/]+)\/?/ @host = $1.dup end # # Save the port # - if line =~ /on\s+([0-9]+)/ + if line =~ /on\s+([0-9]+)/ @port = $1.dup else @port = 21 diff --git a/lib/custodian/protocoltest/http.rb b/lib/custodian/protocoltest/http.rb index 4632630..89d8f18 100644 --- a/lib/custodian/protocoltest/http.rb +++ b/lib/custodian/protocoltest/http.rb @@ -50,7 +50,7 @@ module Custodian # # Save the URL # - @url = line.split(/\s+/)[0] + @url = line.split(/\s+/)[0] @host = @url # @@ -67,7 +67,7 @@ module Custodian # # Ensure we've got a HTTP/HTTPS url. # - if @url !~ /^https?:/ + if @url !~ /^https?:/ raise ArgumentError, "The target wasn't a HTTP/HTTPS URL: #{line}" end @@ -101,20 +101,20 @@ module Custodian # # Expected status # - if line =~ /with status ([0-9]+)/ + if line =~ /with status ([0-9]+)/ @expected_status = $1.dup else @expected_status = '200' end - if line =~ /with (IPv[46])/i + if line =~ /with (IPv[46])/i @resolve_modes << $1.downcase.to_sym end # # The content we expect to find # - if line =~ /with content (["'])(.*?)\1/ + if line =~ /with content (["'])(.*?)\1/ @expected_content = $2.dup else @expected_content = nil @@ -123,7 +123,7 @@ module Custodian # # Do we follow redirects? # - if line =~ /not following redirects?/i + if line =~ /not following redirects?/i @redirect = false end @@ -131,22 +131,22 @@ module Custodian # Do we use cache-busting? # @cache_busting = true - if line =~ /with\s+cache\s+busting/ + if line =~ /with\s+cache\s+busting/ @cache_busting = true end - if line =~ /without\s+cache\s+busting/ + if line =~ /without\s+cache\s+busting/ @cache_busting = false end # Do we need to override the HTTP Host: Header? @host_override = nil - if line =~ /with host header '([^']+)'/ + if line =~ /with host header '([^']+)'/ @host_override = $1.dup end # We can't test on IPv4-only or IPv6-only basis - if line =~ /ipv[46]_only/i - raise ArgumentError, "We cannot limit HTTP/HTTPS tests to IPv4/IPv6-only" + if line =~ /ipv[46]_only/i + raise ArgumentError, 'We cannot limit HTTP/HTTPS tests to IPv4/IPv6-only' end end @@ -156,9 +156,9 @@ module Custodian # Get the right type of this object, based on the URL # def get_type - if @url =~ /^https:/ + if @url =~ /^https:/ 'https' - elsif @url =~ /^http:/ + elsif @url =~ /^http:/ 'http' else raise ArgumentError, "URL isn't http/https: #{@url}" @@ -193,9 +193,8 @@ module Custodian # Run the test. # def run_test - - # Reset state, in case we've previously run. - @error = nil + # Reset state, in case we've previously run. + @error = nil begin require 'rubygems' @@ -205,11 +204,9 @@ module Custodian return Custodian::TestResult::TEST_FAILED end - # # Get the timeout period for this test. - # settings = Custodian::Settings.instance - period = settings.timeout + period = settings.timeout # # The URL we'll fetch/poll. @@ -220,26 +217,23 @@ module Custodian # Parse and append a query-string if not present, if we're # running with cache-busting. # - if @cache_busting + if @cache_busting u = URI.parse(test_url) - if !u.query - u.query = "ctime=#{Time.now.to_i}" - test_url = u.to_s + if !u.query + u.query = "ctime=#{Time.now.to_i}" + test_url = u.to_s end end errors = [] resolution_errors = [] - if @resolve_modes.empty? - resolve_modes = [:ipv4, :ipv6] - else - resolve_modes = @resolve_modes - end + resolve_modes = [:ipv4, :ipv6] + resolve_modes = @resolve_modes if !@resolve_modes.empty? resolve_modes.each do |resolve_mode| - status = nil - content = nil + status = nil + content = nil c = Curl::Easy.new(test_url) @@ -248,9 +242,9 @@ module Custodian # # Should we follow redirections? # - if follow_redirects? + if follow_redirects? c.follow_location = true - c.max_redirects = 10 + c.max_redirects = 10 end unless @host_override.nil? @@ -259,7 +253,7 @@ module Custodian c.ssl_verify_host = false c.ssl_verify_peer = false - c.timeout = period + c.timeout = period # # Set a basic protocol message, for use later. @@ -278,7 +272,7 @@ module Custodian # if c.primary_ip if :ipv4 == resolve_mode - protocol_msg = "#{c.primary_ip}" + protocol_msg = c.primary_ip.to_s else protocol_msg = "[#{c.primary_ip}]" end @@ -305,11 +299,11 @@ module Custodian # A this point we've either had an exception, or we've # got a result # - if status and expected_status.to_i != status.to_i + if status and expected_status.to_i != status.to_i errors << "#{protocol_msg}: Status code was #{status} not the expected #{expected_status}." end - if content.is_a?(String) and + if content.is_a?(String) and expected_content.is_a?(String) and content !~ /#{expected_content}/i errors << "#{protocol_msg}: The response did not contain our expected text '#{expected_content}'." @@ -321,7 +315,7 @@ module Custodian errors << "Hostname did not resolve for #{resolution_errors.join(', ')}" end - if errors.length > 0 + if !errors.empty? if @host_override errors << "Host header was overridden as Host: #{@host_override}" end diff --git a/lib/custodian/protocoltest/imap.rb b/lib/custodian/protocoltest/imap.rb index 2c7079e..eea64e6 100644 --- a/lib/custodian/protocoltest/imap.rb +++ b/lib/custodian/protocoltest/imap.rb @@ -32,13 +32,13 @@ module Custodian # # Save the host # - @host = line.split(/\s+/)[0] + @host = line.split(/\s+/)[0] # # Save the port # - if line =~ /on\s+([0-9]+)/ + if line =~ /on\s+([0-9]+)/ @port = $1.dup else @port = 143 diff --git a/lib/custodian/protocoltest/jabber.rb b/lib/custodian/protocoltest/jabber.rb index 19fc2a4..a5eb574 100644 --- a/lib/custodian/protocoltest/jabber.rb +++ b/lib/custodian/protocoltest/jabber.rb @@ -32,12 +32,12 @@ module Custodian # # Save the host # - @host = line.split(/\s+/)[0] + @host = line.split(/\s+/)[0] # # Save the port # - if line =~ /on\s+([0-9]+)/ + if line =~ /on\s+([0-9]+)/ @port = $1.dup else @port = 5222 diff --git a/lib/custodian/protocoltest/ldap.rb b/lib/custodian/protocoltest/ldap.rb index 7f8091e..d0dc01e 100644 --- a/lib/custodian/protocoltest/ldap.rb +++ b/lib/custodian/protocoltest/ldap.rb @@ -32,7 +32,7 @@ module Custodian # # Save the host # - @host = line.split(/\s+/)[0] + @host = line.split(/\s+/)[0] # # The username/password @@ -40,24 +40,24 @@ module Custodian @ldap_user = nil @ldap_pass = nil - if line =~ /with\s+username\s+'([^']+)'/ + if line =~ /with\s+username\s+'([^']+)'/ @ldap_user = $1.dup end - if line =~ /with\s+password\s+'([^']+)'/ + if line =~ /with\s+password\s+'([^']+)'/ @ldap_pass = $1.dup end - if @ldap_user.nil? + if @ldap_user.nil? raise ArgumentError, "No username specified: #{@line}" end - if @ldap_pass.nil? + if @ldap_pass.nil? raise ArgumentError, "No password specified: #{@line}" end # # Save the port # - if line =~ /on\s+([0-9]+)/ + if line =~ /on\s+([0-9]+)/ @port = $1.dup.to_i else @port = 389 @@ -104,12 +104,12 @@ module Custodian # Bind. ldap.bind(@ldap_user, @ldap_pass) - if ldap.bound? + if ldap.bound? # # Search # - ldap.search(base, scope, filter, attrs) { |entry| + ldap.search(base, scope, filter, attrs) { |entry| puts "We found an LDAP result #{entry.vals('cn')}" } ldap.unbind diff --git a/lib/custodian/protocoltest/mx.rb b/lib/custodian/protocoltest/mx.rb index cd5e58e..378a257 100644 --- a/lib/custodian/protocoltest/mx.rb +++ b/lib/custodian/protocoltest/mx.rb @@ -85,7 +85,7 @@ module Custodian # # So on that basis we must alert. # - if mx.empty? then + if mx.empty? then @error = "Failed to perform DNS lookup of MX record(s) for host #{@host}" return Custodian::TestResult::TEST_FAILED end @@ -109,12 +109,12 @@ module Custodian read = socket.sysread(1024) # trim to a sane length & strip newlines. - if !read.nil? + if !read.nil? read = read[0, 255] read.gsub!(/[\n\r]/, '') end - if read =~ /^220/ + if read =~ /^220/ passed += 1 else failed += 1 @@ -135,7 +135,7 @@ module Custodian # # At this point we should have tested the things # - if failed > 0 + if failed > 0 @error = "There are #{mx.size} hosts running as MX-servers for domain #{@host} - #{passed}:OK #{failed}:FAILED - #{error}" return Custodian::TestResult::TEST_FAILED else diff --git a/lib/custodian/protocoltest/mysql.rb b/lib/custodian/protocoltest/mysql.rb index e462dc4..43ea5bb 100644 --- a/lib/custodian/protocoltest/mysql.rb +++ b/lib/custodian/protocoltest/mysql.rb @@ -32,12 +32,12 @@ module Custodian # # Save the host # - @host = line.split(/\s+/)[0] + @host = line.split(/\s+/)[0] # # Save the port # - if line =~ /on\s+([0-9]+)/ + if line =~ /on\s+([0-9]+)/ @port = $1.dup else @port = 3306 diff --git a/lib/custodian/protocoltest/named.rb b/lib/custodian/protocoltest/named.rb index 6738383..ec3b6e6 100644 --- a/lib/custodian/protocoltest/named.rb +++ b/lib/custodian/protocoltest/named.rb @@ -32,12 +32,12 @@ module Custodian # # Save the host # - @host = line.split(/\s+/)[0] + @host = line.split(/\s+/)[0] # # Save the port # - if line =~ /on\s+([0-9]+)/ + if line =~ /on\s+([0-9]+)/ @port = $1.dup else @port = 53 diff --git a/lib/custodian/protocoltest/openproxy.rb b/lib/custodian/protocoltest/openproxy.rb index d3acfaa..ba0f0dd 100644 --- a/lib/custodian/protocoltest/openproxy.rb +++ b/lib/custodian/protocoltest/openproxy.rb @@ -60,7 +60,7 @@ module Custodian def run_test # Reset state, in case we've previously run. - @error = nil + @error = nil begin require 'rubygems' diff --git a/lib/custodian/protocoltest/ping.rb b/lib/custodian/protocoltest/ping.rb index 075f8db..44da04d 100644 --- a/lib/custodian/protocoltest/ping.rb +++ b/lib/custodian/protocoltest/ping.rb @@ -64,9 +64,9 @@ module Custodian # binary = nil binary = './bin/multi-ping' - binary = '/usr/bin/multi-ping' if File.exist?('/usr/bin/multi-ping') + binary = '/usr/bin/multi-ping' if File.exist?('/usr/bin/multi-ping') - if binary.nil? + if binary.nil? @error = "Failed to find '/usr/bin/multi-ping'" return Custodian::TestResult::TEST_FAILED end @@ -78,7 +78,7 @@ module Custodian # # $(/tmp/exploit.sh) must run ping .. # - if @host !~ /^([a-zA-Z0-9:\-\.]+)$/ + if @host !~ /^([a-zA-Z0-9:\-\.]+)$/ @error = "Invalid hostname for ping-test: #{@host}" return Custodian::TestResult::TEST_FAILED end @@ -102,7 +102,7 @@ module Custodian # begin x = IPAddr.new(@host) - if x.ipv4? or x.ipv6? + if x.ipv4? or x.ipv6? ips.push(@host) end rescue ArgumentError @@ -118,10 +118,10 @@ module Custodian # # Allow the test to disable one/both # - if @line =~ /ipv4_only/ + if @line =~ /ipv4_only/ do_ipv6 = false end - if @line =~ /ipv6_only/ + if @line =~ /ipv6_only/ do_ipv4 = false end @@ -133,11 +133,11 @@ module Custodian timeout(period) do Resolv::DNS.open do |dns| - if do_ipv4 + if do_ipv4 ress = dns.getresources(@host, Resolv::DNS::Resource::IN::A) ress.map { |r| ips.push(r.address.to_s) } end - if do_ipv6 + if do_ipv6 ress = dns.getresources(@host, Resolv::DNS::Resource::IN::AAAA) ress.map { |r| ips.push(r.address.to_s) } end @@ -152,7 +152,7 @@ module Custodian # # Did we fail to perform a DNS lookup? # - if ips.empty? + if ips.empty? @error = "#{@host} failed to resolve to either IPv4 or IPv6" return Custodian::TestResult::TEST_FAILED end diff --git a/lib/custodian/protocoltest/pop3.rb b/lib/custodian/protocoltest/pop3.rb index c66555d..562e4a2 100644 --- a/lib/custodian/protocoltest/pop3.rb +++ b/lib/custodian/protocoltest/pop3.rb @@ -32,12 +32,12 @@ module Custodian # # Save the host # - @host = line.split(/\s+/)[0] + @host = line.split(/\s+/)[0] # # Save the port # - if line =~ /on\s+([0-9]+)/ + if line =~ /on\s+([0-9]+)/ @port = $1.dup else @port = 110 diff --git a/lib/custodian/protocoltest/postgresql.rb b/lib/custodian/protocoltest/postgresql.rb index 85baa76..2cdef92 100644 --- a/lib/custodian/protocoltest/postgresql.rb +++ b/lib/custodian/protocoltest/postgresql.rb @@ -32,12 +32,12 @@ module Custodian # # Save the host # - @host = line.split(/\s+/)[0] + @host = line.split(/\s+/)[0] # # Save the port # - if line =~ /on\s+([0-9]+)/ + if line =~ /on\s+([0-9]+)/ @port = $1.dup else @port = 5432 diff --git a/lib/custodian/protocoltest/rdp.rb b/lib/custodian/protocoltest/rdp.rb index 535d950..a259c3f 100644 --- a/lib/custodian/protocoltest/rdp.rb +++ b/lib/custodian/protocoltest/rdp.rb @@ -31,12 +31,12 @@ module Custodian # # Save the host # - @host = line.split(/\s+/)[0] + @host = line.split(/\s+/)[0] # # Save the port # - if line =~ /on\s+([0-9]+)/ + if line =~ /on\s+([0-9]+)/ @port = $1.dup else @port = 3389 diff --git a/lib/custodian/protocoltest/redis.rb b/lib/custodian/protocoltest/redis.rb index 75ff15b..f6080de 100644 --- a/lib/custodian/protocoltest/redis.rb +++ b/lib/custodian/protocoltest/redis.rb @@ -32,12 +32,12 @@ module Custodian # # Save the host # - @host = line.split(/\s+/)[0] + @host = line.split(/\s+/)[0] # # Save the port # - if line =~ /on\s+([0-9]+)/ + if line =~ /on\s+([0-9]+)/ @port = $1.dup else @port = 6379 diff --git a/lib/custodian/protocoltest/rsync.rb b/lib/custodian/protocoltest/rsync.rb index ec91429..ad1c711 100644 --- a/lib/custodian/protocoltest/rsync.rb +++ b/lib/custodian/protocoltest/rsync.rb @@ -32,15 +32,15 @@ module Custodian # # If the target is an URL then strip to the hostname. # - @host = line.split(/\s+/)[0] - if @host =~ /^rsync:\/\/([^\/]+)\/?/ + @host = line.split(/\s+/)[0] + if @host =~ /^rsync:\/\/([^\/]+)\/?/ @host = $1.dup end # # Save the port # - if line =~ /on\s+([0-9]+)/ + if line =~ /on\s+([0-9]+)/ @port = $1.dup else @port = 873 diff --git a/lib/custodian/protocoltest/smtp.rb b/lib/custodian/protocoltest/smtp.rb index e724c14..a2d3a59 100644 --- a/lib/custodian/protocoltest/smtp.rb +++ b/lib/custodian/protocoltest/smtp.rb @@ -32,12 +32,12 @@ module Custodian # # Save the host # - @host = line.split(/\s+/)[0] + @host = line.split(/\s+/)[0] # # Save the port # - if line =~ /on\s+([0-9]+)/ + if line =~ /on\s+([0-9]+)/ @port = $1.dup else @port = 25 diff --git a/lib/custodian/protocoltest/ssh.rb b/lib/custodian/protocoltest/ssh.rb index e68a93f..99e155c 100644 --- a/lib/custodian/protocoltest/ssh.rb +++ b/lib/custodian/protocoltest/ssh.rb @@ -33,12 +33,12 @@ module Custodian # # Save the host # - @host = line.split(/\s+/)[0] + @host = line.split(/\s+/)[0] # # Save the port # - if line =~ /on\s+([0-9]+)/ + if line =~ /on\s+([0-9]+)/ @port = $1.dup else @port = 22 diff --git a/lib/custodian/protocoltest/ssl.rb b/lib/custodian/protocoltest/ssl.rb index 426e73a..170a6f0 100644 --- a/lib/custodian/protocoltest/ssl.rb +++ b/lib/custodian/protocoltest/ssl.rb @@ -200,7 +200,7 @@ class SSLCheck self.errors << verbose("Failed to fetch certificate for #{self.domain}") return nil else - return ![verify_subject, verify_valid_from, verify_valid_to, verify_signature ].any? { |r| false == r } + return ![verify_subject, verify_valid_from, verify_valid_to, verify_signature].any? { |r| false == r } end end @@ -240,7 +240,7 @@ class SSLCheck verbose "Skipping signing algorithm check for #{self.domain}" return true end - if self.certificate.signature_algorithm.start_with? "sha1" + if self.certificate.signature_algorithm.start_with? 'sha1' self.errors << verbose("Certificate for #{self.domain} is signed with a weak algorithm (SHA1) and should be reissued.") return false else @@ -403,7 +403,7 @@ module Custodian # # If the line disables us then return early # - if @line =~ /no_ssl_check/ + if @line =~ /no_ssl_check/ return Custodian::TestResult::TEST_PASSED end @@ -416,7 +416,7 @@ module Custodian # # If outside 10AM-5PM we don't run the test. # - if hour < 10 || hour > 17 + if hour < 10 || hour > 17 puts("Outside office hours - Not running SSL-Verification of #{@host}") return Custodian::TestResult::TEST_SKIPPED end @@ -424,7 +424,7 @@ module Custodian # # Double-check we've got an SSL host # - if ! @host =~ /^https:\/\// + if !@host =~ /^https:\/\// puts('Not an SSL URL') return Custodian::TestResult::TEST_SKIPPED end @@ -440,8 +440,8 @@ module Custodian return Custodian::TestResult::TEST_PASSED else puts("SSL Verification for #{@host} has failed.") - @error = "SSL Verification for #{@host} failed: " - @error += s.errors.join("\n") + @error = "SSL Verification for #{@host} failed: " + @error += s.errors.join("\n") return Custodian::TestResult::TEST_FAILED end @@ -461,7 +461,7 @@ module Custodian # summary. # def get_type - "ssl-validity" + 'ssl-validity' end diff --git a/lib/custodian/protocoltest/tcp.rb b/lib/custodian/protocoltest/tcp.rb index c50c144..0ab4ff6 100644 --- a/lib/custodian/protocoltest/tcp.rb +++ b/lib/custodian/protocoltest/tcp.rb @@ -63,24 +63,24 @@ module Custodian # # Save the host # - @host = line.split(/\s+/)[0] + @host = line.split(/\s+/)[0] # # Save the port # @port = nil - if line =~ /on\s+([0-9]+)/ + if line =~ /on\s+([0-9]+)/ @port = $1.dup end - if line =~ /on\s+port\s+([0-9]+)/ + if line =~ /on\s+port\s+([0-9]+)/ @port = $1.dup end # # Save the optional banner. # - if line =~ /with\s+banner\s+'([^']+)'/ + if line =~ /with\s+banner\s+'([^']+)'/ @banner = $1.dup else @banner = nil @@ -88,7 +88,7 @@ module Custodian @error = nil - if @port.nil? + if @port.nil? raise ArgumentError, 'Missing port to test against' end end @@ -153,7 +153,7 @@ module Custodian # begin x = IPAddr.new(host) - if x.ipv4? or x.ipv6? + if x.ipv4? or x.ipv6? ips.push(host) end rescue ArgumentError @@ -171,10 +171,10 @@ module Custodian # # Allow the test to disable one/both # - if @line =~ /ipv4_only/ + if @line =~ /ipv4_only/ do_ipv6 = false end - if @line =~ /ipv6_only/ + if @line =~ /ipv6_only/ do_ipv4 = false end @@ -188,11 +188,11 @@ module Custodian Resolv::DNS.open do |dns| - if do_ipv4 + if do_ipv4 ress = dns.getresources(host, Resolv::DNS::Resource::IN::A) ress.map { |r| ips.push(r.address.to_s) } end - if do_ipv6 + if do_ipv6 ress = dns.getresources(host, Resolv::DNS::Resource::IN::AAAA) ress.map { |r| ips.push(r.address.to_s) } end @@ -207,7 +207,7 @@ module Custodian # # Did we fail to perform a DNS lookup? # - if ips.empty? + if ips.empty? @error = "#{@host} failed to resolve to either IPv4 or IPv6" return Custodian::TestResult::TEST_FAILED end @@ -219,7 +219,7 @@ module Custodian # were given. # ips.each do |ip| - if !run_test_internal_real(ip, port, banner, do_read) + if !run_test_internal_real(ip, port, banner, do_read) return Custodian::TestResult::TEST_FAILED # @@ -262,32 +262,32 @@ module Custodian # read a banner from the remote server, if we're supposed to. read = nil - read = socket.sysread(1024) if do_read + read = socket.sysread(1024) if do_read # trim to a sane length & strip newlines. - if !read.nil? + if !read.nil? read = read[0, 255] read.gsub!(/[\n\r]/, '') end socket.close - if banner.nil? + if banner.nil? @error = nil return true else # test for banner # regexp. - if banner.kind_of? Regexp - if (!read.nil?) && (banner.match(read)) + if banner.kind_of? Regexp + if (!read.nil?) && (banner.match(read)) return true end end # string. - if banner.kind_of? String - if (!read.nil?) && (read =~ /#{banner}/i) + if banner.kind_of? String + if (!read.nil?) && (read =~ /#{banner}/i) return true end end diff --git a/lib/custodian/protocoltest/telnet.rb b/lib/custodian/protocoltest/telnet.rb index 032117d..d26c0b3 100644 --- a/lib/custodian/protocoltest/telnet.rb +++ b/lib/custodian/protocoltest/telnet.rb @@ -32,12 +32,12 @@ module Custodian # # Save the host # - @host = line.split(/\s+/)[0] + @host = line.split(/\s+/)[0] # # Save the port # - if line =~ /on\s+([0-9]+)/ + if line =~ /on\s+([0-9]+)/ @port = $1.dup else @port = 23 diff --git a/lib/custodian/protocoltest/tftp.rb b/lib/custodian/protocoltest/tftp.rb index 596a204..9b263fe 100644 --- a/lib/custodian/protocoltest/tftp.rb +++ b/lib/custodian/protocoltest/tftp.rb @@ -75,14 +75,14 @@ module Custodian @file = u.path # Port might not be specified, if it is missing then default to 69. - @port = u.port || "69" + @port = u.port || '69' @port = @port.to_i # # Ensure there is a file to fetch # if @file.nil? || @file.empty? - raise ArgumentError, "Missing file name" + raise ArgumentError, 'Missing file name' end end -- cgit v1.2.1