Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow computername_prefix to be unset #33

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 16 additions & 3 deletions lib/smart_proxy_realm_ad/provider.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion smart_proxy_realm_ad_plugin.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
Loading