Merge branch 'dm-oauth-config-for' into 'master'
Return nil when looking up config for unknown LDAP provider Closes #29342 See merge request !11804
This commit is contained in:
commit
228926daee
3 changed files with 51 additions and 1 deletions
4
changelogs/unreleased/dm-oauth-config-for.yml
Normal file
4
changelogs/unreleased/dm-oauth-config-for.yml
Normal file
|
@ -0,0 +1,4 @@
|
|||
---
|
||||
title: Return nil when looking up config for unknown LDAP provider
|
||||
merge_request:
|
||||
author:
|
|
@ -22,7 +22,11 @@ module Gitlab
|
|||
def self.config_for(name)
|
||||
name = name.to_s
|
||||
if ldap_provider?(name)
|
||||
Gitlab::LDAP::Config.new(name).options
|
||||
if Gitlab::LDAP::Config.valid_provider?(name)
|
||||
Gitlab::LDAP::Config.new(name).options
|
||||
else
|
||||
nil
|
||||
end
|
||||
else
|
||||
Gitlab.config.omniauth.providers.find { |provider| provider.name == name }
|
||||
end
|
||||
|
|
42
spec/lib/gitlab/o_auth/provider_spec.rb
Normal file
42
spec/lib/gitlab/o_auth/provider_spec.rb
Normal file
|
@ -0,0 +1,42 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe Gitlab::OAuth::Provider, lib: true do
|
||||
describe '#config_for' do
|
||||
context 'for an LDAP provider' do
|
||||
context 'when the provider exists' do
|
||||
it 'returns the config' do
|
||||
expect(described_class.config_for('ldapmain')).to be_a(Hash)
|
||||
end
|
||||
end
|
||||
|
||||
context 'when the provider does not exist' do
|
||||
it 'returns nil' do
|
||||
expect(described_class.config_for('ldapfoo')).to be_nil
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context 'for an OmniAuth provider' do
|
||||
before do
|
||||
provider = OpenStruct.new(
|
||||
name: 'google',
|
||||
app_id: 'asd123',
|
||||
app_secret: 'asd123'
|
||||
)
|
||||
allow(Gitlab.config.omniauth).to receive(:providers).and_return([provider])
|
||||
end
|
||||
|
||||
context 'when the provider exists' do
|
||||
it 'returns the config' do
|
||||
expect(described_class.config_for('google')).to be_a(OpenStruct)
|
||||
end
|
||||
end
|
||||
|
||||
context 'when the provider does not exist' do
|
||||
it 'returns nil' do
|
||||
expect(described_class.config_for('foo')).to be_nil
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Reference in a new issue