-
Notifications
You must be signed in to change notification settings - Fork 252
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
Normalize the encryption parameter passed to the LDAP constructor #264
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -539,7 +539,7 @@ def initialize(args = {}) | |
@auth = args[:auth] || DefaultAuth | ||
@base = args[:base] || DefaultTreebase | ||
@force_no_page = args[:force_no_page] || DefaultForceNoPage | ||
@encryption = args[:encryption] # may be nil | ||
@encryption = normalize_encryption(args[:encryption]) # may be nil | ||
@connect_timeout = args[:connect_timeout] | ||
|
||
if pr = @auth[:password] and pr.respond_to?(:call) | ||
|
@@ -609,13 +609,7 @@ def authenticate(username, password) | |
def encryption(args) | ||
warn "Deprecation warning: please give :encryption option as a Hash to Net::LDAP.new" | ||
return if args.nil? | ||
return @encryption = args if args.is_a? Hash | ||
|
||
case method = args.to_sym | ||
when :simple_tls, :start_tls | ||
args = { :method => method, :tls_options => {} } | ||
end | ||
@encryption = args | ||
@encryption = normalize_encryption(args) | ||
end | ||
|
||
# #open takes the same parameters as #new. #open makes a network | ||
|
@@ -1323,4 +1317,17 @@ def new_connection | |
} | ||
raise e | ||
end | ||
|
||
# Normalize encryption parameter the constructor accepts, expands a few | ||
# convenience symbols into recognizable hashes | ||
def normalize_encryption(args) | ||
return if args.nil? | ||
return args if args.is_a? Hash | ||
|
||
case method = args.to_sym | ||
when :simple_tls, :start_tls | ||
{ :method => method, :tls_options => {} } | ||
end | ||
end | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looks good! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry, what exactly would you like me to do? The method should take 1 of 4 types of arguments (nil, string, symbol, or hash) and return either nil or a hash. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ah, sorry, I misunderstood. the purpose of this method is to normalize (I was thinking of validating a given |
||
|
||
end # class LDAP |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You already moved this line to your
normalize_encryption
method.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I debated whether to include that line in there or not. I'm trying to mimic the exact logic that currently exists, which is "if nil is passed to the encryption method, don't set the encryption". If I omit the line, It will set the encryption to nil.
I'm fine with changing it if you feel it is the desired behavior to have the method set the encryption to nil.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's a great point. 👍 to leaving this. Especially since it's a deprecated method.