Allow unauthenticated connections.
This commit is contained in:
Родитель
4deee29a2d
Коммит
536dbbf912
|
@ -28,11 +28,14 @@ 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.
|
||||
* admin_user: is the the ldap administrator user. Required to perform search operation.
|
||||
* admin_password: is the password for the administrator user. Simple authentication is required on the server.
|
||||
* 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`.
|
||||
|
||||
Using administrator credentials is optional but recommended. You can pass those credentials with these two options:
|
||||
|
||||
* admin_user: is the the ldap administrator user dn.
|
||||
* admin_password: is the password for the administrator user.
|
||||
|
||||
Initialize a new adapter using those required options:
|
||||
|
||||
```ruby
|
||||
|
|
|
@ -26,7 +26,9 @@ module GitHub
|
|||
|
||||
@connection = Net::LDAP.new({host: options[:host], port: options[:port]})
|
||||
|
||||
@connection.authenticate(options[:admin_user], options[:admin_password])
|
||||
if options[:admin_user] && options[:admin_password]
|
||||
@connection.authenticate(options[:admin_user], options[:admin_password])
|
||||
end
|
||||
|
||||
if encryption = check_encryption(options[:encryption])
|
||||
@connection.encryption(encryption)
|
||||
|
|
|
@ -33,10 +33,10 @@ module GitHub
|
|||
def self.start_server(options = {})
|
||||
@server_options = DEFAULT_SERVER_OPTIONS.merge(options)
|
||||
|
||||
@server_options[:allow_anonymous] = false
|
||||
@server_options[:ldif] = @server_options[:user_fixtures]
|
||||
@server_options[:domain] = @server_options[:user_domain]
|
||||
@server_options[:tmpdir] ||= server_tmp
|
||||
@server_options[:allow_anonymous] ||= false
|
||||
@server_options[:ldif] = @server_options[:user_fixtures]
|
||||
@server_options[:domain] = @server_options[:user_domain]
|
||||
@server_options[:tmpdir] ||= server_tmp
|
||||
|
||||
@ldap_server = Ladle::Server.new(@server_options)
|
||||
@ldap_server.start
|
||||
|
|
|
@ -1,18 +1,8 @@
|
|||
require 'test_helper'
|
||||
|
||||
class GitHubLdapDomainTest < Minitest::Test
|
||||
module GitHubLdapDomainTestCases
|
||||
def setup
|
||||
GitHub::Ldap.start_server
|
||||
|
||||
@options = GitHub::Ldap.server_options.merge \
|
||||
host: 'localhost',
|
||||
uid: 'uid'
|
||||
|
||||
@domain = GitHub::Ldap.new(@options).domain("dc=github,dc=com")
|
||||
end
|
||||
|
||||
def teardown
|
||||
GitHub::Ldap.stop_server
|
||||
@domain = GitHub::Ldap.new(options).domain("dc=github,dc=com")
|
||||
end
|
||||
|
||||
def test_user_valid_login
|
||||
|
@ -124,3 +114,10 @@ class GitHubLdapDomainTest < Minitest::Test
|
|||
end
|
||||
end
|
||||
|
||||
class GitHubLdapDomainTest < GitHub::Ldap::Test
|
||||
include GitHubLdapDomainTestCases
|
||||
end
|
||||
|
||||
class GitHubLdapDomainUnauthenticatedTest < GitHub::Ldap::UnauthenticatedTest
|
||||
include GitHubLdapDomainTestCases
|
||||
end
|
||||
|
|
|
@ -1,18 +1,8 @@
|
|||
require 'test_helper'
|
||||
|
||||
class GitHubLdapTest < Minitest::Test
|
||||
module GitHubLdapTestCases
|
||||
def setup
|
||||
GitHub::Ldap.start_server
|
||||
|
||||
@options = GitHub::Ldap.server_options.merge \
|
||||
host: 'localhost',
|
||||
uid: 'uid'
|
||||
|
||||
@ldap = GitHub::Ldap.new(@options)
|
||||
end
|
||||
|
||||
def teardown
|
||||
GitHub::Ldap.stop_server
|
||||
@ldap = GitHub::Ldap.new(options)
|
||||
end
|
||||
|
||||
def test_connection_with_default_options
|
||||
|
@ -32,7 +22,7 @@ class GitHubLdapTest < Minitest::Test
|
|||
end
|
||||
|
||||
def test_search_delegator
|
||||
user = @ldap.domain('dc=github,dc=com').valid_login? 'calavera', 'secret'
|
||||
@ldap.domain('dc=github,dc=com').valid_login? 'calavera', 'secret'
|
||||
|
||||
result = @ldap.search(
|
||||
{:base => 'dc=github,dc=com',
|
||||
|
@ -42,3 +32,11 @@ class GitHubLdapTest < Minitest::Test
|
|||
assert_equal 'calavera', result.first[:uid].first
|
||||
end
|
||||
end
|
||||
|
||||
class GitHubLdapTest < GitHub::Ldap::Test
|
||||
include GitHubLdapTestCases
|
||||
end
|
||||
|
||||
class GitHubLdapUnauthenticatedTest < GitHub::Ldap::Test
|
||||
include GitHubLdapTestCases
|
||||
end
|
||||
|
|
|
@ -8,3 +8,37 @@ require 'github/ldap'
|
|||
require 'github/ldap/server'
|
||||
|
||||
require 'minitest/autorun'
|
||||
|
||||
class GitHub::Ldap::Test < Minitest::Test
|
||||
def self.run(reporter, options = {})
|
||||
start_server
|
||||
super
|
||||
stop_server
|
||||
end
|
||||
|
||||
def self.stop_server
|
||||
GitHub::Ldap.stop_server
|
||||
end
|
||||
|
||||
def self.start_server
|
||||
GitHub::Ldap.start_server
|
||||
end
|
||||
|
||||
def options
|
||||
@options ||= GitHub::Ldap.server_options.merge \
|
||||
host: 'localhost',
|
||||
uid: 'uid'
|
||||
end
|
||||
end
|
||||
|
||||
class GitHub::Ldap::UnauthenticatedTest < GitHub::Ldap::Test
|
||||
def self.start_server
|
||||
GitHub::Ldap.start_server(:allow_anonymous => true)
|
||||
end
|
||||
|
||||
def options
|
||||
@options ||= begin
|
||||
super.delete_if {|k, _| [:admin_user, :admin_password].include?(k)}
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Загрузка…
Ссылка в новой задаче