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

Add support for passing a list of ldap servers #96

Merged
merged 7 commits into from
Oct 5, 2016
Merged
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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ There are a few configuration options required to use this adapter:

* host: is the host address where the ldap server lives.
* port: is the port where the ldap server lives.
* hosts: (optional) an enumerable of pairs of hosts and corresponding ports with which to attempt opening connections (default [[host, port]]). Overrides host and port if set.
* encryption: is the encryption protocol, disabled by default. The valid options are `ssl` and `tls`.
* uid: is the field name in the ldap server used to authenticate your users, in ActiveDirectory this is `sAMAccountName`.

Expand Down
4 changes: 4 additions & 0 deletions lib/github/ldap.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ class Ldap
#
# host: required string ldap server host address
# port: required string or number ldap server port
# hosts: an enumerable of pairs of hosts and corresponding ports with
# which to attempt opening connections (default [[host, port]]). Overrides
# host and port if set.
# encryption: optional string. `ssl` or `tls`. nil by default
# admin_user: optional string ldap administrator user dn for authentication
# admin_password: optional string ldap administrator user password
Expand Down Expand Up @@ -88,6 +91,7 @@ def initialize(options = {})
@connection = Net::LDAP.new({
host: options[:host],
port: options[:port],
hosts: options[:hosts],
instrumentation_service: options[:instrumentation_service]
})

Expand Down
15 changes: 15 additions & 0 deletions test/ldap_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,21 @@ def test_connection_with_default_options
assert @ldap.test_connection, "Ldap connection expected to succeed"
end

def test_connection_with_list_of_hosts_with_one_valid_host
ldap = GitHub::Ldap.new(options.merge(hosts: [["localhost", options[:port]]]))
assert ldap.test_connection, "Ldap connection expected to succeed"
end

def test_connection_with_list_of_hosts_with_first_valid
ldap = GitHub::Ldap.new(options.merge(hosts: [["localhost", options[:port]], ["invalid.local", options[:port]]]))
assert ldap.test_connection, "Ldap connection expected to succeed"
end

def test_connection_with_list_of_hosts_with_first_invalid
ldap = GitHub::Ldap.new(options.merge(hosts: [["invalid.local", options[:port]], ["localhost", options[:port]]]))
assert ldap.test_connection, "Ldap connection expected to succeed"
end

def test_simple_tls
assert_equal :simple_tls, @ldap.check_encryption(:ssl)
assert_equal :simple_tls, @ldap.check_encryption('SSL')
Expand Down