Skip to content

Commit

Permalink
Merge pull request #96 from lildude/lildude/multiple-ldap-servers
Browse files Browse the repository at this point in the history
Add support for passing a list of ldap servers
  • Loading branch information
lildude authored Oct 5, 2016
2 parents 2b248d3 + 9315cee commit b75ef74
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 0 deletions.
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

0 comments on commit b75ef74

Please sign in to comment.