Commit 8157c6b8 authored by Marin Jankovski's avatar Marin Jankovski

Merge branch 'fix_ldap_config_lookup' into 'master'

Fix LDAP config lookup for provider 'ldap'

See merge request !1213
parents 1c1d9f78 472a6621
...@@ -2,6 +2,7 @@ v 7.5.0 ...@@ -2,6 +2,7 @@ v 7.5.0
- API: Add support for Hipchat (Kevin Houdebert) - API: Add support for Hipchat (Kevin Houdebert)
- Add time zone configuration on gitlab.yml (Sullivan Senechal) - Add time zone configuration on gitlab.yml (Sullivan Senechal)
- Fix LDAP authentication for Git HTTP access - Fix LDAP authentication for Git HTTP access
- Fix LDAP config lookup for provider 'ldap'
v 7.4.0 v 7.4.0
- Refactored membership logic - Refactored membership logic
......
...@@ -16,10 +16,23 @@ module Gitlab ...@@ -16,10 +16,23 @@ module Gitlab
servers.map {|server| server['provider_name'] } servers.map {|server| server['provider_name'] }
end end
def self.valid_provider?(provider)
providers.include?(provider)
end
def self.invalid_provider(provider)
raise "Unknown provider (#{provider}). Available providers: #{providers}"
end
def initialize(provider) def initialize(provider)
@provider = provider if self.class.valid_provider?(provider)
invalid_provider unless valid_provider? @provider = provider
@options = config_for(provider) elsif provider == 'ldap'
@provider = self.class.providers.first
else
self.class.invalid_provider(provider)
end
@options = config_for(@provider) # Use @provider, not provider
end end
def enabled? def enabled?
...@@ -89,14 +102,6 @@ module Gitlab ...@@ -89,14 +102,6 @@ module Gitlab
end end
end end
def valid_provider?
self.class.providers.include?(provider)
end
def invalid_provider
raise "Unknown provider (#{provider}). Available providers: #{self.class.providers}"
end
def auth_options def auth_options
{ {
auth: { auth: {
......
...@@ -16,5 +16,19 @@ describe Gitlab::LDAP::Config do ...@@ -16,5 +16,19 @@ describe Gitlab::LDAP::Config do
it "raises an error if a unknow provider is used" do it "raises an error if a unknow provider is used" do
expect{ Gitlab::LDAP::Config.new 'unknown' }.to raise_error expect{ Gitlab::LDAP::Config.new 'unknown' }.to raise_error
end end
context "if 'ldap' is the provider name" do
let(:provider) { 'ldap' }
context "and 'ldap' is not in defined as a provider" do
before { Gitlab::LDAP::Config.stub(providers: %w{ldapmain}) }
it "uses the first provider" do
# Fetch the provider_name attribute from 'options' so that we know
# that the 'options' Hash is not empty/nil.
expect(config.options['provider_name']).to eq('ldapmain')
end
end
end
end end
end end
\ No newline at end of file
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment