From 311b0269b4eb9839fa63f80c8d7a58f32b8138a0 Mon Sep 17 00:00:00 2001 From: GitLab Bot Date: Thu, 18 Nov 2021 13:16:36 +0000 Subject: Add latest changes from gitlab-org/gitlab@14-5-stable-ee --- spec/initializers/0_postgresql_types_spec.rb | 16 +++++++ .../initializers/100_patch_omniauth_oauth2_spec.rb | 45 +++++--------------- spec/initializers/carrierwave_patch_spec.rb | 3 -- spec/initializers/database_config_spec.rb | 49 ++-------------------- spec/initializers/session_store_spec.rb | 37 ++++++++++++++++ 5 files changed, 68 insertions(+), 82 deletions(-) create mode 100644 spec/initializers/0_postgresql_types_spec.rb create mode 100644 spec/initializers/session_store_spec.rb (limited to 'spec/initializers') diff --git a/spec/initializers/0_postgresql_types_spec.rb b/spec/initializers/0_postgresql_types_spec.rb new file mode 100644 index 00000000000..76b243033d0 --- /dev/null +++ b/spec/initializers/0_postgresql_types_spec.rb @@ -0,0 +1,16 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe 'PostgreSQL registered types' do + subject(:types) { ApplicationRecord.connection.send(:type_map).keys } + + # These can be obtained via SELECT oid, typname from pg_type + it 'includes custom and standard OIDs' do + expect(types).to include(28, 194, 1034, 3220, 23, 20) + end + + it 'includes custom and standard types' do + expect(types).to include('xid', 'pg_node_tree', '_aclitem', 'pg_lsn', 'int4', 'int8') + end +end diff --git a/spec/initializers/100_patch_omniauth_oauth2_spec.rb b/spec/initializers/100_patch_omniauth_oauth2_spec.rb index 0c436e4ef45..c30a1cdeafa 100644 --- a/spec/initializers/100_patch_omniauth_oauth2_spec.rb +++ b/spec/initializers/100_patch_omniauth_oauth2_spec.rb @@ -2,12 +2,10 @@ require 'spec_helper' -RSpec.describe 'OmniAuth::Strategies::OAuth2', type: :strategy do - let(:strategy) { [OmniAuth::Strategies::OAuth2] } - +RSpec.describe 'OmniAuth::Strategies::OAuth2' do it 'verifies the gem version' do current_version = OmniAuth::OAuth2::VERSION - expected_version = '1.7.1' + expected_version = '1.7.2' expect(current_version).to eq(expected_version), <<~EOF New version #{current_version} of the `omniauth-oauth2` gem detected! @@ -18,39 +16,18 @@ RSpec.describe 'OmniAuth::Strategies::OAuth2', type: :strategy do EOF end - context 'when a custom error message is passed from an OAuth2 provider' do - let(:message) { 'Please go to https://evil.com' } - let(:state) { 'secret' } - let(:callback_path) { '/users/auth/oauth2/callback' } - let(:params) { { state: state, error: 'evil_key', error_description: message } } - let(:error) { last_request.env['omniauth.error'] } - - before do - env('rack.session', { 'omniauth.state' => state }) - end - - it 'returns the custom error message if the state is valid' do - get callback_path, **params - - expect(error.message).to eq("evil_key | #{message}") - end + context 'when a Faraday exception is raised' do + where(exception: [Faraday::TimeoutError, Faraday::ConnectionFailed]) - it 'returns the custom `error_reason` message if the `error_description` is blank' do - get callback_path, **params.merge(error_description: ' ', error_reason: 'custom reason') - - expect(error.message).to eq('evil_key | custom reason') - end - - it 'returns a CSRF error if the state is invalid' do - get callback_path, **params.merge(state: 'invalid') - - expect(error.message).to eq('csrf_detected | CSRF detected') - end + with_them do + it 'passes the exception to OmniAuth' do + instance = OmniAuth::Strategies::OAuth2.new(double) - it 'returns a CSRF error if the state is missing' do - get callback_path, **params.without(:state) + expect(instance).to receive(:original_callback_phase) { raise exception, 'message' } + expect(instance).to receive(:fail!).with(:timeout, kind_of(exception)) - expect(error.message).to eq('csrf_detected | CSRF detected') + instance.callback_phase + end end end end diff --git a/spec/initializers/carrierwave_patch_spec.rb b/spec/initializers/carrierwave_patch_spec.rb index e219db2299d..b0f337935ef 100644 --- a/spec/initializers/carrierwave_patch_spec.rb +++ b/spec/initializers/carrierwave_patch_spec.rb @@ -15,9 +15,6 @@ RSpec.describe 'CarrierWave::Storage::Fog::File' do subject { CarrierWave::Storage::Fog::File.new(uploader, storage, test_filename) } before do - require 'fog/azurerm' - require 'fog/aws' - stub_object_storage(connection_params: connection_options, remote_directory: bucket_name) allow(uploader).to receive(:fog_directory).and_return(bucket_name) diff --git a/spec/initializers/database_config_spec.rb b/spec/initializers/database_config_spec.rb index 23f7fd06254..230f1296760 100644 --- a/spec/initializers/database_config_spec.rb +++ b/spec/initializers/database_config_spec.rb @@ -7,56 +7,15 @@ RSpec.describe 'Database config initializer', :reestablished_active_record_base load Rails.root.join('config/initializers/database_config.rb') end - before do - allow(Gitlab::Runtime).to receive(:max_threads).and_return(max_threads) - end - - let(:max_threads) { 8 } - it 'retains the correct database name for the connection' do - previous_db_name = Gitlab::Database.main.scope.connection.pool.db_config.name + previous_db_name = ApplicationRecord.connection.pool.db_config.name subject - expect(Gitlab::Database.main.scope.connection.pool.db_config.name).to eq(previous_db_name) + expect(ApplicationRecord.connection.pool.db_config.name).to eq(previous_db_name) end - context 'when no custom headroom is specified' do - it 'sets the pool size based on the number of worker threads' do - old = ActiveRecord::Base.connection_db_config.pool - - expect(old).not_to eq(18) - - expect { subject } - .to change { ActiveRecord::Base.connection_db_config.pool } - .from(old) - .to(18) - end - - it 'overwrites custom pool settings' do - config = Gitlab::Database.main.config.merge(pool: 42) - - allow(Gitlab::Database.main).to receive(:config).and_return(config) - subject - - expect(ActiveRecord::Base.connection_db_config.pool).to eq(18) - end - end - - context "when specifying headroom through an ENV variable" do - let(:headroom) { 15 } - - before do - stub_env("DB_POOL_HEADROOM", headroom) - end - - it "adds headroom on top of the calculated size" do - old = ActiveRecord::Base.connection_db_config.pool - - expect { subject } - .to change { ActiveRecord::Base.connection_db_config.pool } - .from(old) - .to(23) - end + it 'does not overwrite custom pool settings' do + expect { subject }.not_to change { ActiveRecord::Base.connection_db_config.pool } end end diff --git a/spec/initializers/session_store_spec.rb b/spec/initializers/session_store_spec.rb new file mode 100644 index 00000000000..3da52ccc981 --- /dev/null +++ b/spec/initializers/session_store_spec.rb @@ -0,0 +1,37 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe 'Session initializer for GitLab' do + subject { Gitlab::Application.config } + + let(:load_session_store) do + load Rails.root.join('config/initializers/session_store.rb') + end + + describe 'config#session_store' do + context 'when the GITLAB_REDIS_STORE_WITH_SESSION_STORE env is not set' do + before do + stub_env('GITLAB_REDIS_STORE_WITH_SESSION_STORE', nil) + end + + it 'initialized as a redis_store with a proper Redis::Store instance' do + expect(subject).to receive(:session_store).with(:redis_store, a_hash_including(redis_store: kind_of(::Redis::Store))) + + load_session_store + end + end + + context 'when the GITLAB_REDIS_STORE_WITH_SESSION_STORE env is disabled' do + before do + stub_env('GITLAB_REDIS_STORE_WITH_SESSION_STORE', false) + end + + it 'initialized as a redis_store with a proper servers configuration' do + expect(subject).to receive(:session_store).with(:redis_store, a_hash_including(servers: kind_of(Hash))) + + load_session_store + end + end + end +end -- cgit v1.2.3