github-ldap 1.0.4 → 1.0.5
Sign up to get free protection for your applications and to get access to all the features.
- data/github-ldap.gemspec +1 -1
- data/lib/github/ldap.rb +18 -12
- data/test/ldap_test.rb +2 -0
- metadata +1 -1
data/github-ldap.gemspec
CHANGED
data/lib/github/ldap.rb
CHANGED
@@ -3,27 +3,25 @@ module GitHub
|
|
3
3
|
require 'net/ldap'
|
4
4
|
require 'github/ldap/domain'
|
5
5
|
|
6
|
+
attr_reader :connection
|
7
|
+
|
6
8
|
def initialize(options = {})
|
7
9
|
@uid = options[:uid] || "sAMAccountName"
|
8
10
|
|
9
|
-
@connection = Net::LDAP.new({
|
10
|
-
host: options[:host],
|
11
|
-
port: options[:port]
|
12
|
-
})
|
11
|
+
@connection = Net::LDAP.new({host: options[:host], port: options[:port]})
|
13
12
|
|
14
13
|
@connection.authenticate(options[:admin_user], options[:admin_password])
|
15
14
|
|
16
|
-
if encryption = check_encryption(options[:
|
15
|
+
if encryption = check_encryption(options[:encryption])
|
17
16
|
@connection.encryption(encryption)
|
18
17
|
end
|
19
18
|
end
|
20
19
|
|
21
|
-
#
|
22
|
-
# to determine whether to use encryptation or not.
|
20
|
+
# Determine whether to use encryption or not.
|
23
21
|
#
|
24
|
-
#
|
22
|
+
# encryption: is the encryption method, either 'ssl', 'tls', 'simple_tls' or 'start_tls'.
|
25
23
|
#
|
26
|
-
# Returns the real
|
24
|
+
# Returns the real encryption type.
|
27
25
|
def check_encryption(encryption)
|
28
26
|
return unless encryption
|
29
27
|
|
@@ -38,11 +36,19 @@ module GitHub
|
|
38
36
|
# Utility method to check if the connection with the server can be stablished.
|
39
37
|
# It tries to bind with the ldap auth default configuration.
|
40
38
|
#
|
41
|
-
#
|
42
|
-
#
|
43
|
-
# Raises an Net::LDAP::LdapError if the connection fails.
|
39
|
+
# Returns an OpenStruct with `code` and `message`.
|
40
|
+
# If `code` is 0, the operation succeeded and there is no message.
|
44
41
|
def test_connection
|
45
42
|
@connection.bind
|
43
|
+
get_last_operation_result
|
44
|
+
end
|
45
|
+
|
46
|
+
# Utility method to get the last operation result with a human friendly message.
|
47
|
+
#
|
48
|
+
# Returns an OpenStruct with `code` and `message`.
|
49
|
+
# If `code` is 0, the operation succeeded and there is no message.
|
50
|
+
def get_last_operation_result
|
51
|
+
@connection.get_operation_result
|
46
52
|
end
|
47
53
|
|
48
54
|
# Creates a new domain object to perform operations
|
data/test/ldap_test.rb
CHANGED
@@ -21,11 +21,13 @@ class GitHubLdapTest < Minitest::Test
|
|
21
21
|
|
22
22
|
def test_simple_tls
|
23
23
|
assert_equal :simple_tls, @ldap.check_encryption(:ssl)
|
24
|
+
assert_equal :simple_tls, @ldap.check_encryption('SSL')
|
24
25
|
assert_equal :simple_tls, @ldap.check_encryption(:simple_tls)
|
25
26
|
end
|
26
27
|
|
27
28
|
def test_start_tls
|
28
29
|
assert_equal :start_tls, @ldap.check_encryption(:tls)
|
30
|
+
assert_equal :start_tls, @ldap.check_encryption('TLS')
|
29
31
|
assert_equal :start_tls, @ldap.check_encryption(:start_tls)
|
30
32
|
end
|
31
33
|
end
|