diff --git a/lib/smart_proxy_realm_ad/provider.rb b/lib/smart_proxy_realm_ad/provider.rb index 7a6ae9d..bf96180 100644 --- a/lib/smart_proxy_realm_ad/provider.rb +++ b/lib/smart_proxy_realm_ad/provider.rb @@ -19,8 +19,8 @@ def initialize(options = {}) @domain_controller = options[:domain_controller] @domain = options[:realm].downcase @ou = options[:ou] - @computername_prefix = options[:computername_prefix] - @computername_hash = options[:computername_hash] + @computername_prefix = options.fetch(:computername_prefix, '') + @computername_hash = options.fetch(:computername_hash, @null) @computername_use_fqdn = options[:computername_use_fqdn] logger.info 'Proxy::AdRealm: initialize...' end @@ -78,7 +78,20 @@ def hostfqdn_to_computername(hostfqdn) end def apply_computername_prefix?(computername) - !computername_prefix.nil? && !computername_prefix.empty? && (computername_hash || !computername[0, computername_prefix.size].casecmp(computername_prefix).zero?) + # Return false if computername is nil or empty + return false if computername.nil? || computername.empty? + + # Return false if computername_prefix is nil or empty + return false if computername_prefix.nil? || computername_prefix.empty? + + # Extract the prefix from computername with the same length as computername_prefix + extracted_prefix = computername[0, computername_prefix.size] + + # Check if prefix is already in the beginning of computername string + prefix_matches = extracted_prefix.casecmp(computername_prefix).zero? + + # Return true if computername_hash is non empty or if the prefix does not match + computername_hash || !prefix_matches end def kinit_radcli_connect diff --git a/smart_proxy_realm_ad_plugin.gemspec b/smart_proxy_realm_ad_plugin.gemspec index 522fc49..2027229 100644 --- a/smart_proxy_realm_ad_plugin.gemspec +++ b/smart_proxy_realm_ad_plugin.gemspec @@ -19,7 +19,7 @@ Gem::Specification.new do |s| s.test_files = Dir['test/**/*'] s.add_development_dependency('rake') - s.add_development_dependency('mocha') + s.add_development_dependency('mocha', '~> 1.3.0') s.add_development_dependency('test-unit') s.add_dependency('rkerberos') s.add_dependency('radcli')