summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJacob Vosmaer <contact@jacobvosmaer.nl>2014-10-23 22:57:16 +0200
committerValery Sizov <valery@gitlab.com>2014-10-24 12:53:32 +0300
commit16a10eb1cd4a5447da9d50b1eba25f020dc8f6b7 (patch)
tree83c5a6a7569b4189bbc3b59f9001a2759d769fb8
parent5f7906e1635baa1aca12527ac9d9f8e84323e95d (diff)
downloadgitlab-ce-16a10eb1cd4a5447da9d50b1eba25f020dc8f6b7.tar.gz
Fix LDAP config lookup for provider 'ldap'
-rw-r--r--CHANGELOG1
-rw-r--r--lib/gitlab/ldap/config.rb27
-rw-r--r--spec/lib/gitlab/ldap/config_spec.rb16
3 files changed, 32 insertions, 12 deletions
diff --git a/CHANGELOG b/CHANGELOG
index 561a23538e7..5a494cccc69 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -1,5 +1,6 @@
v 7.4.1
- Fix LDAP authentication for Git HTTP access
+ - Fix LDAP config lookup for provider 'ldap'
v 7.4.0
- Refactored membership logic
diff --git a/lib/gitlab/ldap/config.rb b/lib/gitlab/ldap/config.rb
index d41bfba9b0f..0cb24d0ccc1 100644
--- a/lib/gitlab/ldap/config.rb
+++ b/lib/gitlab/ldap/config.rb
@@ -16,10 +16,23 @@ module Gitlab
servers.map {|server| server['provider_name'] }
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)
- @provider = provider
- invalid_provider unless valid_provider?
- @options = config_for(provider)
+ if self.class.valid_provider?(provider)
+ @provider = 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
def enabled?
@@ -89,14 +102,6 @@ module Gitlab
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
{
auth: {
diff --git a/spec/lib/gitlab/ldap/config_spec.rb b/spec/lib/gitlab/ldap/config_spec.rb
index 76cc7f95c47..3ebb8aae243 100644
--- a/spec/lib/gitlab/ldap/config_spec.rb
+++ b/spec/lib/gitlab/ldap/config_spec.rb
@@ -16,5 +16,19 @@ describe Gitlab::LDAP::Config do
it "raises an error if a unknow provider is used" do
expect{ Gitlab::LDAP::Config.new 'unknown' }.to raise_error
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 \ No newline at end of file
+end