github-ldap 1.0.11 → 1.0.12

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -28,11 +28,14 @@ There are a few configuration options required to use this adapter:
28
28
 
29
29
  * host: is the host address where the ldap server lives.
30
30
  * port: is the port where the ldap server lives.
31
- * admin_user: is the the ldap administrator user. Required to perform search operation.
32
- * admin_password: is the password for the administrator user. Simple authentication is required on the server.
33
31
  * encryption: is the encryption protocol, disabled by default. The valid options are `ssl` and `tls`.
34
32
  * uid: is the field name in the ldap server used to authenticate your users, in ActiveDirectory this is `sAMAccountName`.
35
33
 
34
+ Using administrator credentials is optional but recommended. You can pass those credentials with these two options:
35
+
36
+ * admin_user: is the the ldap administrator user dn.
37
+ * admin_password: is the password for the administrator user.
38
+
36
39
  Initialize a new adapter using those required options:
37
40
 
38
41
  ```ruby
data/github-ldap.gemspec CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |spec|
4
4
  spec.name = "github-ldap"
5
- spec.version = "1.0.11"
5
+ spec.version = "1.0.12"
6
6
  spec.authors = ["David Calavera"]
7
7
  spec.email = ["david.calavera@gmail.com"]
8
8
  spec.description = %q{Ldap authentication for humans}
data/lib/github/ldap.rb CHANGED
@@ -26,7 +26,9 @@ module GitHub
26
26
 
27
27
  @connection = Net::LDAP.new({host: options[:host], port: options[:port]})
28
28
 
29
- @connection.authenticate(options[:admin_user], options[:admin_password])
29
+ if options[:admin_user] && options[:admin_password]
30
+ @connection.authenticate(options[:admin_user], options[:admin_password])
31
+ end
30
32
 
31
33
  if encryption = check_encryption(options[:encryption])
32
34
  @connection.encryption(encryption)
@@ -33,10 +33,10 @@ module GitHub
33
33
  def self.start_server(options = {})
34
34
  @server_options = DEFAULT_SERVER_OPTIONS.merge(options)
35
35
 
36
- @server_options[:allow_anonymous] = false
37
- @server_options[:ldif] = @server_options[:user_fixtures]
38
- @server_options[:domain] = @server_options[:user_domain]
39
- @server_options[:tmpdir] ||= server_tmp
36
+ @server_options[:allow_anonymous] ||= false
37
+ @server_options[:ldif] = @server_options[:user_fixtures]
38
+ @server_options[:domain] = @server_options[:user_domain]
39
+ @server_options[:tmpdir] ||= server_tmp
40
40
 
41
41
  @ldap_server = Ladle::Server.new(@server_options)
42
42
  @ldap_server.start
data/test/domain_test.rb CHANGED
@@ -1,18 +1,8 @@
1
1
  require 'test_helper'
2
2
 
3
- class GitHubLdapDomainTest < Minitest::Test
3
+ module GitHubLdapDomainTestCases
4
4
  def setup
5
- GitHub::Ldap.start_server
6
-
7
- @options = GitHub::Ldap.server_options.merge \
8
- host: 'localhost',
9
- uid: 'uid'
10
-
11
- @domain = GitHub::Ldap.new(@options).domain("dc=github,dc=com")
12
- end
13
-
14
- def teardown
15
- GitHub::Ldap.stop_server
5
+ @domain = GitHub::Ldap.new(options).domain("dc=github,dc=com")
16
6
  end
17
7
 
18
8
  def test_user_valid_login
@@ -124,3 +114,10 @@ class GitHubLdapDomainTest < Minitest::Test
124
114
  end
125
115
  end
126
116
 
117
+ class GitHubLdapDomainTest < GitHub::Ldap::Test
118
+ include GitHubLdapDomainTestCases
119
+ end
120
+
121
+ class GitHubLdapDomainUnauthenticatedTest < GitHub::Ldap::UnauthenticatedTest
122
+ include GitHubLdapDomainTestCases
123
+ end
data/test/ldap_test.rb CHANGED
@@ -1,18 +1,8 @@
1
1
  require 'test_helper'
2
2
 
3
- class GitHubLdapTest < Minitest::Test
3
+ module GitHubLdapTestCases
4
4
  def setup
5
- GitHub::Ldap.start_server
6
-
7
- @options = GitHub::Ldap.server_options.merge \
8
- host: 'localhost',
9
- uid: 'uid'
10
-
11
- @ldap = GitHub::Ldap.new(@options)
12
- end
13
-
14
- def teardown
15
- GitHub::Ldap.stop_server
5
+ @ldap = GitHub::Ldap.new(options)
16
6
  end
17
7
 
18
8
  def test_connection_with_default_options
@@ -32,7 +22,7 @@ class GitHubLdapTest < Minitest::Test
32
22
  end
33
23
 
34
24
  def test_search_delegator
35
- user = @ldap.domain('dc=github,dc=com').valid_login? 'calavera', 'secret'
25
+ @ldap.domain('dc=github,dc=com').valid_login? 'calavera', 'secret'
36
26
 
37
27
  result = @ldap.search(
38
28
  {:base => 'dc=github,dc=com',
@@ -42,3 +32,11 @@ class GitHubLdapTest < Minitest::Test
42
32
  assert_equal 'calavera', result.first[:uid].first
43
33
  end
44
34
  end
35
+
36
+ class GitHubLdapTest < GitHub::Ldap::Test
37
+ include GitHubLdapTestCases
38
+ end
39
+
40
+ class GitHubLdapUnauthenticatedTest < GitHub::Ldap::UnauthenticatedTest
41
+ include GitHubLdapTestCases
42
+ end
data/test/test_helper.rb CHANGED
@@ -8,3 +8,37 @@ require 'github/ldap'
8
8
  require 'github/ldap/server'
9
9
 
10
10
  require 'minitest/autorun'
11
+
12
+ class GitHub::Ldap::Test < Minitest::Test
13
+ def self.run(reporter, options = {})
14
+ start_server
15
+ super
16
+ stop_server
17
+ end
18
+
19
+ def self.stop_server
20
+ GitHub::Ldap.stop_server
21
+ end
22
+
23
+ def self.start_server
24
+ GitHub::Ldap.start_server
25
+ end
26
+
27
+ def options
28
+ @options ||= GitHub::Ldap.server_options.merge \
29
+ host: 'localhost',
30
+ uid: 'uid'
31
+ end
32
+ end
33
+
34
+ class GitHub::Ldap::UnauthenticatedTest < GitHub::Ldap::Test
35
+ def self.start_server
36
+ GitHub::Ldap.start_server(:allow_anonymous => true)
37
+ end
38
+
39
+ def options
40
+ @options ||= begin
41
+ super.delete_if {|k, _| [:admin_user, :admin_password].include?(k)}
42
+ end
43
+ end
44
+ 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.11
4
+ version: 1.0.12
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-07-29 00:00:00.000000000 Z
12
+ date: 2013-08-19 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: net-ldap
@@ -144,4 +144,3 @@ test_files:
144
144
  - test/filter_test.rb
145
145
  - test/ldap_test.rb
146
146
  - test/test_helper.rb
147
- has_rdoc: