Skip to content

Commit b75ef74

Browse files
authored
Merge pull request #96 from lildude/lildude/multiple-ldap-servers
Add support for passing a list of ldap servers
2 parents 2b248d3 + 9315cee commit b75ef74

File tree

3 files changed

+20
-0
lines changed

3 files changed

+20
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ There are a few configuration options required to use this adapter:
2828

2929
* host: is the host address where the ldap server lives.
3030
* port: is the port where the ldap server lives.
31+
* 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.
3132
* encryption: is the encryption protocol, disabled by default. The valid options are `ssl` and `tls`.
3233
* uid: is the field name in the ldap server used to authenticate your users, in ActiveDirectory this is `sAMAccountName`.
3334

lib/github/ldap.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,9 @@ class Ldap
6161
#
6262
# host: required string ldap server host address
6363
# port: required string or number ldap server port
64+
# hosts: an enumerable of pairs of hosts and corresponding ports with
65+
# which to attempt opening connections (default [[host, port]]). Overrides
66+
# host and port if set.
6467
# encryption: optional string. `ssl` or `tls`. nil by default
6568
# admin_user: optional string ldap administrator user dn for authentication
6669
# admin_password: optional string ldap administrator user password
@@ -88,6 +91,7 @@ def initialize(options = {})
8891
@connection = Net::LDAP.new({
8992
host: options[:host],
9093
port: options[:port],
94+
hosts: options[:hosts],
9195
instrumentation_service: options[:instrumentation_service]
9296
})
9397

test/ldap_test.rb

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,21 @@ def test_connection_with_default_options
99
assert @ldap.test_connection, "Ldap connection expected to succeed"
1010
end
1111

12+
def test_connection_with_list_of_hosts_with_one_valid_host
13+
ldap = GitHub::Ldap.new(options.merge(hosts: [["localhost", options[:port]]]))
14+
assert ldap.test_connection, "Ldap connection expected to succeed"
15+
end
16+
17+
def test_connection_with_list_of_hosts_with_first_valid
18+
ldap = GitHub::Ldap.new(options.merge(hosts: [["localhost", options[:port]], ["invalid.local", options[:port]]]))
19+
assert ldap.test_connection, "Ldap connection expected to succeed"
20+
end
21+
22+
def test_connection_with_list_of_hosts_with_first_invalid
23+
ldap = GitHub::Ldap.new(options.merge(hosts: [["invalid.local", options[:port]], ["localhost", options[:port]]]))
24+
assert ldap.test_connection, "Ldap connection expected to succeed"
25+
end
26+
1227
def test_simple_tls
1328
assert_equal :simple_tls, @ldap.check_encryption(:ssl)
1429
assert_equal :simple_tls, @ldap.check_encryption('SSL')

0 commit comments

Comments
 (0)