Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'spec/support/helpers/admin_mode_helpers.rb')
-rw-r--r--spec/support/helpers/admin_mode_helpers.rb27
1 files changed, 20 insertions, 7 deletions
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