From 59bdd4a565b48666ec90a7c8d03b38338aaf647c Mon Sep 17 00:00:00 2001 From: Marten Cassel Date: Mon, 23 Sep 2024 09:06:37 +0200 Subject: [PATCH] Allow prefix to be empty --- lib/smart_proxy_realm_ad/provider.rb | 19 ++++++++++++++++--- smart_proxy_realm_ad_plugin.gemspec | 2 +- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/lib/smart_proxy_realm_ad/provider.rb b/lib/smart_proxy_realm_ad/provider.rb index 640fadc..0e17ea3 100644 --- a/lib/smart_proxy_realm_ad/provider.rb +++ b/lib/smart_proxy_realm_ad/provider.rb @@ -17,8 +17,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 @@ -76,7 +76,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 2def646..bc055ba 100644 --- a/smart_proxy_realm_ad_plugin.gemspec +++ b/smart_proxy_realm_ad_plugin.gemspec @@ -17,7 +17,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')