From c60010859638f577dab891358e83945561b35ad2 Mon Sep 17 00:00:00 2001 From: GitLab Bot Date: Fri, 22 Dec 2023 15:12:49 +0000 Subject: Add latest changes from gitlab-org/gitlab@master --- spec/support/helpers/admin_mode_helpers.rb | 27 ++++++++++++---- spec/support/helpers/login_helpers.rb | 12 ------- .../instance_integrations_shared_context.rb | 2 +- .../features/inviting_groups_shared_examples.rb | 2 +- .../redis/redis_new_instance_shared_examples.rb | 37 ++++++++++++++++++++++ .../shared_examples/redis/redis_shared_examples.rb | 4 +++ 6 files changed, 63 insertions(+), 21 deletions(-) (limited to 'spec/support') diff --git a/spec/support/helpers/admin_mode_helpers.rb b/spec/support/helpers/admin_mode_helpers.rb index a6e31791127..8b71552f928 100644 --- a/spec/support/helpers/admin_mode_helpers.rb +++ b/spec/support/helpers/admin_mode_helpers.rb @@ -5,17 +5,30 @@ module AdminModeHelper # Administrators are logged in by default in user mode and have to switch to admin # mode for accessing any administrative functionality. This helper lets a user - # be in admin mode without requiring a second authentication step (provided - # the user is an admin) + # access the admin area in two different ways: + # + # * Fast (use_ui: false) and suitable form the most use cases: fakes calls and grants + # access to the admin area without requiring a second authentication step (provided the + # user is an admin) + # * Slow (use_ui: true): visits the admin UI and enters the users password. A second + # authentication step may be needed. # # See also tag :enable_admin_mode in spec/spec_helper.rb for a spec-wide # alternative - def enable_admin_mode!(user) - fake_user_mode = instance_double(Gitlab::Auth::CurrentUserMode) + def enable_admin_mode!(user, use_ui: false) + if use_ui + visit new_admin_session_path + fill_in 'user_password', with: user.password + click_button 'Enter admin mode' + + wait_for_requests + else + fake_user_mode = instance_double(Gitlab::Auth::CurrentUserMode) - allow(Gitlab::Auth::CurrentUserMode).to receive(:new).and_call_original + allow(Gitlab::Auth::CurrentUserMode).to receive(:new).and_call_original - allow(Gitlab::Auth::CurrentUserMode).to receive(:new).with(user).and_return(fake_user_mode) - allow(fake_user_mode).to receive(:admin_mode?).and_return(user&.admin?) + allow(Gitlab::Auth::CurrentUserMode).to receive(:new).with(user).and_return(fake_user_mode) + allow(fake_user_mode).to receive(:admin_mode?).and_return(user&.admin?) + end end end diff --git a/spec/support/helpers/login_helpers.rb b/spec/support/helpers/login_helpers.rb index 0cdddeaa84a..ff1c528d94a 100644 --- a/spec/support/helpers/login_helpers.rb +++ b/spec/support/helpers/login_helpers.rb @@ -49,18 +49,6 @@ module LoginHelpers @current_user = user end - def gitlab_enable_admin_mode_sign_in(user, use_mock_admin_mode: true) - if use_mock_admin_mode - enable_admin_mode!(user) - else - visit new_admin_session_path - fill_in 'user_password', with: user.password - click_button 'Enter admin mode' - - wait_for_requests - end - end - def gitlab_sign_in_via(provider, user, uid, saml_response = nil) mock_auth_hash_with_saml_xml(provider, uid, user.email, saml_response) visit new_user_session_path diff --git a/spec/support/shared_contexts/features/integrations/instance_integrations_shared_context.rb b/spec/support/shared_contexts/features/integrations/instance_integrations_shared_context.rb index c740917cec4..678199a35ea 100644 --- a/spec/support/shared_contexts/features/integrations/instance_integrations_shared_context.rb +++ b/spec/support/shared_contexts/features/integrations/instance_integrations_shared_context.rb @@ -7,7 +7,7 @@ RSpec.shared_context 'instance integration activation' do before do sign_in(user) - gitlab_enable_admin_mode_sign_in(user) + enable_admin_mode!(user) end def visit_instance_integrations diff --git a/spec/support/shared_examples/features/inviting_groups_shared_examples.rb b/spec/support/shared_examples/features/inviting_groups_shared_examples.rb index 4921676a065..d21e69b72e1 100644 --- a/spec/support/shared_examples/features/inviting_groups_shared_examples.rb +++ b/spec/support/shared_examples/features/inviting_groups_shared_examples.rb @@ -9,7 +9,7 @@ RSpec.shared_examples 'inviting groups search results' do before do sign_in(admin) - gitlab_enable_admin_mode_sign_in(admin) + enable_admin_mode!(admin) end it 'shows groups where the admin has no direct membership' do diff --git a/spec/support/shared_examples/redis/redis_new_instance_shared_examples.rb b/spec/support/shared_examples/redis/redis_new_instance_shared_examples.rb index 4a3732efe13..9b774449379 100644 --- a/spec/support/shared_examples/redis/redis_new_instance_shared_examples.rb +++ b/spec/support/shared_examples/redis/redis_new_instance_shared_examples.rb @@ -15,6 +15,37 @@ RSpec.shared_examples "redis_new_instance_shared_examples" do |name, fallback_cl it_behaves_like "redis_shared_examples" + describe '.pool' do + before do + allow(described_class).to receive(:config_file_name).and_call_original + allow(fallback_class).to receive(:params).and_return({}) + + clear_class_pool(described_class) + clear_class_pool(fallback_class) + end + + after do + clear_class_pool(described_class) + clear_class_pool(fallback_class) + end + + context 'when not using fallback config' do + it 'creates its own connection pool' do + expect(fallback_class.pool == described_class.pool).to eq(false) + end + end + + context 'when using fallback config' do + before do + allow(described_class).to receive(:params).and_return({}) + end + + it 'uses the fallback class connection pool' do + expect(fallback_class.pool == described_class.pool).to eq(true) + end + end + end + describe '#fetch_config' do subject { described_class.new('test').send(:fetch_config) } @@ -81,4 +112,10 @@ RSpec.shared_examples "redis_new_instance_shared_examples" do |name, fallback_cl end end end + + def clear_class_pool(klass) + klass.remove_instance_variable(:@pool) + rescue NameError + # raised if @pool was not set; ignore + end end diff --git a/spec/support/shared_examples/redis/redis_shared_examples.rb b/spec/support/shared_examples/redis/redis_shared_examples.rb index 1e30df2af09..4929a753829 100644 --- a/spec/support/shared_examples/redis/redis_shared_examples.rb +++ b/spec/support/shared_examples/redis/redis_shared_examples.rb @@ -217,6 +217,10 @@ RSpec.shared_examples "redis_shared_examples" do clear_pool end + it 'yields a ::Redis' do + described_class.with { |conn| expect(conn).to be_instance_of(::Redis) } + end + context 'when running on single-threaded runtime' do before do allow(Gitlab::Runtime).to receive(:multi_threaded?).and_return(false) -- cgit v1.2.3