Skip to content

Commit 59bdd4a

Browse files
committed
Allow prefix to be empty
1 parent 4501849 commit 59bdd4a

File tree

2 files changed

+17
-4
lines changed

2 files changed

+17
-4
lines changed

lib/smart_proxy_realm_ad/provider.rb

+16-3
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ def initialize(options = {})
1717
@domain_controller = options[:domain_controller]
1818
@domain = options[:realm].downcase
1919
@ou = options[:ou]
20-
@computername_prefix = options[:computername_prefix]
21-
@computername_hash = options[:computername_hash]
20+
@computername_prefix = options.fetch(:computername_prefix, '')
21+
@computername_hash = options.fetch(:computername_hash, @null)
2222
@computername_use_fqdn = options[:computername_use_fqdn]
2323
logger.info 'Proxy::AdRealm: initialize...'
2424
end
@@ -76,7 +76,20 @@ def hostfqdn_to_computername(hostfqdn)
7676
end
7777

7878
def apply_computername_prefix?(computername)
79-
!computername_prefix.nil? && !computername_prefix.empty? && (computername_hash || !computername[0, computername_prefix.size].casecmp(computername_prefix).zero?)
79+
# Return false if computername is nil or empty
80+
return false if computername.nil? || computername.empty?
81+
82+
# Return false if computername_prefix is nil or empty
83+
return false if computername_prefix.nil? || computername_prefix.empty?
84+
85+
# Extract the prefix from computername with the same length as computername_prefix
86+
extracted_prefix = computername[0, computername_prefix.size]
87+
88+
# Check if prefix is already in the beginning of computername string
89+
prefix_matches = extracted_prefix.casecmp(computername_prefix).zero?
90+
91+
# Return true if computername_hash is non empty or if the prefix does not match
92+
computername_hash || !prefix_matches
8093
end
8194

8295
def kinit_radcli_connect

smart_proxy_realm_ad_plugin.gemspec

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ Gem::Specification.new do |s|
1717
s.test_files = Dir['test/**/*']
1818

1919
s.add_development_dependency('rake')
20-
s.add_development_dependency('mocha')
20+
s.add_development_dependency('mocha', '~> 1.3.0')
2121
s.add_development_dependency('test-unit')
2222
s.add_dependency('rkerberos')
2323
s.add_dependency('radcli')

0 commit comments

Comments
 (0)