github-ldap 1.0.4 → 1.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |spec|
4
4
  spec.name = "github-ldap"
5
- spec.version = "1.0.4"
5
+ spec.version = "1.0.5"
6
6
  spec.authors = ["David Calavera"]
7
7
  spec.email = ["david.calavera@gmail.com"]
8
8
  spec.description = %q{Ldap authentication for humans}
@@ -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[:encryptation])
15
+ if encryption = check_encryption(options[:encryption])
17
16
  @connection.encryption(encryption)
18
17
  end
19
18
  end
20
19
 
21
- # Check the legacy auth configuration options (before David's war with omniauth)
22
- # to determine whether to use encryptation or not.
20
+ # Determine whether to use encryption or not.
23
21
  #
24
- # encryptation: is the encryptation method, either 'ssl', 'tls', 'simple_tls' or 'start_tls'.
22
+ # encryption: is the encryption method, either 'ssl', 'tls', 'simple_tls' or 'start_tls'.
25
23
  #
26
- # Returns the real encryptation type.
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
- # Return true if the connection is successful.
42
- # Return false if the authentication settings are not valid.
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
@@ -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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: github-ldap
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.4
4
+ version: 1.0.5
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: