Skip to content
Snippets Groups Projects
Commit 03368340 authored by Drew Blessing's avatar Drew Blessing
Browse files

Merge branch 'ldap_failover' into 'master'

Add support for LDAP failover

Add host failover support to this library. It's been supported in Net::LDAP for some time.

See merge request !4
parents 81d2e680 bc9199d2
No related branches found
No related tags found
1 merge request!4Add support for LDAP failover
Pipeline #
image: "ruby:2.3.1"
before_script:
- bundle install
stages:
- test
rspec:
stage: test
script:
- bundle exec rake spec
Loading
Loading
@@ -2,7 +2,7 @@ PATH
remote: .
specs:
gitlab_omniauth-ldap (1.2.1)
net-ldap (~> 0.9)
net-ldap (~> 0.12)
omniauth (~> 1.0)
pyu-ruby-sasl (~> 0.0.3.1)
rubyntlm (~> 0.3)
Loading
Loading
@@ -12,12 +12,12 @@ GEM
specs:
coderay (1.0.8)
diff-lcs (1.1.3)
hashie (3.4.0)
hashie (3.4.4)
method_source (0.8.1)
net-ldap (0.11)
omniauth (1.2.2)
net-ldap (0.15.0)
omniauth (1.3.1)
hashie (>= 1.2, < 4)
rack (~> 1.0)
rack (>= 1.0, < 3)
pry (0.9.10)
coderay (~> 1.0.5)
method_source (~> 0.8)
Loading
Loading
@@ -35,7 +35,7 @@ GEM
rspec-expectations (2.12.1)
diff-lcs (~> 1.1.3)
rspec-mocks (2.12.1)
rubyntlm (0.5.0)
rubyntlm (0.5.2)
slop (3.3.3)
 
PLATFORMS
Loading
Loading
@@ -47,3 +47,6 @@ DEPENDENCIES
rack-test
rake
rspec
BUNDLED WITH
1.12.5
Loading
Loading
@@ -10,7 +10,7 @@ Gem::Specification.new do |gem|
gem.license = "MIT"
 
gem.add_runtime_dependency 'omniauth', '~> 1.0'
gem.add_runtime_dependency 'net-ldap', '~> 0.9'
gem.add_runtime_dependency 'net-ldap', '~> 0.12'
gem.add_runtime_dependency 'pyu-ruby-sasl', '~> 0.0.3.1'
gem.add_runtime_dependency 'rubyntlm', '~> 0.3'
 
Loading
Loading
Loading
Loading
@@ -13,10 +13,19 @@ module OmniAuth
class AuthenticationError < StandardError; end
class ConnectionError < StandardError; end
 
VALID_ADAPTER_CONFIGURATION_KEYS = [:host, :port, :method, :bind_dn, :password, :try_sasl, :sasl_mechanisms, :uid, :base, :allow_anonymous, :filter]
VALID_ADAPTER_CONFIGURATION_KEYS = [
:hosts, :host, :port, :method, :bind_dn, :password, :try_sasl,
:sasl_mechanisms, :uid, :base, :allow_anonymous, :filter
]
 
# A list of needed keys. Possible alternatives are specified using sub-lists.
MUST_HAVE_KEYS = [:host, :port, :method, [:uid, :filter], :base]
MUST_HAVE_KEYS = [
:base,
:method,
[:hosts, :host],
[:hosts, :port],
[:uid, :filter]
]
 
METHOD = {
:ssl => :simple_tls,
Loading
Loading
@@ -47,12 +56,12 @@ module OmniAuth
end
method = ensure_method(@method)
config = {
:host => @host,
:port => @port,
:encryption => method,
:base => @base
base: @base,
hosts: @hosts,
host: @host,
port: @port,
method: @method
}
@bind_method = @try_sasl ? :sasl : (@allow_anonymous||!@bind_dn||!@password ? :anonymous : :simple)
 
 
Loading
Loading
module OmniAuth
module LDAP
VERSION = "1.2.1"
VERSION = "1.3.1"
end
end
require 'spec_helper'
describe "OmniAuth::LDAP::Adaptor" do
describe OmniAuth::LDAP::Adaptor do
 
describe 'initialize' do
it 'should throw exception when must have field is not set' do
Loading
Loading
@@ -7,6 +7,17 @@ describe "OmniAuth::LDAP::Adaptor" do
lambda { OmniAuth::LDAP::Adaptor.new({host: "192.168.1.145", method: 'plain'})}.should raise_error(ArgumentError)
end
 
it 'should not throw an error if hosts is set but host and port are not' do
expect(
described_class.new(
hosts: [['192.168.1.145', 389], ['192.168.1.146', 389]],
method: 'plain',
base: 'dc=example,dc=com',
uid: 'uid'
)
).not_to raise_error(ArgumentError)
end
it 'should throw exception when method is not supported' do
lambda { OmniAuth::LDAP::Adaptor.new({host: "192.168.1.145", method: 'myplain', uid: 'uid', port: 389, base: 'dc=com'})}.should raise_error(OmniAuth::LDAP::Adaptor::ConfigurationError)
end
Loading
Loading
@@ -52,6 +63,33 @@ describe "OmniAuth::LDAP::Adaptor" do
adaptor.connection.instance_variable_get('@auth')[:initial_credential].should =~ /^NTLMSSP/
adaptor.connection.instance_variable_get('@auth')[:challenge_response].should_not be_nil
end
it 'sets up a connection with the proper host and port' do
adapter = described_class.new(
host: '192.168.1.145',
method: 'plain',
base: 'dc=example,dc=com',
port: 3890,
uid: 'uid'
)
expect(adapter.connection.host).to eq('192.168.1.145')
expect(adapter.connection.port).to eq(3890)
expect(adapter.connection.hosts).to be_nil
end
it 'sets up a connection with a enumerable pairs of hosts' do
adapter = described_class.new(
hosts: [['192.168.1.145', 636], ['192.168.1.146', 636]],
method: 'plain',
base: 'dc=example,dc=com',
uid: 'uid'
)
expect(adapter.connection.host).to eq('127.0.0.1')
expect(adapter.connection.port).to eq(389)
expect(adapter.connection.hosts).to match_array([['192.168.1.145', 636], ['192.168.1.146', 636]])
end
end
 
describe 'bind_as' do
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment