summaryrefslogtreecommitdiff
path: root/spec/controllers/application_controller_spec.rb
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2019-09-26 12:06:00 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2019-09-26 12:06:00 +0000
commit5707f305f4b961e24369fcdaecf0b8ce1c34bad8 (patch)
tree3b291653b83b3e6c2bffc77c54527fbe6f6373be /spec/controllers/application_controller_spec.rb
parent759cd6c2985088d187ed519f2a881c2c690b34ec (diff)
downloadgitlab-ce-5707f305f4b961e24369fcdaecf0b8ce1c34bad8.tar.gz
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/controllers/application_controller_spec.rb')
-rw-r--r--spec/controllers/application_controller_spec.rb44
1 files changed, 44 insertions, 0 deletions
diff --git a/spec/controllers/application_controller_spec.rb b/spec/controllers/application_controller_spec.rb
index 5ef8a15d702..8c3642fb047 100644
--- a/spec/controllers/application_controller_spec.rb
+++ b/spec/controllers/application_controller_spec.rb
@@ -777,4 +777,48 @@ describe ApplicationController do
end
end
end
+
+ describe '#current_user_mode', :do_not_mock_admin_mode do
+ include_context 'custom session'
+
+ controller(described_class) do
+ def index
+ render html: 'authenticated'
+ end
+ end
+
+ before do
+ allow(ActiveSession).to receive(:list_sessions).with(user).and_return([session])
+
+ sign_in(user)
+ get :index
+ end
+
+ context 'with a regular user' do
+ it 'admin mode is not set' do
+ expect(response).to have_gitlab_http_status(:ok)
+ expect(Gitlab::Auth::CurrentUserMode.new(user).admin_mode?).to be(false)
+ end
+ end
+
+ context 'with an admin user' do
+ let(:user) { create(:admin) }
+
+ it 'admin mode is not set' do
+ expect(response).to have_gitlab_http_status(:ok)
+ expect(Gitlab::Auth::CurrentUserMode.new(user).admin_mode?).to be(false)
+ end
+
+ context 'that re-authenticated' do
+ before do
+ Gitlab::Auth::CurrentUserMode.new(user).enable_admin_mode!(password: user.password)
+ end
+
+ it 'admin mode is set' do
+ expect(response).to have_gitlab_http_status(:ok)
+ expect(Gitlab::Auth::CurrentUserMode.new(user).admin_mode?).to be(true)
+ end
+ end
+ end
+ end
end