diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2019-09-26 12:06:00 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2019-09-26 12:06:00 +0000 |
commit | 5707f305f4b961e24369fcdaecf0b8ce1c34bad8 (patch) | |
tree | 3b291653b83b3e6c2bffc77c54527fbe6f6373be /spec/controllers/application_controller_spec.rb | |
parent | 759cd6c2985088d187ed519f2a881c2c690b34ec (diff) | |
download | gitlab-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.rb | 44 |
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 |