diff --git a/.rubocop.yml b/.rubocop.yml index af28bb45b..5ae463f23 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -18,6 +18,9 @@ Layout/ParameterAlignment: Layout/DotPosition: Enabled: false +Layout/EmptyLineAfterGuardClause: + Enabled: false + Layout/FirstArgumentIndentation: EnforcedStyle: consistent @@ -115,6 +118,10 @@ Style/PreferredHashMethods: Style/StringLiterals: Enabled: false +Style/SymbolArray: + EnforcedStyle: brackets + MinSize: 1 + Style/TernaryParentheses: EnforcedStyle: require_parentheses_when_complex diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index fad4cc457..e407c87d3 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -13,37 +13,6 @@ Layout/CaseIndentation: Enabled: false -# Offense count: 123 -# Cop supports --auto-correct. -Layout/EmptyLineAfterGuardClause: - Enabled: false - -# Offense count: 7 -# Cop supports --auto-correct. -Layout/EmptyLinesAroundArguments: - Enabled: false - -# Offense count: 2 -# Cop supports --auto-correct. -# Configuration parameters: IndentationWidth. -# SupportedStyles: special_inside_parentheses, consistent, align_brackets -Layout/FirstArrayElementIndentation: - EnforcedStyle: consistent - -# Offense count: 12 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle, IndentationWidth. -# SupportedStyles: special_inside_parentheses, consistent, align_braces -Layout/FirstHashElementIndentation: - Enabled: false - -# Offense count: 11 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle. -# SupportedStyles: symmetrical, new_line, same_line -Layout/MultilineArrayBraceLayout: - Enabled: false - # Offense count: 2 # Cop supports --auto-correct. # Configuration parameters: EnforcedStyle. @@ -65,28 +34,6 @@ Layout/MultilineMethodCallBraceLayout: Layout/MultilineOperationIndentation: Enabled: false -# Offense count: 45 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle. -# SupportedStyles: space, no_space -Layout/SpaceAroundEqualsInParameterDefault: - Enabled: false - -# Offense count: 136 -# Cop supports --auto-correct. -# Configuration parameters: AllowForAlignment, EnforcedStyleForExponentOperator. -# SupportedStylesForExponentOperator: space, no_space -Layout/SpaceAroundOperators: - Enabled: false - -# Offense count: 20 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle, EnforcedStyleForEmptyBrackets. -# SupportedStyles: space, no_space, compact -# SupportedStylesForEmptyBrackets: space, no_space -Layout/SpaceInsideArrayLiteralBrackets: - Enabled: false - # Offense count: 419 # Cop supports --auto-correct. # Configuration parameters: EnforcedStyle, EnforcedStyleForEmptyBraces. @@ -193,18 +140,6 @@ Style/ClassAndModuleChildren: Style/ClassVars: Enabled: false -# Offense count: 6 -# Cop supports --auto-correct. -Style/ColonMethodCall: - Enabled: false - -# Offense count: 1 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle, AllowInnerBackticks. -# SupportedStyles: backticks, percent_x, mixed -Style/CommandLiteral: - Enabled: false - # Offense count: 1 # Cop supports --auto-correct. # Configuration parameters: Keywords. @@ -216,27 +151,10 @@ Style/CommentAnnotation: Style/DoubleNegation: Enabled: false -# Offense count: 6 -# Cop supports --auto-correct. -Style/EmptyLiteral: - Enabled: false - -# Offense count: 6 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle. -# SupportedStyles: compact, expanded -Style/EmptyMethod: - Enabled: false - # Offense count: 1 Style/EvalWithLocation: Enabled: false -# Offense count: 34 -# Cop supports --auto-correct. -Style/ExpandPathArguments: - Enabled: false - # Offense count: 18 # Cop supports --auto-correct. # Configuration parameters: EnforcedStyle. @@ -335,11 +253,6 @@ Style/RandomWithOffset: Style/RedundantPercentQ: Enabled: false -# Offense count: 9 -# Cop supports --auto-correct. -Style/RedundantSelf: - Enabled: false - # Offense count: 6 # Cop supports --auto-correct. # Configuration parameters: EnforcedStyle, AllowInnerSlashes. @@ -366,13 +279,6 @@ Style/RescueStandardError: Style/SignalException: Enabled: false -# Offense count: 50 -# Cop supports --auto-correct. -# Configuration parameters: MinSize. -# SupportedStyles: percent, brackets -Style/SymbolArray: - EnforcedStyle: brackets - # Offense count: 9 # Cop supports --auto-correct. # Configuration parameters: AllowNamedUnderscoreVariables. diff --git a/Gemfile b/Gemfile index 1e5fc8887..3162158ba 100644 --- a/Gemfile +++ b/Gemfile @@ -5,5 +5,5 @@ gemspec gem 'concurrent-ruby', '~> 1.0', require: 'concurrent' Dir["#{File.dirname(__FILE__)}/bundler.d/*.rb"].each do |bundle| - self.instance_eval(Bundler.read_file(bundle)) + instance_eval(Bundler.read_file(bundle)) end diff --git a/bin/smart-proxy b/bin/smart-proxy index 1abdb1eb1..78e6c6282 100755 --- a/bin/smart-proxy +++ b/bin/smart-proxy @@ -1,6 +1,6 @@ #!/usr/bin/env ruby -$LOAD_PATH.unshift(*Dir[File.expand_path("../../lib", __FILE__), File.expand_path("../../modules", __FILE__)]) +$LOAD_PATH.unshift(*Dir[File.expand_path('../lib', __dir__), File.expand_path('../modules', __dir__)]) require 'smart_proxy_main' Proxy::Launcher.new.launch diff --git a/config.ru b/config.ru index 13ebffebe..691ab4671 100644 --- a/config.ru +++ b/config.ru @@ -1,4 +1,4 @@ -$LOAD_PATH.unshift *Dir[File.expand_path("../lib", __FILE__), File.expand_path("../modules", __FILE__)] +$LOAD_PATH.unshift *Dir[File.expand_path('lib', __dir__), File.expand_path('modules', __dir__)] require 'smart_proxy_main' ::Proxy::PluginInitializer.new(::Proxy::Plugins.instance).initialize_plugins diff --git a/extra/changelog b/extra/changelog index 379f280b2..469a2c997 100755 --- a/extra/changelog +++ b/extra/changelog @@ -1,6 +1,6 @@ #!/usr/bin/env ruby -cmd=`git log --pretty='format:%ci___%an <%ae>___%s'` +cmd = `git log --pretty='format:%ci___%an <%ae>___%s'` list = {} list_order = [] diff --git a/extra/dhcpd_config_check.rb b/extra/dhcpd_config_check.rb index 7c7d2e07e..0ecb9b9c7 100644 --- a/extra/dhcpd_config_check.rb +++ b/extra/dhcpd_config_check.rb @@ -1,4 +1,4 @@ -$LOAD_PATH.unshift(*Dir[File.expand_path("../../modules", __FILE__)]) +$LOAD_PATH.unshift(*Dir[File.expand_path('../modules', __dir__)]) require 'English' require 'optparse' diff --git a/extra/migrations/20150327000000_migrate_monolithic_config.rb b/extra/migrations/20150327000000_migrate_monolithic_config.rb index 6b74c5b1d..0049a3f3f 100644 --- a/extra/migrations/20150327000000_migrate_monolithic_config.rb +++ b/extra/migrations/20150327000000_migrate_monolithic_config.rb @@ -21,34 +21,34 @@ def migrate end def modules - [ :settings, :tftp, :dns, :dhcp, :puppet, :puppetca, :bmc, :chef, :realm ] + [:settings, :tftp, :dns, :dhcp, :puppet, :puppetca, :bmc, :chef, :realm] end def known_options { - :daemon => :settings, - :daemon_pid => :settings, - :log_file => :settings, - :log_level => :settings, - :port => :settings, - :ssl_ca_file => :settings, - :ssl_certificate => :settings, - :ssl_private_key => :settings, - :trusted_hosts => :settings, - :virsh_network => :settings, - :foreman_url => :settings, - :settings_directory => :settings, - :http_port => :settings, - :https_port => :settings, - :use_cache => :settings, - :cache_location => :settings, - :puppetca_use_sudo => :puppetca, - :puppetdir => :puppetca, - :ssldir => :puppetca, - :sudo_command => :puppetca, - :customrun_args => :puppet, - :customrun_cmd => :puppet, - :freeipa_remove_dns => :realm, + :daemon => :settings, + :daemon_pid => :settings, + :log_file => :settings, + :log_level => :settings, + :port => :settings, + :ssl_ca_file => :settings, + :ssl_certificate => :settings, + :ssl_private_key => :settings, + :trusted_hosts => :settings, + :virsh_network => :settings, + :foreman_url => :settings, + :settings_directory => :settings, + :http_port => :settings, + :https_port => :settings, + :use_cache => :settings, + :cache_location => :settings, + :puppetca_use_sudo => :puppetca, + :puppetdir => :puppetca, + :ssldir => :puppetca, + :sudo_command => :puppetca, + :customrun_args => :puppet, + :customrun_cmd => :puppet, + :freeipa_remove_dns => :realm, } end diff --git a/extra/migrations/20150611000000_migrate_dns_settings.rb b/extra/migrations/20150611000000_migrate_dns_settings.rb index 57663b27f..16ee5104d 100644 --- a/extra/migrations/20150611000000_migrate_dns_settings.rb +++ b/extra/migrations/20150611000000_migrate_dns_settings.rb @@ -16,18 +16,18 @@ def migrate def known_dns_options { - :enabled => [:dns], - :dns_provider => [:dns], - :dns_key => [:dns_nsupdate], - :dns_server => [:dns_nsupdate, :dns_nsupdate_gss, :dns_dnscmd], - :dns_ttl => [:dns], - :dns_tsig_keytab => [:dns_nsupdate_gss], - :dns_tsig_principal => [:dns_nsupdate_gss], + :enabled => [:dns], + :dns_provider => [:dns], + :dns_key => [:dns_nsupdate], + :dns_server => [:dns_nsupdate, :dns_nsupdate_gss, :dns_dnscmd], + :dns_ttl => [:dns], + :dns_tsig_keytab => [:dns_nsupdate_gss], + :dns_tsig_principal => [:dns_nsupdate_gss], } end def migrate_dns_configuration(data) - output = Hash.new { |h, k| h[k] = Hash.new } + output = Hash.new { |h, k| h[k] = {} } data.each do |option, value| if known_dns_options.include? option diff --git a/extra/migrations/20150826000000_migrate_dhcp_settings.rb b/extra/migrations/20150826000000_migrate_dhcp_settings.rb index f82016db6..f8b2020bb 100644 --- a/extra/migrations/20150826000000_migrate_dhcp_settings.rb +++ b/extra/migrations/20150826000000_migrate_dhcp_settings.rb @@ -2,15 +2,15 @@ class MigrateDhcpSettings < ::Proxy::Migration KNOWN_PARAMETERS = { - :enabled => [:dhcp, :enabled], - :dhcp_vendor => [:dhcp, :use_provider, :old_provider_name_to_new], - :dhcp_subnets => [:dhcp, :subnets], - :dhcp_config => [:dhcp_isc, :config], - :dhcp_leases => [:dhcp_isc, :leases], - :dhcp_key_name => [:dhcp_isc, :key_name], - :dhcp_key_secret => [:dhcp_isc, :key_secret], - :dhcp_omapi_port => [:dhcp_isc, :omapi_port], - :dhcp_server => [:dhcp, :server], + :enabled => [:dhcp, :enabled], + :dhcp_vendor => [:dhcp, :use_provider, :old_provider_name_to_new], + :dhcp_subnets => [:dhcp, :subnets], + :dhcp_config => [:dhcp_isc, :config], + :dhcp_leases => [:dhcp_isc, :leases], + :dhcp_key_name => [:dhcp_isc, :key_name], + :dhcp_key_secret => [:dhcp_isc, :key_secret], + :dhcp_omapi_port => [:dhcp_isc, :omapi_port], + :dhcp_server => [:dhcp, :server], } def remap_parameter(aparameter, avalue) @@ -42,7 +42,7 @@ def old_provider_name_to_new(aname) end def migrate_dhcp_configuration(to_migrate) - migrated = Hash.new { |h, k| h[k] = Hash.new } + migrated = Hash.new { |h, k| h[k] = {} } to_migrate.each do |option, value| module_name, parameter_name, parameter_value = remap_parameter(option, value) migrated[module_name][parameter_name] = parameter_value diff --git a/extra/migrations/20160413000000_migrate_puppet_settings.rb b/extra/migrations/20160413000000_migrate_puppet_settings.rb index d25a520d0..dd9c767bf 100644 --- a/extra/migrations/20160413000000_migrate_puppet_settings.rb +++ b/extra/migrations/20160413000000_migrate_puppet_settings.rb @@ -2,22 +2,22 @@ class MigratePuppetSettings < ::Proxy::Migration KNOWN_PARAMETERS = { - :enabled => [:puppet, :enabled], - :puppet_provider => [:puppet, :use_provider], - :puppet_user => [:puppet_proxy_puppetrun, :puppet_proxy_mcollective, :puppet_user], - :salt_puppetrun_cmd => [:puppet_proxy_salt, :command], - :customrun_cmd => [:puppet_proxy_customrun, :command], - :customrun_args => [:puppet_proxy_customrun, :command_arguments], - :puppet_url => [:puppet_proxy_puppet_api, :puppet_url], - :puppet_ssl_ca => [:puppet_proxy_puppet_api, :puppet_ssl_ca], - :puppet_ssl_cert => [:puppet_proxy_puppet_api, :puppet_ssl_cert], - :puppet_ssl_key => [:puppet_proxy_puppet_api, :puppet_ssl_key], - :puppetssh_sudo => [:puppet_proxy_ssh, :use_sudo], - :puppetssh_command => [:puppet_proxy_ssh, :command], - :puppetssh_wait => [:puppet_proxy_ssh, :wait], - :puppetssh_user => [:puppet_proxy_ssh, :user], - :puppetssh_keyfile => [:puppet_proxy_ssh, :keyfile], - :mcollective_user => [:puppet_proxy_mcollective, :user], + :enabled => [:puppet, :enabled], + :puppet_provider => [:puppet, :use_provider], + :puppet_user => [:puppet_proxy_puppetrun, :puppet_proxy_mcollective, :puppet_user], + :salt_puppetrun_cmd => [:puppet_proxy_salt, :command], + :customrun_cmd => [:puppet_proxy_customrun, :command], + :customrun_args => [:puppet_proxy_customrun, :command_arguments], + :puppet_url => [:puppet_proxy_puppet_api, :puppet_url], + :puppet_ssl_ca => [:puppet_proxy_puppet_api, :puppet_ssl_ca], + :puppet_ssl_cert => [:puppet_proxy_puppet_api, :puppet_ssl_cert], + :puppet_ssl_key => [:puppet_proxy_puppet_api, :puppet_ssl_key], + :puppetssh_sudo => [:puppet_proxy_ssh, :use_sudo], + :puppetssh_command => [:puppet_proxy_ssh, :command], + :puppetssh_wait => [:puppet_proxy_ssh, :wait], + :puppetssh_user => [:puppet_proxy_ssh, :user], + :puppetssh_keyfile => [:puppet_proxy_ssh, :keyfile], + :mcollective_user => [:puppet_proxy_mcollective, :user], } def migrate @@ -52,7 +52,7 @@ def old_provider_name_to_new(aname) end def migrate_puppet_configuration(to_migrate) - migrated = Hash.new { |h, k| h[k] = Hash.new } + migrated = Hash.new { |h, k| h[k] = {} } to_migrate.each do |option, value| remap_parameter(option, value).each { |module_name, parameter_name, parameter_value| migrated[module_name][parameter_name] = parameter_value } end diff --git a/extra/migrations/20161209000000_migrate_realm_settings.rb b/extra/migrations/20161209000000_migrate_realm_settings.rb index 31ef03b78..8a1ba62af 100644 --- a/extra/migrations/20161209000000_migrate_realm_settings.rb +++ b/extra/migrations/20161209000000_migrate_realm_settings.rb @@ -2,11 +2,11 @@ class MigrateRealmSettings < ::Proxy::Migration KNOWN_PARAMETERS = { - :enabled => [:realm, :enabled], - :realm_provider => [:realm, :use_provider], - :realm_keytab => [:realm_freeipa, :keytab_path], - :realm_principal => [:realm_freeipa, :principal], - :freeipa_remove_dns => [:realm_freeipa, :remove_dns], + :enabled => [:realm, :enabled], + :realm_provider => [:realm, :use_provider], + :realm_keytab => [:realm_freeipa, :keytab_path], + :realm_principal => [:realm_freeipa, :principal], + :freeipa_remove_dns => [:realm_freeipa, :remove_dns], } def migrate @@ -29,7 +29,7 @@ def remap_parameter(aparameter, avalue) end def migrate_realm_configuration(to_migrate) - migrated = Hash.new { |h, k| h[k] = Hash.new } + migrated = Hash.new { |h, k| h[k] = {} } to_migrate.each do |option, value| module_name, parameter_name, parameter_value = remap_parameter(option, value) migrated[module_name][parameter_name] = parameter_value diff --git a/extra/migrations/20170523000000_migrate_autosign_setting.rb b/extra/migrations/20170523000000_migrate_autosign_setting.rb index 3451f4272..b09ca4e3b 100644 --- a/extra/migrations/20170523000000_migrate_autosign_setting.rb +++ b/extra/migrations/20170523000000_migrate_autosign_setting.rb @@ -29,7 +29,7 @@ def remap_parameter(aparameter, avalue) end def migrate_autosign_configuration(to_migrate) - migrated = Hash.new { |h, k| h[k] = Hash.new } + migrated = Hash.new { |h, k| h[k] = {} } to_migrate.each do |option, value| module_name, parameter_name, parameter_value = remap_parameter(option, value) migrated[module_name][parameter_name] = parameter_value diff --git a/extra/query.rb b/extra/query.rb index b3eec258a..9511ebfe2 100755 --- a/extra/query.rb +++ b/extra/query.rb @@ -35,13 +35,13 @@ require 'rdoc/usage' require 'pathname' -opts = GetoptLong.new([ '--verbose', '-v', GetoptLong::NO_ARGUMENT ], - [ '--help', '-h', GetoptLong::NO_ARGUMENT ], - [ '--key', GetoptLong::REQUIRED_ARGUMENT ], - [ '--cert', GetoptLong::REQUIRED_ARGUMENT ], - [ '--ca', GetoptLong::REQUIRED_ARGUMENT ], - [ '--verb', GetoptLong::REQUIRED_ARGUMENT ], - [ '--json', GetoptLong::NO_ARGUMENT ] +opts = GetoptLong.new(['--verbose', '-v', GetoptLong::NO_ARGUMENT], + ['--help', '-h', GetoptLong::NO_ARGUMENT], + ['--key', GetoptLong::REQUIRED_ARGUMENT], + ['--cert', GetoptLong::REQUIRED_ARGUMENT], + ['--ca', GetoptLong::REQUIRED_ARGUMENT], + ['--verb', GetoptLong::REQUIRED_ARGUMENT], + ['--json', GetoptLong::NO_ARGUMENT] ) json = false verb = :get @@ -49,7 +49,7 @@ opts.each do |opt, arg| case opt when '--help' - RDoc::usage + RDoc.usage when '--key' key = arg when '--cert' @@ -72,8 +72,8 @@ cert ||= origin.join "signed.pem" ca ||= origin.join "ca.pem" else - hostfile = %x{hostname -f}.chomp + ".pem" - key ||= "/var/lib/puppet/ssl/private_keys/" + hostfile + hostfile = `hostname -f`.chomp + ".pem" + key ||= "/var/lib/puppet/ssl/private_keys/" + hostfile cert ||= "/var/lib/puppet/ssl/certs/" + hostfile ca ||= "/var/lib/puppet/ssl/certs/ca.pem" end diff --git a/lib/bundler_helper.rb b/lib/bundler_helper.rb index 3a4bf15a4..0ab198865 100644 --- a/lib/bundler_helper.rb +++ b/lib/bundler_helper.rb @@ -1,7 +1,7 @@ module Proxy class BundlerHelper def self.require_groups(*groups) - if File.exist?(File.expand_path('../../Gemfile.in', __FILE__)) + if File.exist?(File.expand_path('../Gemfile.in', __dir__)) # If there is a Gemfile.in file, we will not use Bundler but BundlerExt # gem which parses this file and loads all dependencies from the system # rathern then trying to download them from rubygems.org. It always @@ -19,7 +19,7 @@ def self.require_groups(*groups) exit 1 end end - BundlerExt.system_require(File.expand_path('../../Gemfile.in', __FILE__), *groups) + BundlerExt.system_require(File.expand_path('../Gemfile.in', __dir__), *groups) else require 'bundler' unless defined?(Bundler) Bundler.require(*groups) diff --git a/lib/proxy/file_lock.rb b/lib/proxy/file_lock.rb index ed9eeb7ab..cc2891825 100644 --- a/lib/proxy/file_lock.rb +++ b/lib/proxy/file_lock.rb @@ -2,7 +2,7 @@ module Proxy module FileLock class << self def try_locking(afile) - f = File.open(afile, File::RDWR|File::CREAT, 0644) + f = File.open(afile, File::RDWR | File::CREAT, 0644) return f if f.flock(File::LOCK_EX | File::LOCK_NB) == 0 f.close nil diff --git a/lib/proxy/helpers.rb b/lib/proxy/helpers.rb index 65c3a40b4..7f7d6038b 100644 --- a/lib/proxy/helpers.rb +++ b/lib/proxy/helpers.rb @@ -7,7 +7,7 @@ module Proxy::Helpers # Accepts a html error code and a message, which is then returned to the caller after adding to the proxy log # OR a block which is executed and its errors handled in a similar way. # If no code is supplied when the block is declared then the html error used is 400. - def log_halt(code=nil, exception_or_msg=nil, custom_msg=nil) + def log_halt(code = nil, exception_or_msg = nil, custom_msg = nil) message = exception_or_msg.to_s message = "#{custom_msg}: #{message}" if custom_msg exception = exception_or_msg.is_a?(Exception) ? exception_or_msg : Exception.new(exception_or_msg) @@ -79,7 +79,7 @@ def resolv(*args) end # reverse lookup an IP address while verifying it via forward resolv - def remote_fqdn(forward_verify=true) + def remote_fqdn(forward_verify = true) ip = request.env['REMOTE_ADDR'] log_halt 403, 'could not get remote address from environment' if ip.empty? diff --git a/lib/proxy/log_buffer/decorator.rb b/lib/proxy/log_buffer/decorator.rb index 0debf874e..f0e30199e 100644 --- a/lib/proxy/log_buffer/decorator.rb +++ b/lib/proxy/log_buffer/decorator.rb @@ -30,7 +30,7 @@ def add(severity, message = nil, progname = nil, exception_or_backtrace = nil) return if message == '' reopened = false @mutex.synchronize do - if self.roll_log? + if roll_log? # decorator is in-memory only, reopen underlaying logging appenders ::Logging.reopen self.roll_log = false @@ -54,7 +54,7 @@ def add(severity, message = nil, progname = nil, exception_or_backtrace = nil) end info("Logging file reopened via USR1 signal") if reopened # exceptions are also sent to structured log if available - self.exception("Error details for #{message}", exception_or_backtrace) if exception_or_backtrace&.is_a?(Exception) + exception("Error details for #{message}", exception_or_backtrace) if exception_or_backtrace&.is_a?(Exception) end def trace? diff --git a/lib/proxy/pluggable.rb b/lib/proxy/pluggable.rb index 4965c41b1..4bd6060ab 100644 --- a/lib/proxy/pluggable.rb +++ b/lib/proxy/pluggable.rb @@ -8,7 +8,7 @@ def after_activation(&blk) end def requires(plugin_name, version_spec) - self.dependencies << ::Proxy::Dependency.new(plugin_name, cleanup_version(version_spec)) + dependencies << ::Proxy::Dependency.new(plugin_name, cleanup_version(version_spec)) end def bundler_group(name) diff --git a/lib/proxy/plugins.rb b/lib/proxy/plugins.rb index 369d3aaa5..ce7655e85 100644 --- a/lib/proxy/plugins.rb +++ b/lib/proxy/plugins.rb @@ -65,7 +65,7 @@ def plugin_enabled?(plugin_name) end def self.disable_plugin(plugin_name) - self.instance.disable_plugin(plugin_name) + instance.disable_plugin(plugin_name) end def disable_plugin(plugin_name) diff --git a/lib/proxy/request.rb b/lib/proxy/request.rb index d59caa33c..b70259dba 100644 --- a/lib/proxy/request.rb +++ b/lib/proxy/request.rb @@ -9,11 +9,11 @@ def initialize(base_uri) @base_uri = base_uri end - def query_string(input={}) + def query_string(input = {}) input.compact.map { |k, v| "#{CGI.escape(k.to_s)}=#{CGI.escape(v)}" }.join("&") end - def create_get(path, query={}, headers={}) + def create_get(path, query = {}, headers = {}) uri = uri(path) req = Net::HTTP::Get.new("#{uri.path || '/'}?#{query_string(query)}") req = add_headers(req, headers) @@ -24,7 +24,7 @@ def uri(path) URI.join(@base_uri.to_s, path) end - def add_headers(req, headers={}) + def add_headers(req, headers = {}) req.add_field('Accept', 'application/json,version=2') req.content_type = headers["Content-Type"] || 'application/json' headers.each do |k, v| @@ -33,7 +33,7 @@ def add_headers(req, headers={}) req end - def create_post(path, body, headers={}, query={}) + def create_post(path, body, headers = {}, query = {}) uri = uri(path) uri.query = query_string(query) req = Net::HTTP::Post.new(uri) diff --git a/lib/proxy/util.rb b/lib/proxy/util.rb index 3c6a66a1e..f5d4c4afd 100644 --- a/lib/proxy/util.rb +++ b/lib/proxy/util.rb @@ -20,7 +20,7 @@ def start(&ensured_block) logger.debug "Starting task: #{@command}" @task = Thread.new(@command) do |cmd| status = nil - Open3::popen3(cmd) do |stdin, stdout, stderr, thr| + Open3.popen3(cmd) do |stdin, stdout, stderr, thr| stdout.each do |line| logger.debug "[#{thr.pid}] #{line}" end diff --git a/lib/sinatra/authorization.rb b/lib/sinatra/authorization.rb index c71119305..7be503e8c 100644 --- a/lib/sinatra/authorization.rb +++ b/lib/sinatra/authorization.rb @@ -32,7 +32,7 @@ def do_authorize_with_trusted_hosts if trusted_hosts logger.debug "verifying remote client #{request.env['REMOTE_ADDR']} against trusted_hosts #{trusted_hosts}" - if [ 'yes', 'on', 1 ].include? request.env['HTTPS'].to_s + if ['yes', 'on', 1].include? request.env['HTTPS'].to_s fqdn = https_cert_cn else fqdn = remote_fqdn(Proxy::SETTINGS.forward_verify) diff --git a/modules/bmc/base.rb b/modules/bmc/base.rb index 4180212fd..77c3b1869 100644 --- a/modules/bmc/base.rb +++ b/modules/bmc/base.rb @@ -6,7 +6,7 @@ def initialize(args) @host = connect(args) end - def poweroff(soft=false) + def poweroff(soft = false) raise NotImplementedError.new end @@ -54,7 +54,7 @@ def bootdevices raise NotImplementedError.new end - def bootdevice=(args={ :device => nil, :reboot => false, :persistent => false }) + def bootdevice=(args = { :device => nil, :reboot => false, :persistent => false }) raise NotImplementedError.new end @@ -66,19 +66,19 @@ def identifyoff raise NotImplementedError.new end - def bootpxe(reboot=false, persistent=false) + def bootpxe(reboot = false, persistent = false) raise NotImplementedError.new end - def bootdisk(reboot=false, persistent=false) + def bootdisk(reboot = false, persistent = false) raise NotImplementedError.new end - def bootbios(reboot=false, persistent=false) + def bootbios(reboot = false, persistent = false) raise NotImplementedError.new end - def bootcdrom(reboot=false, persistent=false) + def bootcdrom(reboot = false, persistent = false) raise NotImplementedError.new end diff --git a/modules/bmc/bmc_api.rb b/modules/bmc/bmc_api.rb index ea1dcaf42..817d29cd0 100644 --- a/modules/bmc/bmc_api.rb +++ b/modules/bmc/bmc_api.rb @@ -409,8 +409,13 @@ def bmc_setup # of using smart-proxy. Its simply a tunnel to pass credentials through, # since we are essentially remotely executing ipmi commands using Rubyipmi. - args = { :host => params[:host], :username => username, :options => body_parameters['options'], - :password => password, :bmc_provider => provider_type } + args = { + :host => params[:host], + :username => username, + :options => body_parameters['options'], + :password => password, + :bmc_provider => provider_type, + } @bmc = Proxy::BMC::IPMI.new(args) when "shell" require 'bmc/shell' diff --git a/modules/bmc/bmc_plugin.rb b/modules/bmc/bmc_plugin.rb index 14f041822..8df040ba8 100644 --- a/modules/bmc/bmc_plugin.rb +++ b/modules/bmc/bmc_plugin.rb @@ -1,7 +1,7 @@ module Proxy::BMC class Plugin < Proxy::Plugin - http_rackup_path File.expand_path("http_config.ru", File.expand_path("../", __FILE__)) - https_rackup_path File.expand_path("http_config.ru", File.expand_path("../", __FILE__)) + http_rackup_path File.expand_path("http_config.ru", File.expand_path(__dir__)) + https_rackup_path File.expand_path("http_config.ru", File.expand_path(__dir__)) plugin :bmc, ::Proxy::VERSION end diff --git a/modules/bmc/ipmi.rb b/modules/bmc/ipmi.rb index fba8f2aaf..36421de08 100644 --- a/modules/bmc/ipmi.rb +++ b/modules/bmc/ipmi.rb @@ -35,7 +35,7 @@ def self.providers # Turn the ipmi device off, if its already off then nothing will happen # If soft=true then the ipmi will perform a graceful shutdown - def poweroff(soft=false) + def poweroff(soft = false) if soft host.chassis.power.softShutdown else @@ -66,7 +66,7 @@ def bootdevice host.chassis.config.bootdevice end - def bootdevice=(args={ :device => nil, :reboot => false, :persistent => false }) + def bootdevice=(args = { :device => nil, :reboot => false, :persistent => false }) host.chassis.bootdevice(args[:device], args[:reboot], args[:persistent]) end @@ -115,22 +115,22 @@ def identifystatus end # Boot to pxe - def bootpxe(reboot=false, persistent=false) + def bootpxe(reboot = false, persistent = false) host.chassis.bootpxe(reboot, persistent) end # boot to disk - def bootdisk(reboot=false, persistent=false) + def bootdisk(reboot = false, persistent = false) host.chassis.bootdisk(reboot, persistent) end # boot to bios - def bootbios(reboot=false, persistent=false) + def bootbios(reboot = false, persistent = false) host.chassis.bootbios(reboot, persistent) end # boot to cdrom - def bootcdrom(reboot=false, persistent=false) + def bootcdrom(reboot = false, persistent = false) host.chassis.bootcdrom(reboot, persistent) end @@ -194,7 +194,7 @@ def version end # BMC reset - def reset(type='cold') + def reset(type = 'cold') host.bmc.reset(type) end diff --git a/modules/bmc/ssh.rb b/modules/bmc/ssh.rb index dc7c0fce8..8468a92b1 100644 --- a/modules/bmc/ssh.rb +++ b/modules/bmc/ssh.rb @@ -79,16 +79,16 @@ def netmask '' end - def bootpxe(reboot=false, persistent=false) + def bootpxe(reboot = false, persistent = false) end - def bootdisk(reboot=false, persistent=false) + def bootdisk(reboot = false, persistent = false) end - def bootbios(reboot=false, persistent=false) + def bootbios(reboot = false, persistent = false) end - def bootcdrom(reboot=false, persistent=false) + def bootcdrom(reboot = false, persistent = false) end end end diff --git a/modules/dhcp/dhcp_plugin.rb b/modules/dhcp/dhcp_plugin.rb index 85ed113d6..3bd285542 100644 --- a/modules/dhcp/dhcp_plugin.rb +++ b/modules/dhcp/dhcp_plugin.rb @@ -1,6 +1,6 @@ class Proxy::DhcpPlugin < ::Proxy::Plugin - http_rackup_path File.expand_path("http_config.ru", File.expand_path("../", __FILE__)) - https_rackup_path File.expand_path("http_config.ru", File.expand_path("../", __FILE__)) + http_rackup_path File.expand_path("http_config.ru", File.expand_path(__dir__)) + https_rackup_path File.expand_path("http_config.ru", File.expand_path(__dir__)) uses_provider default_settings :use_provider => 'dhcp_isc', :server => '127.0.0.1', :subnets => [], :ping_free_ip => true diff --git a/modules/dhcp_common/dhcp_common.rb b/modules/dhcp_common/dhcp_common.rb index 76d9c1369..07eee9986 100644 --- a/modules/dhcp_common/dhcp_common.rb +++ b/modules/dhcp_common/dhcp_common.rb @@ -35,7 +35,7 @@ def self.ipv4_to_i(ipv4_address) def self.i_to_ipv4(ipv4_as_i) octets = [3, 2, 1, 0].each_with_object([]) do |i, all| - all.push((ipv4_as_i >> i*8) & 0xff) + all.push((ipv4_as_i >> i * 8) & 0xff) end octets.join(".") end diff --git a/modules/dhcp_common/free_ips.rb b/modules/dhcp_common/free_ips.rb index 4b1db85f8..5a0b8e299 100644 --- a/modules/dhcp_common/free_ips.rb +++ b/modules/dhcp_common/free_ips.rb @@ -11,7 +11,7 @@ class FreeIps attr_reader :allocated_ips, :allocation_timestamps, :blacklist_interval, :m - def initialize(blacklist_interval = 30*60) + def initialize(blacklist_interval = 30 * 60) @blacklist_interval = blacklist_interval @allocated_ips = Set.new @allocation_timestamps = [] diff --git a/modules/dhcp_common/isc/configuration_parser.rb b/modules/dhcp_common/isc/configuration_parser.rb index 8aa6b8067..90a65a2d8 100644 --- a/modules/dhcp_common/isc/configuration_parser.rb +++ b/modules/dhcp_common/isc/configuration_parser.rb @@ -150,7 +150,8 @@ def visit(_, _, _, parent) end class CommentNode < Struct.new :comment - def visit(_, _, _, _); end + def visit(_, _, _, _) + end end class KeyValueNode < Struct.new :key, :value diff --git a/modules/dhcp_common/isc/omapi_provider.rb b/modules/dhcp_common/isc/omapi_provider.rb index 6d3553639..53156f20a 100644 --- a/modules/dhcp_common/isc/omapi_provider.rb +++ b/modules/dhcp_common/isc/omapi_provider.rb @@ -88,7 +88,7 @@ def format_omshell_output(output) output.map { |x| "omshell= #{x.chomp}" }.join("\n") end - def report(msg, response="") + def report(msg, response = "") logger.debug(format_omshell_output(response)) if response.nil? || (!response.empty? && !response.grep(/can't|no more|not connected|Syntax error/).empty?) logger.error "Omshell failed: " + (response.nil? ? "Problem launching omshell" : format_omshell_output(response)) diff --git a/modules/dhcp_common/record.rb b/modules/dhcp_common/record.rb index d3d2720cb..f70beb36f 100644 --- a/modules/dhcp_common/record.rb +++ b/modules/dhcp_common/record.rb @@ -36,7 +36,7 @@ def deleteable? end def <=>(other) - self.ip <=> other.ip + ip <=> other.ip end def eql?(other) diff --git a/modules/dhcp_common/subnet.rb b/modules/dhcp_common/subnet.rb index ff43a65d4..bc609c8f1 100644 --- a/modules/dhcp_common/subnet.rb +++ b/modules/dhcp_common/subnet.rb @@ -62,8 +62,8 @@ def netmask_to_i end def validate_subnet_range!(from_address, to_address) - if (from=validate_ip(from_address)) && (to=validate_ip(to_address)) - raise Proxy::DHCP::Error, "Range does not belong to provided subnet" unless self.include?(from) && self.include?(to) + if (from = validate_ip(from_address)) && (to = validate_ip(to_address)) + raise Proxy::DHCP::Error, "Range does not belong to provided subnet" unless include?(from) && include?(to) from = IPAddr.new(from) to = IPAddr.new(to) raise Proxy::DHCP::Error, "#{from} can't be lower IP address than #{to} - change the order?" if from > to diff --git a/modules/dhcp_isc/dhcp_isc_plugin.rb b/modules/dhcp_isc/dhcp_isc_plugin.rb index deb64585a..bcf3ece47 100644 --- a/modules/dhcp_isc/dhcp_isc_plugin.rb +++ b/modules/dhcp_isc/dhcp_isc_plugin.rb @@ -6,7 +6,7 @@ class Plugin < ::Proxy::Provider capability 'dhcp_filename_hostname' default_settings :config => '/etc/dhcp/dhcpd.conf', :leases => '/var/lib/dhcpd/dhcpd.leases', - :omapi_port => '7911', :blacklist_duration_minutes => 30*60 + :omapi_port => '7911', :blacklist_duration_minutes => 30 * 60 requires :dhcp, ::Proxy::VERSION validate_readable :config, :leases diff --git a/modules/dhcp_libvirt/dhcp_libvirt_main.rb b/modules/dhcp_libvirt/dhcp_libvirt_main.rb index 4f6f6e3b4..919351f23 100644 --- a/modules/dhcp_libvirt/dhcp_libvirt_main.rb +++ b/modules/dhcp_libvirt/dhcp_libvirt_main.rb @@ -8,7 +8,7 @@ def initialize(network, libvirt_network_impl, subnet_service, free_ips_service) super(@network, nil, subnet_service, free_ips_service) end - def add_record(options={}) + def add_record(options = {}) record = super(options) libvirt_network.add_dhcp_record record record diff --git a/modules/dhcp_native_ms/dhcp_native_ms_plugin.rb b/modules/dhcp_native_ms/dhcp_native_ms_plugin.rb index 893200cbb..22c7ca4cb 100644 --- a/modules/dhcp_native_ms/dhcp_native_ms_plugin.rb +++ b/modules/dhcp_native_ms/dhcp_native_ms_plugin.rb @@ -2,7 +2,7 @@ module ::Proxy::DHCP::NativeMS class Plugin < ::Proxy::Provider plugin :dhcp_native_ms, ::Proxy::VERSION - default_settings :disable_ddns => true, :blacklist_duration_minutes => 30*60 + default_settings :disable_ddns => true, :blacklist_duration_minutes => 30 * 60 requires :dhcp, ::Proxy::VERSION diff --git a/modules/dns/dns_api.rb b/modules/dns/dns_api.rb index bb93c5a48..426cfbe34 100644 --- a/modules/dns/dns_api.rb +++ b/modules/dns/dns_api.rb @@ -96,7 +96,7 @@ def validate_srv_name!(name) raise Proxy::Dns::Error.new("Invalid DNS srv name #{name}") unless name =~ /^([a-zA-Z0-9_]([-a-zA-Z0-9_]+)?\.?)+$/ end - def validate_dns_name!(name, type=nil) + def validate_dns_name!(name, type = nil) if type == 'SRV' validate_srv_name!(name) else diff --git a/modules/dns/dns_plugin.rb b/modules/dns/dns_plugin.rb index 8a4cc6e52..c145723e0 100644 --- a/modules/dns/dns_plugin.rb +++ b/modules/dns/dns_plugin.rb @@ -1,7 +1,7 @@ module Proxy::Dns class Plugin < ::Proxy::Plugin - http_rackup_path File.expand_path("http_config.ru", File.expand_path("../", __FILE__)) - https_rackup_path File.expand_path("http_config.ru", File.expand_path("../", __FILE__)) + http_rackup_path File.expand_path("http_config.ru", File.expand_path(__dir__)) + https_rackup_path File.expand_path("http_config.ru", File.expand_path(__dir__)) uses_provider default_settings :use_provider => 'dns_nsupdate', :dns_ttl => 86_400 diff --git a/modules/dns_dnscmd/dns_dnscmd_main.rb b/modules/dns_dnscmd/dns_dnscmd_main.rb index dfcc4ae2b..d7d486a9c 100644 --- a/modules/dns_dnscmd/dns_dnscmd_main.rb +++ b/modules/dns_dnscmd/dns_dnscmd_main.rb @@ -33,18 +33,18 @@ def do_remove(name, type) nil end - def execute(cmd, msg=nil, error_only=false) + def execute(cmd, msg = nil, error_only = false) tsecs = 5 response = nil interpreter = Proxy::SETTINGS.x86_64 ? 'c:\windows\sysnative\cmd.exe' : 'c:\windows\system32\cmd.exe' - command = interpreter + ' /c c:\Windows\System32\dnscmd.exe ' + "#{@server} #{cmd}" + command = interpreter + ' /c c:\Windows\System32\dnscmd.exe ' + "#{@server} #{cmd}" std_in = std_out = std_err = nil begin timeout(tsecs) do logger.debug "executing: #{command}" std_in, std_out, std_err = Open3.popen3(command) - response = std_out.readlines + response = std_out.readlines response += std_err.readlines end rescue Timeout::Error diff --git a/modules/facts/facts_plugin.rb b/modules/facts/facts_plugin.rb index 76b81bea5..2e01508a7 100644 --- a/modules/facts/facts_plugin.rb +++ b/modules/facts/facts_plugin.rb @@ -1,6 +1,6 @@ class Proxy::FactsPlugin < ::Proxy::Plugin - http_rackup_path File.expand_path("http_config.ru", File.expand_path("../", __FILE__)) - https_rackup_path File.expand_path("http_config.ru", File.expand_path("../", __FILE__)) + http_rackup_path File.expand_path("http_config.ru", File.expand_path(__dir__)) + https_rackup_path File.expand_path("http_config.ru", File.expand_path(__dir__)) default_settings :enabled => false plugin :facts, ::Proxy::VERSION diff --git a/modules/httpboot/httpboot_plugin.rb b/modules/httpboot/httpboot_plugin.rb index 9a5bb73eb..50a519b19 100644 --- a/modules/httpboot/httpboot_plugin.rb +++ b/modules/httpboot/httpboot_plugin.rb @@ -1,7 +1,7 @@ module Proxy::Httpboot class Plugin < ::Proxy::Plugin - http_rackup_path File.expand_path("http_config.ru", File.expand_path("../", __FILE__)) - https_rackup_path File.expand_path("http_config.ru", File.expand_path("../", __FILE__)) + http_rackup_path File.expand_path("http_config.ru", File.expand_path(__dir__)) + https_rackup_path File.expand_path("http_config.ru", File.expand_path(__dir__)) plugin :httpboot, ::Proxy::VERSION diff --git a/modules/libvirt_common/libvirt_network.rb b/modules/libvirt_common/libvirt_network.rb index db7bc841f..fea2608ff 100644 --- a/modules/libvirt_common/libvirt_network.rb +++ b/modules/libvirt_common/libvirt_network.rb @@ -13,7 +13,7 @@ def initialize(url = nil, network = nil) end def connection - @connection ||= ::Libvirt::open(@url) + @connection ||= ::Libvirt.open(@url) @connection end diff --git a/modules/logs/logs_plugin.rb b/modules/logs/logs_plugin.rb index fadf573b0..0fc5ffa66 100644 --- a/modules/logs/logs_plugin.rb +++ b/modules/logs/logs_plugin.rb @@ -1,6 +1,6 @@ class ::Proxy::LogsPlugin < ::Proxy::Plugin - http_rackup_path File.expand_path("http_config.ru", File.expand_path("../", __FILE__)) - https_rackup_path File.expand_path("http_config.ru", File.expand_path("../", __FILE__)) + http_rackup_path File.expand_path("http_config.ru", File.expand_path(__dir__)) + https_rackup_path File.expand_path("http_config.ru", File.expand_path(__dir__)) plugin :logs, ::Proxy::VERSION default_settings :enabled => true diff --git a/modules/puppet_proxy/puppet_plugin.rb b/modules/puppet_proxy/puppet_plugin.rb index 3f43b66bb..864426564 100644 --- a/modules/puppet_proxy/puppet_plugin.rb +++ b/modules/puppet_proxy/puppet_plugin.rb @@ -1,7 +1,7 @@ module Proxy::Puppet class Plugin < Proxy::Plugin - http_rackup_path File.expand_path("http_config.ru", File.expand_path("../", __FILE__)) - https_rackup_path File.expand_path("http_config.ru", File.expand_path("../", __FILE__)) + http_rackup_path File.expand_path("http_config.ru", File.expand_path(__dir__)) + https_rackup_path File.expand_path("http_config.ru", File.expand_path(__dir__)) plugin :puppet, ::Proxy::VERSION diff --git a/modules/puppet_proxy_common/puppet_class.rb b/modules/puppet_proxy_common/puppet_class.rb index 01eee1052..19c6e83e5 100644 --- a/modules/puppet_proxy_common/puppet_class.rb +++ b/modules/puppet_proxy_common/puppet_class.rb @@ -11,12 +11,12 @@ def to_s # returns module name (excluding of the class name) def module - klass[0..(klass.index("::")-1)] if has_module?(klass) + klass[0..(klass.index("::") - 1)] if has_module?(klass) end # returns class name (excluding of the module name) def name - has_module?(klass) ? klass[(klass.index("::")+2)..-1] : klass + has_module?(klass) ? klass[(klass.index("::") + 2)..-1] : klass end attr_reader :params @@ -28,9 +28,9 @@ def has_module?(klass) def to_json(*a) { - 'json_class' => self.class.name, - 'klass' => klass, - 'params' => params, + 'json_class' => self.class.name, + 'klass' => klass, + 'params' => params, }.to_json(*a) end diff --git a/modules/puppetca/puppetca_plugin.rb b/modules/puppetca/puppetca_plugin.rb index 22b9e326b..96a5bec25 100644 --- a/modules/puppetca/puppetca_plugin.rb +++ b/modules/puppetca/puppetca_plugin.rb @@ -1,7 +1,7 @@ module Proxy::PuppetCa class Plugin < ::Proxy::Plugin - http_rackup_path File.expand_path("http_config.ru", File.expand_path("../", __FILE__)) - https_rackup_path File.expand_path("http_config.ru", File.expand_path("../", __FILE__)) + http_rackup_path File.expand_path("http_config.ru", File.expand_path(__dir__)) + https_rackup_path File.expand_path("http_config.ru", File.expand_path(__dir__)) uses_provider default_settings :use_provider => 'puppetca_hostname_whitelisting' diff --git a/modules/puppetca_hostname_whitelisting/puppetca_hostname_whitelisting_autosigner.rb b/modules/puppetca_hostname_whitelisting/puppetca_hostname_whitelisting_autosigner.rb index 81c364598..e769f8351 100644 --- a/modules/puppetca_hostname_whitelisting/puppetca_hostname_whitelisting_autosigner.rb +++ b/modules/puppetca_hostname_whitelisting/puppetca_hostname_whitelisting_autosigner.rb @@ -21,7 +21,7 @@ def disable(certname) end end.uniq.compact if found - open(autosign_file, File::TRUNC|File::RDWR) do |autosign| + open(autosign_file, File::TRUNC | File::RDWR) do |autosign| autosign.write entries.join end logger.debug "Removed #{certname} from autosign" diff --git a/modules/realm/realm_plugin.rb b/modules/realm/realm_plugin.rb index c9c09860d..495935785 100644 --- a/modules/realm/realm_plugin.rb +++ b/modules/realm/realm_plugin.rb @@ -1,7 +1,7 @@ module Proxy::Realm class Plugin < ::Proxy::Plugin - http_rackup_path File.expand_path("http_config.ru", File.expand_path("../", __FILE__)) - https_rackup_path File.expand_path("http_config.ru", File.expand_path("../", __FILE__)) + http_rackup_path File.expand_path("http_config.ru", File.expand_path(__dir__)) + https_rackup_path File.expand_path("http_config.ru", File.expand_path(__dir__)) default_settings :use_provider => 'realm_freeipa' diff --git a/modules/realm_freeipa/provider.rb b/modules/realm_freeipa/provider.rb index 45d69e035..99a97de73 100644 --- a/modules/realm_freeipa/provider.rb +++ b/modules/realm_freeipa/provider.rb @@ -33,7 +33,7 @@ def configure_ipa login.use_ssl = true login.verify_mode = OpenSSL::SSL::VERIFY_NONE - request = Net::HTTP::Post.new("/ipa/session/login_kerberos", 'Authorization'=>"Negotiate #{strict_encode64(token)}", 'Referer' => ipa_config.uri) + request = Net::HTTP::Post.new("/ipa/session/login_kerberos", 'Authorization' => "Negotiate #{strict_encode64(token)}", 'Referer' => ipa_config.uri) response = login.request(request) cookie = response['Set-Cookie'] @@ -41,7 +41,7 @@ def configure_ipa XMLRPC::Config.module_eval { const_set(:ENABLE_NIL_PARSER, true) } ipa = XMLRPC::Client.new2(ipa_config.scheme + "://" + ipa_config.host + "/ipa/session/xml") # For some reason ipa insists on having 'Referer' header to be present... - ipa.http_header_extra={ 'Referer' => ipa_config.uri, 'Content-Type' => 'text/xml; charset=utf-8' } + ipa.http_header_extra = { 'Referer' => ipa_config.uri, 'Content-Type' => 'text/xml; charset=utf-8' } ipa.cookie = cookie # set the session cookie ipa diff --git a/modules/root/root_plugin.rb b/modules/root/root_plugin.rb index b51b240f8..8c794abee 100644 --- a/modules/root/root_plugin.rb +++ b/modules/root/root_plugin.rb @@ -2,8 +2,8 @@ class ::Proxy::RootPlugin < ::Proxy::Plugin plugin :foreman_proxy, ::Proxy::VERSION default_settings :enabled => true - http_rackup_path File.expand_path("http_config.ru", File.expand_path("../", __FILE__)) - https_rackup_path File.expand_path("http_config.ru", File.expand_path("../", __FILE__)) + http_rackup_path File.expand_path("http_config.ru", File.expand_path(__dir__)) + https_rackup_path File.expand_path("http_config.ru", File.expand_path(__dir__)) override_module_loader_class ::Proxy::RootPluginLoader end diff --git a/modules/templates/templates_plugin.rb b/modules/templates/templates_plugin.rb index 5dda4aad4..403050fed 100644 --- a/modules/templates/templates_plugin.rb +++ b/modules/templates/templates_plugin.rb @@ -1,7 +1,7 @@ module Proxy::Templates class Plugin < ::Proxy::Plugin - http_rackup_path File.expand_path("http_config.ru", File.expand_path("../", __FILE__)) - https_rackup_path File.expand_path("http_config.ru", File.expand_path("../", __FILE__)) + http_rackup_path File.expand_path("http_config.ru", File.expand_path(__dir__)) + https_rackup_path File.expand_path("http_config.ru", File.expand_path(__dir__)) plugin :templates, ::Proxy::VERSION diff --git a/modules/tftp/server.rb b/modules/tftp/server.rb index 3c16e833a..3dc706305 100644 --- a/modules/tftp/server.rb +++ b/modules/tftp/server.rb @@ -75,7 +75,7 @@ def pxe_default end def pxeconfig_file(mac) - ["#{pxeconfig_dir}/01-"+mac.tr(':', "-").downcase] + ["#{pxeconfig_dir}/01-" + mac.tr(':', "-").downcase] end end class Pxelinux < Syslinux; end @@ -90,7 +90,7 @@ def pxe_default end def pxeconfig_file(mac) - ["#{pxeconfig_dir}/menu.lst.01"+mac.delete(':').upcase, "#{pxeconfig_dir}/01-"+mac.tr(':', '-').upcase] + ["#{pxeconfig_dir}/menu.lst.01" + mac.delete(':').upcase, "#{pxeconfig_dir}/01-" + mac.tr(':', '-').upcase] end end @@ -104,7 +104,7 @@ def pxe_default end def pxeconfig_file(mac) - ["#{pxeconfig_dir}/grub.cfg-01-"+mac.tr(':', '-').downcase, "#{pxeconfig_dir}/grub.cfg-#{mac.downcase}"] + ["#{pxeconfig_dir}/grub.cfg-01-" + mac.tr(':', '-').downcase, "#{pxeconfig_dir}/grub.cfg-#{mac.downcase}"] end end @@ -118,7 +118,7 @@ def pxe_default end def pxeconfig_file(mac) - ["#{pxeconfig_dir}/"+mac.delete(':').upcase, "#{pxeconfig_dir}/"+mac.delete(':').upcase+".cfg"] + ["#{pxeconfig_dir}/" + mac.delete(':').upcase, "#{pxeconfig_dir}/" + mac.delete(':').upcase + ".cfg"] end end @@ -132,7 +132,7 @@ def pxe_default end def pxeconfig_file(mac) - ["#{pxeconfig_dir}/"+mac.delete(':').upcase] + ["#{pxeconfig_dir}/" + mac.delete(':').upcase] end end @@ -146,7 +146,7 @@ def pxe_default end def pxeconfig_file(mac) - ["#{pxeconfig_dir}/01-"+mac.tr(':', "-").downcase+".ipxe"] + ["#{pxeconfig_dir}/01-" + mac.tr(':', "-").downcase + ".ipxe"] end end diff --git a/modules/tftp/tftp_api.rb b/modules/tftp/tftp_api.rb index a1214aad0..1bc6276c7 100644 --- a/modules/tftp/tftp_api.rb +++ b/modules/tftp/tftp_api.rb @@ -11,7 +11,7 @@ class Api < ::Sinatra::Base VARIANTS = ["Syslinux", "Pxelinux", "Pxegrub", "Pxegrub2", "Ztp", "Poap", "Ipxe"].freeze helpers do - def instantiate(variant, mac=nil) + def instantiate(variant, mac = nil) # Filenames must end in a hex representation of a mac address but only if mac is not empty log_halt 403, "Invalid MAC address: #{mac}" unless valid_mac?(mac) || mac.nil? log_halt 403, "Unrecognized pxeboot config type: #{variant}" unless VARIANTS.include?(variant.capitalize) diff --git a/modules/tftp/tftp_plugin.rb b/modules/tftp/tftp_plugin.rb index 37dd85051..5f1b197af 100644 --- a/modules/tftp/tftp_plugin.rb +++ b/modules/tftp/tftp_plugin.rb @@ -2,8 +2,8 @@ module Proxy::TFTP class Plugin < ::Proxy::Plugin plugin :tftp, ::Proxy::VERSION - http_rackup_path File.expand_path("http_config.ru", File.expand_path("../", __FILE__)) - https_rackup_path File.expand_path("http_config.ru", File.expand_path("../", __FILE__)) + http_rackup_path File.expand_path("http_config.ru", File.expand_path(__dir__)) + https_rackup_path File.expand_path("http_config.ru", File.expand_path(__dir__)) default_settings :tftproot => '/var/lib/tftpboot', :tftp_read_timeout => 60, diff --git a/test/bmc/bmc_api_shell_test.rb b/test/bmc/bmc_api_shell_test.rb index b975e65c4..825879e0e 100644 --- a/test/bmc/bmc_api_shell_test.rb +++ b/test/bmc/bmc_api_shell_test.rb @@ -15,7 +15,7 @@ def app def setup @host ||= ENV["ipmihost"] || "host" provider ||= ENV["ipmiprovider"] || "shell" - @args = { :bmc_provider => provider } + @args = { :bmc_provider => provider } end def test_api_shell_should_powercycle_with_shutdown diff --git a/test/bmc/bmc_api_test.rb b/test/bmc/bmc_api_test.rb index af73b81e1..939bc1385 100644 --- a/test/bmc/bmc_api_test.rb +++ b/test/bmc/bmc_api_test.rb @@ -23,7 +23,7 @@ def setup pass ||= ENV["ipmipass"] || "pass" @host ||= ENV["ipmihost"] || "host" provider ||= ENV["ipmiprovider"] || "ipmitool" - @args = { 'bmc_provider' => provider, 'blah' => 'test' } + @args = { 'bmc_provider' => provider, 'blah' => 'test' } authorize user, pass end @@ -112,7 +112,7 @@ def test_api_bmc_setup_returns_new_ipmi_proxy_given_ipmitool Proxy::BMC::IPMI.any_instance.stubs(:poweron).returns(true) Proxy::BMC::IPMI.any_instance.expects(:connect).with(:host => 'host', :username => 'user', :password => 'pass', :bmc_provider => 'ipmitool', - :options=>{"privilege"=>"OPERATOR"}) + :options => {"privilege" => "OPERATOR"}) body = {'bmc_provider' => 'ipmitool', :options => {'privilege' => 'OPERATOR'}}.to_json put "/#{host}/chassis/power/on", body, "CONTENT_TYPE" => "application/json" end @@ -123,7 +123,7 @@ def test_api_bmc_setup_returns_new_ipmi_proxy_given_freeipmi Proxy::BMC::IPMI.any_instance.stubs(:poweron).returns(true) Proxy::BMC::IPMI.any_instance.expects(:connect).with(:host => 'host', :username => 'user', :password => 'pass', :bmc_provider => 'freeipmi', - :options=>{"privilege"=>"OPERATOR"}) + :options => {"privilege" => "OPERATOR"}) body = {'bmc_provider' => 'freeipmi', :options => {'privilege' => 'OPERATOR'}}.to_json put "/#{host}/chassis/power/on", body, "CONTENT_TYPE" => "application/json" end @@ -142,8 +142,8 @@ def test_api_uses_options_hash_from_body Proxy::BMC::IPMI.any_instance.stubs(:poweron).returns(true) Proxy::BMC::IPMI.any_instance.expects(:connect).with(:host => 'host', :username => 'user', :password => 'pass', :bmc_provider => 'freeipmi', - :options=>{"driver"=>"lan20", "privilege"=>"OPERATOR"}) - body = {'bmc_provider' => 'freeipmi', :options => {"driver"=>"lan20", 'privilege' => 'OPERATOR'}}.to_json + :options => {"driver" => "lan20", "privilege" => "OPERATOR"}) + body = {'bmc_provider' => 'freeipmi', :options => {"driver" => "lan20", 'privilege' => 'OPERATOR'}}.to_json put "/#{host}/chassis/power/on", body, "CONTENT_TYPE" => "application/json" assert last_response.ok?, "Last response was not ok: #{last_response.body}" data = JSON.parse(last_response.body) @@ -156,7 +156,7 @@ def test_api_uses_options_hash_when_nil Proxy::BMC::IPMI.any_instance.stubs(:poweron).returns(true) Proxy::BMC::IPMI.any_instance.expects(:connect).with(:host => 'host', :username => 'user', :password => 'pass', :bmc_provider => 'freeipmi', - :options=>nil) + :options => nil) body = {'bmc_provider' => 'freeipmi', :options => nil}.to_json put "/#{host}/chassis/power/on", body, "CONTENT_TYPE" => "application/json" assert last_response.ok?, "Last response was not ok: #{last_response.body}" @@ -577,7 +577,7 @@ def test_api_can_pass_options_in_body args = { 'bmc_provider' => 'freeipmi', :options => {:driver => 'lan20', :privilege => 'USER'} }.to_json Proxy::BMC::IPMI.any_instance.expects(:connect).with(:username => 'user', :password => 'pass', :host => 'host', :bmc_provider => 'freeipmi', - :options=>{"driver"=>"lan20", "privilege"=>"USER"}) + :options => {"driver" => "lan20", "privilege" => "USER"}) Proxy::BMC::IPMI.any_instance.stubs(:bootbios).returns(true) put "/#{@host}/chassis/config/bootdevice/bios", args, "CONTENT_TYPE" => "application/json" assert last_response.ok?, "Last response was not ok: #{last_response.body}" diff --git a/test/dhcp/conf_parser_test.rb b/test/dhcp/conf_parser_test.rb index 6ae921c93..ed2b98d35 100644 --- a/test/dhcp/conf_parser_test.rb +++ b/test/dhcp/conf_parser_test.rb @@ -27,7 +27,7 @@ def test_hardware_parser Proxy::DHCP::CommonISC::ConfigurationParser.new.hardware.parse!('hardware token-ring 1:1:1:1:1:1;') end - MULTILINE_FQDN_LIST =<<~EOFFQDNLIST + MULTILINE_FQDN_LIST = <<~EOFFQDNLIST ns1.isc.org, ns1.isc.org, ns1.isc.org @@ -39,7 +39,7 @@ def test_fqdn_list_with_various_spacing assert_equal ['ns1.isc.org', 'ns1.isc.org', 'ns1.isc.org'], Proxy::DHCP::CommonISC::ConfigurationParser::FQDN_LIST.parse!(MULTILINE_FQDN_LIST) end - MULTILINE_IP_LIST =<<~EOFIPLIST + MULTILINE_IP_LIST = <<~EOFIPLIST 204.254.239.1, 204.254.239.2, 204.254.239.3 @@ -114,7 +114,7 @@ def test_subnet_matching_with_unrecognized_attribute Proxy::DHCP::CommonISC::ConfigurationParser.new.conf.parse!("subnet 192.168.1.0 netmask 255.255.255.128 {adaptive-lease-time-threshold 50;}") end - MULTILINE_SUBNET_WITH_OPtIONS =< ["192.168.122.250"]), - Proxy::DHCP::Subnet.new("192.168.123.0", "255.255.255.192", - "routers" => ["192.168.123.1"], "domain_name_servers" => ["192.168.123.1"], - "range" => ["192.168.123.2", "192.168.123.62"]), - Proxy::DHCP::Subnet.new("192.168.124.0", "255.255.255.0", - "routers" => ["192.168.124.1", "192.168.124.2"], - "domain_name_servers" => ["192.168.123.1", "192.168.122.250"]), + @subnets = [ + Proxy::DHCP::Subnet.new("192.168.122.0", "255.255.255.0", "routers" => ["192.168.122.250"]), + Proxy::DHCP::Subnet.new("192.168.123.0", "255.255.255.192", + "routers" => ["192.168.123.1"], "domain_name_servers" => ["192.168.123.1"], + "range" => ["192.168.123.2", "192.168.123.62"]), + Proxy::DHCP::Subnet.new("192.168.124.0", "255.255.255.0", + "routers" => ["192.168.124.1", "192.168.124.2"], + "domain_name_servers" => ["192.168.123.1", "192.168.122.250"]), ] @subnet = @subnets.first - @reservations = [Proxy::DHCP::Reservation.new("test.example.com", - "192.168.122.1", - "00:11:bb:cc:dd:ee", - @subnet, - :hostname => "test.example.com"), - Proxy::DHCP::Reservation.new("ten.example.com", - "192.168.122.10", - "10:10:10:10:10:10", - @subnet, - :hostname => "ten.example.com")] + @reservations = [ + Proxy::DHCP::Reservation.new("test.example.com", + "192.168.122.1", + "00:11:bb:cc:dd:ee", + @subnet, + :hostname => "test.example.com"), + Proxy::DHCP::Reservation.new("ten.example.com", + "192.168.122.10", + "10:10:10:10:10:10", + @subnet, + :hostname => "ten.example.com"), + ] @leases = [ Proxy::DHCP::Lease.new(nil, "192.168.122.2", "00:aa:bb:cc:dd:ee", @subnet, date_format("Sat Jul 12 10:08:29 UTC 2014"), nil, "active"), @@ -93,7 +96,7 @@ def test_get_network_unused_ip get "/192.168.122.0/unused_ip?mac=01:02:03:04:05:06&from=192.168.122.10&to=192.168.122.20" assert last_response.ok?, "Last response was not ok: #{last_response.status} #{last_response.body}" - assert_equal({"ip"=>"192.168.122.11"}, JSON.parse(last_response.body)) + assert_equal({"ip" => "192.168.122.11"}, JSON.parse(last_response.body)) end def test_get_unused_ip_for_nonexistent_network @@ -115,9 +118,9 @@ def test_get_record assert last_response.ok?, "Last response was not ok: #{last_response.status} #{last_response.body}" expected = { - "hostname" =>"test.example.com", - "ip" =>"192.168.122.1", - "mac" =>"00:11:bb:cc:dd:ee", + "hostname" => "test.example.com", + "ip" => "192.168.122.1", + "mac" => "00:11:bb:cc:dd:ee", } assert_equal expected, JSON.parse(last_response.body) end @@ -160,14 +163,14 @@ def test_get_lease_record_by_ip assert last_response.ok?, "Last response was not ok: #{last_response.status} #{last_response.body}" expected = [{ - "ends" => nil, - "ip" => "192.168.122.2", - "mac" => "00:aa:bb:cc:dd:ee", - "name" => "lease-00aabbccddee", + "ends" => nil, + "ip" => "192.168.122.2", + "mac" => "00:aa:bb:cc:dd:ee", + "name" => "lease-00aabbccddee", "starts" => "2014-07-12 10:08:29 UTC", - "state" => "active", + "state" => "active", "subnet" => "192.168.122.0/255.255.255.0", - "type" => "lease", + "type" => "lease", }] assert_equal expected, JSON.parse(last_response.body) end @@ -193,11 +196,11 @@ def test_get_record_by_mac expected = { "deleteable" => true, "type" => "reservation", - "hostname" =>"test.example.com", - "ip" =>"192.168.122.1", - "mac" =>"00:11:bb:cc:dd:ee", + "hostname" => "test.example.com", + "ip" => "192.168.122.1", + "mac" => "00:11:bb:cc:dd:ee", "name" => 'test.example.com', - "subnet" =>"192.168.122.0/255.255.255.0", # NOTE: 'subnet' attribute isn't being used by foreman, which adds a 'network' attribute instead + "subnet" => "192.168.122.0/255.255.255.0", # NOTE: 'subnet' attribute isn't being used by foreman, which adds a 'network' attribute instead } assert_equal expected, JSON.parse(last_response.body) end @@ -209,14 +212,14 @@ def test_get_record_by_mac_64 assert last_response.ok?, "Last response was not ok: #{last_response.status} #{last_response.body}" expected = { - "ends"=>nil, - "ip"=>"192.168.122.5", - "mac"=>"80:00:02:08:fe:80:00:00:00:00:00:00:00:02:aa:bb:cc:dd:ee:ff", - "name"=>"lease-80000208fe800000000000000002aabbccddeeff", - "starts"=>"2015-07-12 10:08:29 UTC", - "state"=>"active", - "subnet"=>"192.168.122.0/255.255.255.0", - "type"=>"lease", + "ends" => nil, + "ip" => "192.168.122.5", + "mac" => "80:00:02:08:fe:80:00:00:00:00:00:00:00:02:aa:bb:cc:dd:ee:ff", + "name" => "lease-80000208fe800000000000000002aabbccddeeff", + "starts" => "2015-07-12 10:08:29 UTC", + "state" => "active", + "subnet" => "192.168.122.0/255.255.255.0", + "type" => "lease", } assert_equal expected, JSON.parse(last_response.body) end @@ -230,11 +233,11 @@ def test_get_record_by_mac_uppercase expected = { "deleteable" => true, "type" => "reservation", - "hostname" =>"test.example.com", - "ip" =>"192.168.122.1", - "mac" =>"00:11:bb:cc:dd:ee", + "hostname" => "test.example.com", + "ip" => "192.168.122.1", + "mac" => "00:11:bb:cc:dd:ee", "name" => 'test.example.com', - "subnet" =>"192.168.122.0/255.255.255.0", # NOTE: 'subnet' attribute isn't being used by foreman, which adds a 'network' attribute instead + "subnet" => "192.168.122.0/255.255.255.0", # NOTE: 'subnet' attribute isn't being used by foreman, which adds a 'network' attribute instead } assert_equal expected, JSON.parse(last_response.body) end @@ -254,10 +257,10 @@ def test_get_record_by_mac_for_nonexistent_network # New record with identical duplicate contents should be a successful no-op def test_create_record_with_a_collision params = { - "hostname" => "test.example.com", - "ip" => "192.168.122.1", - "mac" => "00:11:bb:cc:dd:ee", - "network" => "192.168.122.0", + "hostname" => "test.example.com", + "ip" => "192.168.122.1", + "mac" => "00:11:bb:cc:dd:ee", + "network" => "192.168.122.0", } @server.expects(:add_record).raises(Proxy::DHCP::Collision) @@ -268,10 +271,10 @@ def test_create_record_with_a_collision def test_create_duplicate_record params = { - "hostname" => "test.example.com", - "ip" => "192.168.122.1", - "mac" => "00:11:bb:cc:dd:ee", - "network" => "192.168.122.0", + "hostname" => "test.example.com", + "ip" => "192.168.122.1", + "mac" => "00:11:bb:cc:dd:ee", + "network" => "192.168.122.0", } @server.expects(:add_record).raises(Proxy::DHCP::AlreadyExists) diff --git a/test/dhcp/dhcp_isc_subnet_service_initialization_test.rb b/test/dhcp/dhcp_isc_subnet_service_initialization_test.rb index e66781bf6..fb25c1a47 100644 --- a/test/dhcp/dhcp_isc_subnet_service_initialization_test.rb +++ b/test/dhcp/dhcp_isc_subnet_service_initialization_test.rb @@ -8,7 +8,7 @@ require 'dhcp_common/isc/subnet_service_initialization' class DhcpIscSubnetServiceInitializationTest < Test::Unit::TestCase - DHCPD_CONFIG =<<~END + DHCPD_CONFIG = <<~END # This is a comment. omapi-port 7911; diff --git a/test/dhcp/free_ips_test.rb b/test/dhcp/free_ips_test.rb index 6e03b5d5c..d5068dd80 100644 --- a/test/dhcp/free_ips_test.rb +++ b/test/dhcp/free_ips_test.rb @@ -7,7 +7,7 @@ class Proxy::DHCPFreeIpsTest < Test::Unit::TestCase def setup - @blacklist_interval = 30*60 + @blacklist_interval = 30 * 60 @free_ips = Proxy::DHCP::FreeIps.new(@blacklist_interval) @subnet = Proxy::DHCP::Subnet.new("192.168.1.0", "255.255.255.0") end @@ -32,7 +32,7 @@ def test_address_range_with_start_and_end def test_find_free_ip @free_ips.stubs(:icmp_pingable?).returns(false) @free_ips.stubs(:tcp_pingable?).returns(false) - r = Proxy::DHCP::Reservation.new('test', "192.168.1.1", "aa:bb:cc:dd:ee:ff", @subnet, :hostname =>'test') + r = Proxy::DHCP::Reservation.new('test', "192.168.1.1", "aa:bb:cc:dd:ee:ff", @subnet, :hostname => 'test') assert_equal "192.168.1.2", @free_ips.find_free_ip("192.168.1.1", "192.168.1.2", [r]) end @@ -55,7 +55,7 @@ def test_find_free_ip_should_temprarily_blacklist_allocated_ip @free_ips.stubs(:icmp_pingable?).returns(false) @free_ips.stubs(:tcp_pingable?).returns(false) @free_ips.expects(:time_now).returns(time_now = Time.now.to_i) - r = Proxy::DHCP::Reservation.new('test', "192.168.1.1", "aa:bb:cc:dd:ee:ff", @subnet, :hostname =>'test') + r = Proxy::DHCP::Reservation.new('test', "192.168.1.1", "aa:bb:cc:dd:ee:ff", @subnet, :hostname => 'test') assert @free_ips.allocated_ips.empty? assert @free_ips.allocation_timestamps.empty? @@ -69,14 +69,14 @@ def test_find_free_ip_should_temprarily_blacklist_allocated_ip def test_find_free_ip_should_use_icmp_ping @free_ips.expects(:icmp_pingable?).returns(false) @free_ips.stubs(:tcp_pingable?).returns(false) - r = Proxy::DHCP::Reservation.new('test', "192.168.1.1", "aa:bb:cc:dd:ee:ff", @subnet, :hostname =>'test') + r = Proxy::DHCP::Reservation.new('test', "192.168.1.1", "aa:bb:cc:dd:ee:ff", @subnet, :hostname => 'test') @free_ips.find_free_ip("192.168.1.1", "192.168.1.2", [r]) end def test_find_free_ip_should_use_tcp_ping @free_ips.expects(:tcp_pingable?).returns(false) @free_ips.stubs(:icmp_pingable?).returns(false) - r = Proxy::DHCP::Reservation.new('test', "192.168.1.1", "aa:bb:cc:dd:ee:ff", @subnet, :hostname =>'test') + r = Proxy::DHCP::Reservation.new('test', "192.168.1.1", "aa:bb:cc:dd:ee:ff", @subnet, :hostname => 'test') @free_ips.find_free_ip("192.168.1.1", "192.168.1.2", [r]) end @@ -84,7 +84,7 @@ def test_find_free_ip_should_temporarily_blaclist_pingable_ip @free_ips.expects(:tcp_pingable?).returns(true) @free_ips.stubs(:icmp_pingable?).returns(false) @free_ips.expects(:time_now).returns(time_now = Time.now.to_i) - r = Proxy::DHCP::Reservation.new('test', "192.168.1.1", "aa:bb:cc:dd:ee:ff", @subnet, :hostname =>'test') + r = Proxy::DHCP::Reservation.new('test', "192.168.1.1", "aa:bb:cc:dd:ee:ff", @subnet, :hostname => 'test') assert @free_ips.allocated_ips.empty? assert @free_ips.allocation_timestamps.empty? @@ -99,7 +99,7 @@ def test_clean_up_allocated_ips @free_ips.stubs(:icmp_pingable?).returns(false) @free_ips.stubs(:tcp_pingable?).returns(false) @free_ips.expects(:time_now).returns(Time.now.to_i) - r = Proxy::DHCP::Reservation.new('test', "192.168.1.1", "aa:bb:cc:dd:ee:ff", @subnet, :hostname =>'test') + r = Proxy::DHCP::Reservation.new('test', "192.168.1.1", "aa:bb:cc:dd:ee:ff", @subnet, :hostname => 'test') @free_ips.find_free_ip("192.168.1.1", "192.168.1.2", [r]) diff --git a/test/dhcp/sparc_attrs.rb b/test/dhcp/sparc_attrs.rb index 353e8ed73..a21c91587 100644 --- a/test/dhcp/sparc_attrs.rb +++ b/test/dhcp/sparc_attrs.rb @@ -1,20 +1,20 @@ module SparcAttrs def sparc_attrs { - "hostname"=>"example-server.example.com", - "mac"=>"00:21:28:6d:62:e8", - "ip"=>"192.168.122.11", - "network"=>"192.168.122.0", - "nextServer"=>"192.168.122.24", - "filename"=>"Solaris-5.10-hw0811-sun4v-inetboot", - "root_path_name"=>"/Solaris/install/Solaris_5.10_sparc_hw0811/Solaris_10/Tools/Boot", - "sysid_server_path"=>"192.168.122.24:/Solaris/jumpstart/sysidcfg/sysidcfg_primary", - "install_server_ip"=>"192.168.122.24", - "jumpstart_server_path"=>"192.168.122.24:/Solaris/jumpstart", - "install_server_name"=>"example-server.example.com", - "root_server_hostname"=>"example-server.example.com", - "root_server_ip"=>"192.168.122.24", - "install_path"=>"/Solaris/install/Solaris_5.10_sparc_hw0811", + "hostname" => "example-server.example.com", + "mac" => "00:21:28:6d:62:e8", + "ip" => "192.168.122.11", + "network" => "192.168.122.0", + "nextServer" => "192.168.122.24", + "filename" => "Solaris-5.10-hw0811-sun4v-inetboot", + "root_path_name" => "/Solaris/install/Solaris_5.10_sparc_hw0811/Solaris_10/Tools/Boot", + "sysid_server_path" => "192.168.122.24:/Solaris/jumpstart/sysidcfg/sysidcfg_primary", + "install_server_ip" => "192.168.122.24", + "jumpstart_server_path" => "192.168.122.24:/Solaris/jumpstart", + "install_server_name" => "example-server.example.com", + "root_server_hostname" => "example-server.example.com", + "root_server_ip" => "192.168.122.24", + "install_path" => "/Solaris/install/Solaris_5.10_sparc_hw0811", } end end diff --git a/test/dhcp_isc/dhcp_isc_config_test.rb b/test/dhcp_isc/dhcp_isc_config_test.rb index e6aeaacf7..4cf6de291 100644 --- a/test/dhcp_isc/dhcp_isc_config_test.rb +++ b/test/dhcp_isc/dhcp_isc_config_test.rb @@ -7,6 +7,6 @@ def test_default_configuration assert_equal '7911', Proxy::DHCP::ISC::Plugin.settings.omapi_port assert_equal '/etc/dhcp/dhcpd.conf', Proxy::DHCP::ISC::Plugin.settings.config assert_equal '/var/lib/dhcpd/dhcpd.leases', Proxy::DHCP::ISC::Plugin.settings.leases - assert_equal 30*60, Proxy::DHCP::ISC::Plugin.settings.blacklist_duration_minutes + assert_equal 30 * 60, Proxy::DHCP::ISC::Plugin.settings.blacklist_duration_minutes end end diff --git a/test/dhcp_libvirt/subnet_service_initializer_test.rb b/test/dhcp_libvirt/subnet_service_initializer_test.rb index 9676c0f41..0e5fc40c1 100644 --- a/test/dhcp_libvirt/subnet_service_initializer_test.rb +++ b/test/dhcp_libvirt/subnet_service_initializer_test.rb @@ -25,10 +25,10 @@ def setup XMLFIXTURE @json_leases = [{ - "ipaddr" => "192.168.122.22", - "mac" => "52:54:00:13:05:12", - "expirytime" => 1_455_723_598, - }] + "ipaddr" => "192.168.122.22", + "mac" => "52:54:00:13:05:12", + "expirytime" => 1_455_723_598, + }] @libvirt_network = mock() @subnet_store = {} @service = Proxy::DHCP::SubnetService.new(Proxy::MemoryStore.new, Proxy::MemoryStore.new, diff --git a/test/dhcp_ms_native/server_ms_test.rb b/test/dhcp_ms_native/server_ms_test.rb index b274cc553..5e807cec6 100644 --- a/test/dhcp_ms_native/server_ms_test.rb +++ b/test/dhcp_ms_native/server_ms_test.rb @@ -47,24 +47,38 @@ def test_should_return_subnet_with_options def test_should_return_all_hosts @dhcpsapi.expects(:list_subnet_elements).with(@network, anything).returns([{:element => {:reserved_ip_address => '192.168.42.10'}}]) - @dhcpsapi.expects(:list_clients_2008).with(@network).returns([ - {:client_ip_address => '192.168.42.10', :subnet_mask => @netmask, :client_hardware_address => '00:01:02:03:04:05', :client_name => 'test', :client_lease_expires => nil}, - {:client_ip_address => '192.168.42.11', :subnet_mask => @netmask, :client_hardware_address => '00:01:02:03:04:06', :client_name => 'test-2', :client_lease_expires => Time.now + 120}]) + @dhcpsapi.expects(:list_clients_2008).with(@network).returns( + [ + {:client_ip_address => '192.168.42.10', :subnet_mask => @netmask, :client_hardware_address => '00:01:02:03:04:05', :client_name => 'test', :client_lease_expires => nil}, + {:client_ip_address => '192.168.42.11', :subnet_mask => @netmask, :client_hardware_address => '00:01:02:03:04:06', :client_name => 'test-2', :client_lease_expires => Time.now + 120}, + ] + ) hosts = @server.all_hosts(@network) assert_equal 1, hosts.size - assert_equal ::Proxy::DHCP::Reservation.new('test', '192.168.42.10', '00:01:02:03:04:05', ::Proxy::DHCP::Subnet.new(@network, @netmask), - :hostname => 'test', - :deleteable => true), hosts.first + assert_equal( + ::Proxy::DHCP::Reservation.new( + 'test', + '192.168.42.10', + '00:01:02:03:04:05', + ::Proxy::DHCP::Subnet.new(@network, @netmask), + :hostname => 'test', + :deleteable => true + ), + hosts.first + ) end def test_should_return_all_leases lease_expires = Time.now + 120 @dhcpsapi.expects(:list_subnet_elements).with(@network, anything).returns([{:element => {:reserved_ip_address => '192.168.42.10'}}]) - @dhcpsapi.expects(:list_clients_2008).with(@network).returns([ - {:client_ip_address => '192.168.42.10', :subnet_mask => @netmask, :client_hardware_address => '00:01:02:03:04:05', :client_name => 'test', :client_lease_expires => nil}, - {:client_ip_address => '192.168.42.11', :subnet_mask => @netmask, :client_hardware_address => '00:01:02:03:04:06', :client_name => 'test-2', :client_lease_expires => lease_expires}]) + @dhcpsapi.expects(:list_clients_2008).with(@network).returns( + [ + {:client_ip_address => '192.168.42.10', :subnet_mask => @netmask, :client_hardware_address => '00:01:02:03:04:05', :client_name => 'test', :client_lease_expires => nil}, + {:client_ip_address => '192.168.42.11', :subnet_mask => @netmask, :client_hardware_address => '00:01:02:03:04:06', :client_name => 'test-2', :client_lease_expires => lease_expires}, + ] + ) leases = @server.all_leases(@network) diff --git a/test/dns_dnscmd/dnscmd_test.rb b/test/dns_dnscmd/dnscmd_test.rb index 72b45d0e3..a73257042 100644 --- a/test/dns_dnscmd/dnscmd_test.rb +++ b/test/dns_dnscmd/dnscmd_test.rb @@ -105,8 +105,6 @@ def test_dnscmd_enum_zones_parses_primary_zones_only domain.local Primary AD-Domain Secure domain.com Secondary File TrustAnchors Primary AD-Forest - - Command completed successfully.'.split("\n") Proxy::Dns::Dnscmd::Record.any_instance.expects(:execute).with('/EnumZones', nil, true).returns(to_parse) assert_equal [ @@ -127,8 +125,6 @@ def test_enum_a_records 3600 A 192.168.33.34 Command completed successfully. - - '.split("\n") Proxy::Dns::Dnscmd::Record.any_instance.expects(:execute).with('/EnumRecords domain.local host.domain.local. /Type A', 'EnumRecords', true).returns(to_parse) assert_equal ['192.168.33.33', '192.168.33.34'], Proxy::Dns::Dnscmd::Record.new('server', 999).enum_records('domain.local', 'host.domain.local', 'A') @@ -141,8 +137,6 @@ def test_enum_aaaa_records 3600 AAAA 2001:db8:85a3::8a2e:370:7334 Command completed successfully. - - '.split("\n") Proxy::Dns::Dnscmd::Record.any_instance.expects(:execute).with('/EnumRecords domain.local host.domain.local. /Type AAAA', 'EnumRecords', true).returns(to_parse) assert_equal ['2001:db8:85a3::8a2e:370:7335', '2001:db8:85a3::8a2e:370:7334'], Proxy::Dns::Dnscmd::Record.new('server', 999).enum_records('domain.local', 'host.domain.local', 'AAAA') @@ -154,8 +148,6 @@ def test_enum_cname_records @ 3600 CNAME alias.example.com. Command completed successfully. - - '.split("\n") Proxy::Dns::Dnscmd::Record.any_instance.expects(:execute).with('/EnumRecords example.com alias.example.com. /Type CNAME', 'EnumRecords', true).returns(to_parse) assert_equal ['alias.example.com.'], Proxy::Dns::Dnscmd::Record.new('server', 999).enum_records('example.com', 'alias.example.com', 'CNAME') @@ -167,8 +159,6 @@ def test_enum_ptr_records @ 3600 PTR host.domain.local. Command completed successfully. - - '.split("\n") Proxy::Dns::Dnscmd::Record.any_instance.expects(:execute).with('/EnumRecords 33.168.192.in-addr.arpa 33.33.168.192.in-addr.arpa. /Type PTR', 'EnumRecords', true).returns(to_parse) assert_equal ['host.domain.local.'], Proxy::Dns::Dnscmd::Record.new('server', 999).enum_records('33.168.192.in-addr.arpa', '33.33.168.192.in-addr.arpa', 'PTR') @@ -181,8 +171,6 @@ def test_enum_ptr_records_when_multiple 3600 PTR host2.domain.local. Command completed successfully. - - '.split("\n") Proxy::Dns::Dnscmd::Record.any_instance.expects(:execute).with('/EnumRecords 33.168.192.in-addr.arpa 33.33.168.192.in-addr.arpa. /Type PTR', 'EnumRecords', true).returns(to_parse) assert_equal ['host.domain.local.', 'host2.domain.local.'], Proxy::Dns::Dnscmd::Record.new('server', 999).enum_records('33.168.192.in-addr.arpa', '33.33.168.192.in-addr.arpa', 'PTR') @@ -193,8 +181,6 @@ def test_enum_ptr_records_when_none DNS Server failed to enumerate records for node 33.33.168.192.in-addr.arpa.. Status = 9714 (0x000025f2) Command failed: DNS_ERROR_NAME_DOES_NOT_EXIST 9714 0x25F2 - - '.split("\n") Proxy::Dns::Dnscmd::Record.any_instance.expects(:execute).with('/EnumRecords 33.168.192.in-addr.arpa 33.33.168.192.in-addr.arpa. /Type PTR', 'EnumRecords', true).returns(to_parse) assert_equal [], Proxy::Dns::Dnscmd::Record.new('server', 999).enum_records('33.168.192.in-addr.arpa', '33.33.168.192.in-addr.arpa', 'PTR') diff --git a/test/migrations/monolithic_config_file_migration_test.rb b/test/migrations/monolithic_config_file_migration_test.rb index 98b0f1cd7..de8637199 100644 --- a/test/migrations/monolithic_config_file_migration_test.rb +++ b/test/migrations/monolithic_config_file_migration_test.rb @@ -87,7 +87,7 @@ def test_output_has_correct_realm_settings end def test_output_has_correct_unknown_settings - assert_equal @unknown, :foo=>"bar" + assert_equal @unknown, :foo => "bar" end def test_migration_correctly_uses_http_when_ssl_disabled diff --git a/test/plugins/plugin_initializer_test.rb b/test/plugins/plugin_initializer_test.rb index 327b9961c..b751d043b 100644 --- a/test/plugins/plugin_initializer_test.rb +++ b/test/plugins/plugin_initializer_test.rb @@ -74,6 +74,6 @@ def test_initialize_plugins {:name => :plugin_5, :version => '1.0', :class => TestPlugin5, :state => :disabled, :http_enabled => false, :https_enabled => false, :settings => {}, :capabilities => []}, {:name => :plugin_6, :version => '1.0', :class => TestPlugin6, :state => :running, :http_enabled => true, :https_enabled => true, - :settings=>{:foo=>:bar}, :capabilities => [CAP_LAMBDA, CAP_PROC, 'foo']}], loaded) + :settings => {:foo => :bar}, :capabilities => [CAP_LAMBDA, CAP_PROC, 'foo']}], loaded) end end diff --git a/test/plugins/plugin_test.rb b/test/plugins/plugin_test.rb index e7253a445..eb1f5c6e4 100644 --- a/test/plugins/plugin_test.rb +++ b/test/plugins/plugin_test.rb @@ -36,7 +36,10 @@ def test_uses_default_module_initializer_if_after_activation_block_not_present assert_equal ::Proxy::DefaultModuleLoader, TestPluginWithoutAfterActivationBlock.module_loader_class end - class TestLoadClasses; def load_classes; end; end + class TestLoadClasses + def load_classes + end + end class TestLoadClassesViaClassPlugin < ::Proxy::Plugin load_classes TestLoadClasses end diff --git a/test/puppet/puppet_api_environments_retriever_test.rb b/test/puppet/puppet_api_environments_retriever_test.rb index 73cd7a206..656a6e581 100644 --- a/test/puppet/puppet_api_environments_retriever_test.rb +++ b/test/puppet/puppet_api_environments_retriever_test.rb @@ -18,7 +18,7 @@ def setup end def test_api_response_parsing - @api.find_environments_response = JSON.load(File.read(File.expand_path('../fixtures/environments_api.json', __FILE__))) + @api.find_environments_response = JSON.load(File.read(File.expand_path('fixtures/environments_api.json', __dir__))) envs = @retriever.all assert_equal Set.new(['production', 'example_env', 'development', 'common']), Set.new(envs.map(&:name)) diff --git a/test/puppet/puppet_api_v3_environment_classes_retriever_test.rb b/test/puppet/puppet_api_v3_environment_classes_retriever_test.rb index 83c5e3098..b2f61b70b 100644 --- a/test/puppet/puppet_api_v3_environment_classes_retriever_test.rb +++ b/test/puppet/puppet_api_v3_environment_classes_retriever_test.rb @@ -29,7 +29,7 @@ def test_passes_cached_etag_value_to_puppetapi def test_returns_cached_classes_if_puppet_responds_with_not_modified Proxy::PuppetApi::EnvironmentClassesApiv3.any_instance.expects(:list_classes).returns([Proxy::PuppetApi::EnvironmentClassesApiv3::NOT_MODIFIED, 42]) - expected_classes =<<~EOL + expected_classes = <<~EOL { "files": [ { @@ -88,7 +88,7 @@ def setup @retriever = Proxy::PuppetApi::V3EnvironmentClassesApiClassesRetriever.new(nil, nil, nil, nil, nil) end - ENVIRONMENT_CLASSES_RESPONSE =<<~EOL + ENVIRONMENT_CLASSES_RESPONSE = <<~EOL { "files": [ { @@ -116,12 +116,13 @@ def test_parser_with_environment_classes_response expected_reponse = [ {"classes" => [{"name" => "dns::config", "params" => []}], "path" => "/manifests/config.pp"}, { "classes" => [{"name" => "dns::install", "params" => []}], "path" => "/manifests/install.pp"}, - {"error" => "Syntax error at '=>' at /manifests/witherror.pp:20:19", "path" => "/manifests/witherror.pp"}] + {"error" => "Syntax error at '=>' at /manifests/witherror.pp:20:19", "path" => "/manifests/witherror.pp"}, + ] Proxy::PuppetApi::EnvironmentClassesApiv3.any_instance.expects(:list_classes).returns([JSON.load(ENVIRONMENT_CLASSES_RESPONSE), 42]) assert_equal expected_reponse, @retriever.classes_and_errors_in_environment('test_environment') end - ENVIRONMENT_CLASSES_RESPONSE_WITH_EXPRESSION_PARAMETERS =<<~EOL + ENVIRONMENT_CLASSES_RESPONSE_WITH_EXPRESSION_PARAMETERS = <<~EOL { "files": [{"classes": [{"name": "dns", "params": [ @@ -140,15 +141,21 @@ def test_legacy_parser_with_environment_classes_response_with_variable_expressio end def test_parser_with_environment_classes_response_with_variable_expression_parameteres - expected_response = [ - {"classes" => [{"name" => "dns", "params" => [ - {"default_source" => "${::dns::params::namedconf_path}", "name" => "namedconf_path"}, - {"default_source" => "${::dns::params::dnsdir}", "name" => "dnsdir"}]}], "path" => "/manifests/init.pp"}] + expected_response = [{ + "classes" => [{ + "name" => "dns", + "params" => [ + {"default_source" => "${::dns::params::namedconf_path}", "name" => "namedconf_path"}, + {"default_source" => "${::dns::params::dnsdir}", "name" => "dnsdir"}, + ], + }], + "path" => "/manifests/init.pp", + }] Proxy::PuppetApi::EnvironmentClassesApiv3.any_instance.expects(:list_classes).returns([JSON.load(ENVIRONMENT_CLASSES_RESPONSE_WITH_EXPRESSION_PARAMETERS), 42]) assert_equal expected_response, @retriever.classes_and_errors_in_environment('test_environment') end - ENVIRONMENT_CLASSES_RESPONSE_WITH_DEFAULT_LITERALS =<<~EOL + ENVIRONMENT_CLASSES_RESPONSE_WITH_DEFAULT_LITERALS = <<~EOL { "files": [{"classes": [{"name": "testing", "params": [ @@ -175,14 +182,19 @@ def test_legacy_parser_with_puppet_environment_classes_response_with_default_lit end def test_parser_with_puppet_environment_classes_response_with_default_literals - expected_response = [ - {"classes" => [{"name" => "testing", "params" => [ - {"default_literal" => "literal default", "default_source" => "literal default", "name" => "string_with_literal_default", "type" => "String"}, - { - "default_literal" => {"one" => "foo", "two" => "hello"}, - "default_source" => "{'one' => 'foo', 'two' => 'hello'}", - "name" => "a_hash", - "type" => "Hash"}]}], "path" => "init.pp"}] + expected_response = [{ + "classes" => [{ + "name" => "testing", "params" => [ + {"default_literal" => "literal default", "default_source" => "literal default", "name" => "string_with_literal_default", "type" => "String"}, + { + "default_literal" => {"one" => "foo", "two" => "hello"}, + "default_source" => "{'one' => 'foo', 'two' => 'hello'}", + "name" => "a_hash", + "type" => "Hash"}, + ] + }], + "path" => "init.pp", + }] Proxy::PuppetApi::EnvironmentClassesApiv3.any_instance.expects(:list_classes).returns([JSON.load(ENVIRONMENT_CLASSES_RESPONSE_WITH_DEFAULT_LITERALS), 42]) assert_equal expected_response, @retriever.classes_and_errors_in_environment('test_environment') diff --git a/test/puppet/puppet_class_test.rb b/test/puppet/puppet_class_test.rb index 39381b247..cfbe9c6a4 100644 --- a/test/puppet/puppet_class_test.rb +++ b/test/puppet/puppet_class_test.rb @@ -26,7 +26,7 @@ def test_should_parse_puppet_class_correctly def test_json_serialization clazz = Proxy::Puppet::PuppetClass.new( - "foreman_proxy::install", "namedconf_path"=>"${::dns::params::namedconf_path}", "dnsdir"=>"${::dns::params::dnsdir}") + "foreman_proxy::install", "namedconf_path" => "${::dns::params::namedconf_path}", "dnsdir" => "${::dns::params::dnsdir}") assert clazz.to_json.include?("\"json_class\":\"Proxy::Puppet::PuppetClass\"") assert clazz.to_json.include?("\"klass\":\"foreman_proxy::install\"") diff --git a/test/puppetca/puppetca_api_test.rb b/test/puppetca/puppetca_api_test.rb index 39c2983c3..c4c46b0c1 100644 --- a/test/puppetca/puppetca_api_test.rb +++ b/test/puppetca/puppetca_api_test.rb @@ -12,9 +12,11 @@ def list {} end - def sign(certname); end + def sign(certname) + end - def clean(certname); end + def clean(certname) + end end module Proxy::PuppetCa diff --git a/test/puppetca_http_api/puppetca_http_impl_test.rb b/test/puppetca_http_api/puppetca_http_impl_test.rb index dd633e197..0a4304a58 100644 --- a/test/puppetca_http_api/puppetca_http_impl_test.rb +++ b/test/puppetca_http_api/puppetca_http_impl_test.rb @@ -5,9 +5,11 @@ class PuppetCaHttpImplTest < Test::Unit::TestCase class FakeCaApiV1Request - def sign(certname); end + def sign(certname) + end - def clean(certname); end + def clean(certname) + end def search(key = 'foreman') [ diff --git a/test/puppetca_puppet_cert/puppetca_puppet_cert_test.rb b/test/puppetca_puppet_cert/puppetca_puppet_cert_test.rb index e78b8f71b..b4d7a9e92 100644 --- a/test/puppetca_puppet_cert/puppetca_puppet_cert_test.rb +++ b/test/puppetca_puppet_cert/puppetca_puppet_cert_test.rb @@ -20,7 +20,7 @@ def test_which_should_return_a_binary_path assert_equal '/bin/ls', @puppet_cert.which('ls') end - INVENTORY_CONTENTS =<<~EOF + INVENTORY_CONTENTS = <<~EOF 0x0002 2015-09-01T15:15:57UTC 2020-08-31T15:15:57UTC /CN=revoked.my.domain 0x0003 2015-09-02T08:34:59UTC 2020-09-01T08:34:59UTC /CN=active.my.domain 0x0004 2017-01-11T15:04:35UTC 2022-01-11T15:04:35UTC /CN=revoked.my.domain @@ -33,7 +33,7 @@ def test_parse_inventory @puppet_cert.parse_inventory(INVENTORY_CONTENTS)) end - CRL_CONTENTS =<<~EOF + CRL_CONTENTS = <<~EOF -----BEGIN X509 CRL----- MIIC9DCB3QIBATANBgkqhkiG9w0BAQUFADA0MTIwMAYDVQQDDClQdXBwZXQgQ0E6 IGx1Y2lkLW5vbnNlbnNlLmFwcGxpZWRsb2dpYy5jYRcNMTcwMTEyMTUzNjM1WhcN @@ -77,8 +77,8 @@ def test_revoked_serials end def test_compute_ca_inventory - assert_equal({"revoked.my.domain"=>{:serial=>4, :not_before=>"2017-01-11T15:04:35UTC", :not_after=>"2022-01-11T15:04:35UTC", :state=>"revoked"}, - "active.my.domain"=>{:serial=>3, :not_before=>"2015-09-02T08:34:59UTC", :not_after=>"2020-09-01T08:34:59UTC"}, + assert_equal({"revoked.my.domain" => {:serial => 4, :not_before => "2017-01-11T15:04:35UTC", :not_after => "2022-01-11T15:04:35UTC", :state => "revoked"}, + "active.my.domain" => {:serial => 3, :not_before => "2015-09-02T08:34:59UTC", :not_after => "2020-09-01T08:34:59UTC"}, "second-active.my.domain" => {:serial => 5, :not_before => "2017-01-14T12:01:22UTC", :not_after => "2022-01-14T12:01:22UTC"}}, @puppet_cert.compute_ca_inventory(INVENTORY_CONTENTS, CRL_CONTENTS)) end diff --git a/test/puppetca_token_whitelisting/puppetca_token_whitelisting_token_storage_test.rb b/test/puppetca_token_whitelisting/puppetca_token_whitelisting_token_storage_test.rb index 4ad9a46a0..c0acc5cfd 100644 --- a/test/puppetca_token_whitelisting/puppetca_token_whitelisting_token_storage_test.rb +++ b/test/puppetca_token_whitelisting/puppetca_token_whitelisting_token_storage_test.rb @@ -47,7 +47,7 @@ def test_should_be_able_to_remove_elements def test_should_queue_writes_when_locked @storage.lock do assert_raise Timeout::Error do - Timeout::timeout(3) do + Timeout.timeout(3) do @storage.write ['test'] end end diff --git a/test/realm/ipa_config_parser_test.rb b/test/realm/ipa_config_parser_test.rb index 66c124bd2..0899e4eea 100644 --- a/test/realm/ipa_config_parser_test.rb +++ b/test/realm/ipa_config_parser_test.rb @@ -3,7 +3,7 @@ class IpaConfigParserTest < Test::Unit::TestCase def setup - @parser = Proxy::FreeIPARealm::IpaConfigParser.new(File.expand_path("realm.conf", File.expand_path("../", __FILE__))) + @parser = Proxy::FreeIPARealm::IpaConfigParser.new(File.expand_path("realm.conf", File.expand_path(__dir__))) end def test_should_return_uri diff --git a/test/realm_freeipa/freeipa_provider_test.rb b/test/realm_freeipa/freeipa_provider_test.rb index 4209b1607..c42c4d501 100644 --- a/test/realm_freeipa/freeipa_provider_test.rb +++ b/test/realm_freeipa/freeipa_provider_test.rb @@ -116,13 +116,13 @@ def test_ensure_utf 1 => malformed_string, :key => malformed_string } new_hash = Proxy::FreeIPARealm::Provider.ensure_utf(malformed_hash) - assert_equal({ unicode_string => { unicode_string => [ unicode_string, 'test'], + assert_equal({ unicode_string => { unicode_string => [unicode_string, 'test'], 'hello' => 'world' }, 1 => unicode_string, :key => unicode_string }, new_hash) deserialized_hash = JSON.load(JSON.pretty_generate(new_hash)) - assert_equal({ unicode_string => { unicode_string => [ unicode_string, 'test'], + assert_equal({ unicode_string => { unicode_string => [unicode_string, 'test'], 'hello' => 'world' }, '1' => unicode_string, 'key' => unicode_string }, deserialized_hash) diff --git a/test/request_test.rb b/test/request_test.rb index 83d4b223c..22d79fa27 100644 --- a/test/request_test.rb +++ b/test/request_test.rb @@ -17,21 +17,21 @@ def setup end def test_get - stub_request(:get, @foreman_url+'/path').to_return(:status => [200, 'OK'], :body => "body") + stub_request(:get, @foreman_url + '/path').to_return(:status => [200, 'OK'], :body => "body") proxy_req = @request.request_factory.create_get("/path") result = @request.send_request(proxy_req) assert_equal("body", result.body) end def test_get_with_headers - stub_request(:get, @foreman_url+'/path?a=b').with(:headers => {"h1" => "header"}).to_return(:status => [200, 'OK'], :body => "body") + stub_request(:get, @foreman_url + '/path?a=b').with(:headers => {"h1" => "header"}).to_return(:status => [200, 'OK'], :body => "body") proxy_req = @request.request_factory.create_get "/path", {"a" => "b"}, "h1" => "header" result = @request.send_request(proxy_req) assert_equal("body", result.body) end def test_post - stub_request(:post, @foreman_url+'/path').with(:body => "body").to_return(:status => [200, 'OK'], :body => "body") + stub_request(:post, @foreman_url + '/path').with(:body => "body").to_return(:status => [200, 'OK'], :body => "body") proxy_req = @request.request_factory.create_post("/path", "body") result = @request.send_request(proxy_req) assert_equal("body", result.body) diff --git a/test/sd_notify_test.rb b/test/sd_notify_test.rb index 14212f4e0..57cad6837 100644 --- a/test/sd_notify_test.rb +++ b/test/sd_notify_test.rb @@ -43,7 +43,7 @@ def with_notify_socket(socket) end def with_test_socket(&block) - socket_path = File.expand_path('../tmp/systemd.socket', __FILE__) + socket_path = File.expand_path('tmp/systemd.socket', __dir__) File.delete(socket_path) if File.exist?(socket_path) socket = Socket.new(Socket::AF_UNIX, Socket::SOCK_DGRAM, 0) diff --git a/test/templates/template_proxy_request_test.rb b/test/templates/template_proxy_request_test.rb index 1f6860554..cacf18909 100644 --- a/test/templates/template_proxy_request_test.rb +++ b/test/templates/template_proxy_request_test.rb @@ -38,7 +38,7 @@ def test_header_extraction_http_version_gets_removed def test_template_requests_return_data_and_contain_template_url @expected_body = "my template" args = { :token => "test-token" } - stub_request(:get, @foreman_url+'/unattended/provision?token=test-token&url='+@template_url).to_return(:status => [200, 'OK'], :body => @expected_body) + stub_request(:get, @foreman_url + '/unattended/provision?token=test-token&url=' + @template_url).to_return(:status => [200, 'OK'], :body => @expected_body) result = Proxy::Templates::TemplateProxyRequest.new.get('provision', @request_env, args) assert_equal(@expected_body, result) end @@ -46,15 +46,15 @@ def test_template_requests_return_data_and_contain_template_url def test_template_requests_via_post @expected_body = "my template" args = { :token => "test-token" } - stub_request(:post, @foreman_url+'/unattended/built?token=test-token&url='+@template_url). + stub_request(:post, @foreman_url + '/unattended/built?token=test-token&url=' + @template_url). with( body: "my template", headers: { - 'Accept'=>['*/*', 'application/json,version=2'], - 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', - 'Content-Type'=>'application/json', - 'User-Agent'=>'Ruby', - 'X-Forwarded-For'=>'1.2.3.4, proxy.lan', + 'Accept' => ['*/*', 'application/json,version=2'], + 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', + 'Content-Type' => 'application/json', + 'User-Agent' => 'Ruby', + 'X-Forwarded-For' => '1.2.3.4, proxy.lan', }). to_return(status: 200, body: "", headers: {}) Proxy::Templates::TemplateProxyRequest.new.post('built', @request_env, args, @expected_body) @@ -63,7 +63,7 @@ def test_template_requests_via_post def test_template_requests_pass_static_flag_to_foreman @expected_body = "my template" args = { :token => "test-token", :static => "true" } - stub_request(:get, @foreman_url+'/unattended/provision?static=true&token=test-token&url='+@template_url).to_return(:status => [200, 'OK'], :body => @expected_body) + stub_request(:get, @foreman_url + '/unattended/provision?static=true&token=test-token&url=' + @template_url).to_return(:status => [200, 'OK'], :body => @expected_body) result = Proxy::Templates::TemplateProxyRequest.new.get('provision', @request_env, args) assert_equal(@expected_body, result) end @@ -71,7 +71,7 @@ def test_template_requests_pass_static_flag_to_foreman def test_template_requests_with_macaddress @expected_body = "my template" args = { :mac => "aa:bb:cc:dd:ee:ff" } - stub_request(:get, @foreman_url+'/unattended/provision?mac=aa:bb:cc:dd:ee:ff&url='+@template_url).to_return(:status => [200, 'OK'], :body => @expected_body) + stub_request(:get, @foreman_url + '/unattended/provision?mac=aa:bb:cc:dd:ee:ff&url=' + @template_url).to_return(:status => [200, 'OK'], :body => @expected_body) result = Proxy::Templates::TemplateProxyRequest.new.get('provision', @request_env, args) assert_equal(@expected_body, result) end @@ -80,8 +80,8 @@ def test_template_requests_with_rhn_headers @expected_body = "my template" @request_env['HTTP_X_RHN_PROVISIONING_MAC_0'] = 'aa:bb:cc:dd:ee:ff' args = { :token => "test-token" } - stub_request(:get, @foreman_url+'/unattended/provision?token=test-token&url='+@template_url). - with(:headers => {'X-Forwarded-For'=>'1.2.3.4, proxy.lan', 'X-Rhn-Provisioning-Mac-0'=>'aa:bb:cc:dd:ee:ff'}). + stub_request(:get, @foreman_url + '/unattended/provision?token=test-token&url=' + @template_url). + with(:headers => {'X-Forwarded-For' => '1.2.3.4, proxy.lan', 'X-Rhn-Provisioning-Mac-0' => 'aa:bb:cc:dd:ee:ff'}). to_return(:status => [200, 'OK'], :body => @expected_body) result = Proxy::Templates::TemplateProxyRequest.new.get('provision', @request_env, args) assert_equal(@expected_body, result) diff --git a/test/test_helper.rb b/test/test_helper.rb index df01f2d5f..dcd5bf95e 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -46,7 +46,7 @@ def launch(protocol: 'https', plugins: [], settings: {}) app = launcher.public_send("#{protocol}_app", port, plugins) launcher.webrick_server(app.merge(AccessLog: [Logger.new('/dev/null')]), ['localhost'], port).start end - Timeout::timeout(2) do + Timeout.timeout(2) do sleep(0.1) until can_connect?('localhost', @settings.send("#{protocol}_port")) end end diff --git a/test/util_test.rb b/test/util_test.rb index 1e8b23aa2..ddc1df904 100644 --- a/test/util_test.rb +++ b/test/util_test.rb @@ -27,7 +27,7 @@ def test_commandtask_with_exit_1 end def test_strict_encode64 - assert_equal "YWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWE=", UtilClass.strict_encode64("a"*50) + assert_equal "YWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWE=", UtilClass.strict_encode64("a" * 50) end def test_to_bool_true