diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2023-12-21 00:16:25 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2023-12-21 00:16:25 +0300 |
commit | faf60c19a9a1a29ce07d1b51ea3a69466e7129f3 (patch) | |
tree | 8ba3c836fd5ce4431e83301cefe9d9c0c9827c10 /spec/support | |
parent | 054c9f71bc79eea35d482c4c53bff34214c5deaa (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/support')
4 files changed, 21 insertions, 22 deletions
diff --git a/spec/support/helpers/admin_mode_helpers.rb b/spec/support/helpers/admin_mode_helpers.rb index 8b71552f928..a6e31791127 100644 --- a/spec/support/helpers/admin_mode_helpers.rb +++ b/spec/support/helpers/admin_mode_helpers.rb @@ -5,30 +5,17 @@ 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 - # 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. + # be in admin mode without requiring a second authentication step (provided + # the user is an admin) # # See also tag :enable_admin_mode in spec/spec_helper.rb for a spec-wide # alternative - 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) + def enable_admin_mode!(user) + 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?) - end + 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 diff --git a/spec/support/helpers/login_helpers.rb b/spec/support/helpers/login_helpers.rb index ff1c528d94a..0cdddeaa84a 100644 --- a/spec/support/helpers/login_helpers.rb +++ b/spec/support/helpers/login_helpers.rb @@ -49,6 +49,18 @@ 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 678199a35ea..c740917cec4 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) - enable_admin_mode!(user) + gitlab_enable_admin_mode_sign_in(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 d21e69b72e1..4921676a065 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) - enable_admin_mode!(admin) + gitlab_enable_admin_mode_sign_in(admin) end it 'shows groups where the admin has no direct membership' do |