Commit 6226d19c authored by Rémy Coutable's avatar Rémy Coutable

Minimize CE/EE difference in Gitlab::Auth::LDAP::Config

Signed-off-by: default avatarRémy Coutable <remy@rymai.me>
parent 8b287679
...@@ -11,6 +11,8 @@ module Gitlab ...@@ -11,6 +11,8 @@ module Gitlab
attr_accessor :provider, :options attr_accessor :provider, :options
InvalidProvider = Class.new(StandardError)
def self.enabled? def self.enabled?
Gitlab.config.ldap.enabled Gitlab.config.ldap.enabled
end end
...@@ -22,6 +24,10 @@ module Gitlab ...@@ -22,6 +24,10 @@ module Gitlab
def self.available_servers def self.available_servers
return [] unless enabled? return [] unless enabled?
_available_servers
end
def self._available_servers
Array.wrap(servers.first) Array.wrap(servers.first)
end end
...@@ -34,7 +40,7 @@ module Gitlab ...@@ -34,7 +40,7 @@ module Gitlab
end end
def self.invalid_provider(provider) def self.invalid_provider(provider)
raise "Unknown provider (#{provider}). Available providers: #{providers}" raise InvalidProvider.new("Unknown provider (#{provider}). Available providers: #{providers}")
end end
def initialize(provider) def initialize(provider)
...@@ -84,13 +90,17 @@ module Gitlab ...@@ -84,13 +90,17 @@ module Gitlab
end end
def base def base
options['base'] @base ||= Person.normalize_dn(options['base'])
end end
def uid def uid
options['uid'] options['uid']
end end
def label
options['label']
end
def sync_ssh_keys? def sync_ssh_keys?
sync_ssh_keys.present? sync_ssh_keys.present?
end end
...@@ -132,6 +142,10 @@ module Gitlab ...@@ -132,6 +142,10 @@ module Gitlab
options['timeout'].to_i options['timeout'].to_i
end end
def external_groups
options['external_groups'] || []
end
def has_auth? def has_auth?
options['password'] || options['bind_dn'] options['password'] || options['bind_dn']
end end
......
...@@ -23,7 +23,7 @@ describe Gitlab::Auth::LDAP::Config do ...@@ -23,7 +23,7 @@ describe Gitlab::Auth::LDAP::Config do
end end
it 'raises an error if a unknown provider is used' do it 'raises an error if a unknown provider is used' do
expect { described_class.new 'unknown' }.to raise_error(RuntimeError) expect { described_class.new 'unknown' }.to raise_error(described_class::InvalidProvider)
end end
end end
...@@ -370,4 +370,38 @@ describe Gitlab::Auth::LDAP::Config do ...@@ -370,4 +370,38 @@ describe Gitlab::Auth::LDAP::Config do
}) })
end end
end end
describe '#base' do
context 'when the configured base is not normalized' do
it 'returns the normalized base' do
stub_ldap_config(options: { 'base' => 'DC=example, DC= com' })
expect(config.base).to eq('dc=example,dc=com')
end
end
context 'when the configured base is normalized' do
it 'returns the base unaltered' do
stub_ldap_config(options: { 'base' => 'dc=example,dc=com' })
expect(config.base).to eq('dc=example,dc=com')
end
end
context 'when the configured base is malformed' do
it 'returns the base unaltered' do
stub_ldap_config(options: { 'base' => 'invalid,dc=example,dc=com' })
expect(config.base).to eq('invalid,dc=example,dc=com')
end
end
context 'when the configured base is blank' do
it 'returns the base unaltered' do
stub_ldap_config(options: { 'base' => '' })
expect(config.base).to eq('')
end
end
end
end end
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