debian-mirror-gitlab/spec/lib/gitlab/auth/o_auth/provider_spec.rb

95 lines
2.5 KiB
Ruby
Raw Normal View History

2019-10-12 21:52:04 +05:30
# frozen_string_literal: true
2017-09-10 17:25:29 +05:30
require 'spec_helper'
2020-07-28 23:09:34 +05:30
RSpec.describe Gitlab::Auth::OAuth::Provider do
2018-11-18 11:00:15 +05:30
describe '.enabled?' do
before do
allow(described_class).to receive(:providers).and_return([:ldapmain, :google_oauth2])
end
context 'when OmniAuth is disabled' do
before do
allow(Gitlab::Auth).to receive(:omniauth_enabled?).and_return(false)
end
it 'allows database auth' do
expect(described_class.enabled?('database')).to be_truthy
end
it 'allows LDAP auth' do
expect(described_class.enabled?('ldapmain')).to be_truthy
end
it 'does not allow other OmniAuth providers' do
expect(described_class.enabled?('google_oauth2')).to be_falsey
end
end
context 'when OmniAuth is enabled' do
before do
allow(Gitlab::Auth).to receive(:omniauth_enabled?).and_return(true)
end
it 'allows database auth' do
expect(described_class.enabled?('database')).to be_truthy
end
it 'allows LDAP auth' do
expect(described_class.enabled?('ldapmain')).to be_truthy
end
it 'allows other OmniAuth providers' do
expect(described_class.enabled?('google_oauth2')).to be_truthy
end
end
end
2017-09-10 17:25:29 +05:30
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(
2020-05-24 23:13:21 +05:30
name: 'google_oauth2',
2017-09-10 17:25:29 +05:30
app_id: 'asd123',
app_secret: 'asd123'
)
allow(Gitlab.config.omniauth).to receive(:providers).and_return([provider])
end
context 'when the provider exists' do
2020-05-24 23:13:21 +05:30
subject { described_class.config_for('google_oauth2') }
2017-09-10 17:25:29 +05:30
it 'returns the config' do
2020-05-24 23:13:21 +05:30
expect(subject).to be_a(OpenStruct)
end
it 'merges defaults with the given configuration' do
defaults = Gitlab::OmniauthInitializer.default_arguments_for('google_oauth2').deep_stringify_keys
expect(subject['args']).to include(defaults)
2017-09-10 17:25:29 +05:30
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