2020-01-24 19:08:59 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'spec_helper'
|
|
|
|
|
2021-07-21 17:10:10 -04:00
|
|
|
RSpec.describe 'Admin mode', :js do
|
2020-01-24 19:08:59 -05:00
|
|
|
include MobileHelpers
|
2021-05-31 17:09:39 -04:00
|
|
|
include Spec::Support::Helpers::Features::TopNavSpecHelpers
|
2020-01-24 19:08:59 -05:00
|
|
|
include StubENV
|
|
|
|
|
|
|
|
let(:admin) { create(:admin) }
|
|
|
|
|
2021-07-21 17:10:10 -04:00
|
|
|
before do
|
|
|
|
stub_env('IN_MEMORY_APPLICATION_SETTINGS', 'false')
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'application setting :admin_mode is enabled', :request_store do
|
2020-01-24 19:08:59 -05:00
|
|
|
before do
|
2021-07-21 17:10:10 -04:00
|
|
|
sign_in(admin)
|
2020-01-24 19:08:59 -05:00
|
|
|
end
|
|
|
|
|
2021-07-21 17:10:10 -04:00
|
|
|
context 'when not in admin mode' do
|
|
|
|
it 'has no leave admin mode button' do
|
|
|
|
visit new_admin_session_path
|
|
|
|
open_top_nav
|
|
|
|
|
|
|
|
page.within('.navbar-sub-nav') do
|
|
|
|
expect(page).not_to have_link(href: destroy_admin_session_path)
|
|
|
|
end
|
2020-01-24 19:08:59 -05:00
|
|
|
end
|
|
|
|
|
2021-07-21 17:10:10 -04:00
|
|
|
it 'can open pages not in admin scope' do
|
|
|
|
visit new_admin_session_path
|
|
|
|
open_top_nav_projects
|
2020-01-24 19:08:59 -05:00
|
|
|
|
2021-07-21 17:10:10 -04:00
|
|
|
within_top_nav do
|
|
|
|
click_link('Your projects')
|
2021-05-12 17:10:13 -04:00
|
|
|
end
|
2020-01-24 19:08:59 -05:00
|
|
|
|
2021-07-21 17:10:10 -04:00
|
|
|
expect(page).to have_current_path(dashboard_projects_path)
|
|
|
|
end
|
2020-01-24 19:08:59 -05:00
|
|
|
|
2021-07-21 17:10:10 -04:00
|
|
|
it 'is necessary to provide credentials again before opening pages in admin scope' do
|
|
|
|
visit general_admin_application_settings_path # admin logged out because not in admin_mode
|
2020-01-24 19:08:59 -05:00
|
|
|
|
2021-07-21 17:10:10 -04:00
|
|
|
expect(page).to have_current_path(new_admin_session_path)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'can enter admin mode' do
|
|
|
|
visit new_admin_session_path
|
2020-01-24 19:08:59 -05:00
|
|
|
|
2021-07-21 17:10:10 -04:00
|
|
|
fill_in 'user_password', with: admin.password
|
2020-01-24 19:08:59 -05:00
|
|
|
|
2021-07-21 17:10:10 -04:00
|
|
|
click_button 'Enter Admin Mode'
|
|
|
|
|
|
|
|
expect(page).to have_current_path(admin_root_path)
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'on a read-only instance' do
|
|
|
|
before do
|
2021-08-02 05:10:09 -04:00
|
|
|
allow(Gitlab::Database).to receive(:read_only?).and_return(true)
|
2020-01-24 19:08:59 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'can enter admin mode' do
|
|
|
|
visit new_admin_session_path
|
|
|
|
|
2020-03-13 08:09:22 -04:00
|
|
|
fill_in 'user_password', with: admin.password
|
2020-01-24 19:08:59 -05:00
|
|
|
|
|
|
|
click_button 'Enter Admin Mode'
|
|
|
|
|
|
|
|
expect(page).to have_current_path(admin_root_path)
|
|
|
|
end
|
2021-07-21 17:10:10 -04:00
|
|
|
end
|
|
|
|
end
|
2020-01-24 19:08:59 -05:00
|
|
|
|
2021-07-21 17:10:10 -04:00
|
|
|
context 'when in admin_mode' do
|
|
|
|
before do
|
|
|
|
gitlab_enable_admin_mode_sign_in(admin)
|
|
|
|
end
|
2021-05-12 17:10:13 -04:00
|
|
|
|
2021-07-21 17:10:10 -04:00
|
|
|
it 'contains link to leave admin mode' do
|
|
|
|
open_top_nav
|
2021-05-12 17:10:13 -04:00
|
|
|
|
2021-07-21 17:10:10 -04:00
|
|
|
within_top_nav do
|
|
|
|
expect(page).to have_link(href: destroy_admin_session_path)
|
2020-01-24 19:08:59 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-07-21 17:10:10 -04:00
|
|
|
it 'can leave admin mode using main dashboard link' do
|
|
|
|
gitlab_disable_admin_mode
|
2021-05-12 17:10:13 -04:00
|
|
|
|
2021-07-21 17:10:10 -04:00
|
|
|
open_top_nav
|
2020-01-24 19:08:59 -05:00
|
|
|
|
2021-07-21 17:10:10 -04:00
|
|
|
within_top_nav do
|
|
|
|
expect(page).to have_link(href: new_admin_session_path)
|
2020-01-24 19:08:59 -05:00
|
|
|
end
|
2021-07-21 17:10:10 -04:00
|
|
|
end
|
2020-01-24 19:08:59 -05:00
|
|
|
|
2021-07-21 17:10:10 -04:00
|
|
|
it 'can open pages not in admin scope' do
|
|
|
|
open_top_nav_projects
|
2020-01-24 19:08:59 -05:00
|
|
|
|
2021-07-21 17:10:10 -04:00
|
|
|
within_top_nav do
|
|
|
|
click_link('Your projects')
|
2021-05-12 17:10:13 -04:00
|
|
|
end
|
2020-01-24 19:08:59 -05:00
|
|
|
|
2021-07-21 17:10:10 -04:00
|
|
|
expect(page).to have_current_path(dashboard_projects_path)
|
|
|
|
end
|
2021-06-08 20:10:20 -04:00
|
|
|
|
2021-07-21 17:10:10 -04:00
|
|
|
context 'nav bar' do
|
|
|
|
it 'shows admin dashboard links on bigger screen' do
|
2021-05-12 17:10:13 -04:00
|
|
|
visit root_dashboard_path
|
2021-05-31 17:09:39 -04:00
|
|
|
open_top_nav
|
2020-01-24 19:08:59 -05:00
|
|
|
|
2021-07-21 17:10:10 -04:00
|
|
|
expect(page).to have_link(text: 'Admin', href: admin_root_path, visible: true)
|
|
|
|
expect(page).to have_link(text: 'Leave Admin Mode', href: destroy_admin_session_path, visible: true)
|
2020-01-24 19:08:59 -05:00
|
|
|
end
|
2021-07-21 17:10:10 -04:00
|
|
|
end
|
2020-01-24 19:08:59 -05:00
|
|
|
|
2021-07-21 17:10:10 -04:00
|
|
|
context 'on a read-only instance' do
|
|
|
|
before do
|
2021-08-02 05:10:09 -04:00
|
|
|
allow(Gitlab::Database).to receive(:read_only?).and_return(true)
|
2020-01-24 19:08:59 -05:00
|
|
|
end
|
|
|
|
|
2021-07-21 17:10:10 -04:00
|
|
|
it 'can leave admin mode' do
|
|
|
|
gitlab_disable_admin_mode
|
2020-01-24 19:08:59 -05:00
|
|
|
|
2021-07-21 17:10:10 -04:00
|
|
|
open_top_nav
|
2021-05-12 17:10:13 -04:00
|
|
|
|
2021-07-21 17:10:10 -04:00
|
|
|
within_top_nav do
|
|
|
|
expect(page).to have_link(href: new_admin_session_path)
|
2020-01-24 19:08:59 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-07-21 17:10:10 -04:00
|
|
|
context 'application setting :admin_mode is disabled' do
|
2020-01-24 19:08:59 -05:00
|
|
|
before do
|
2021-07-21 17:10:10 -04:00
|
|
|
stub_application_setting(admin_mode: false)
|
|
|
|
sign_in(admin)
|
2020-01-24 19:08:59 -05:00
|
|
|
end
|
|
|
|
|
2021-07-21 17:10:10 -04:00
|
|
|
it 'shows no admin mode buttons in navbar' do
|
|
|
|
visit admin_root_path
|
|
|
|
open_top_nav
|
2021-05-12 17:10:13 -04:00
|
|
|
|
2021-07-21 17:10:10 -04:00
|
|
|
expect(page).not_to have_link(href: new_admin_session_path)
|
|
|
|
expect(page).not_to have_link(href: destroy_admin_session_path)
|
2020-01-24 19:08:59 -05:00
|
|
|
end
|
2021-05-12 17:10:13 -04:00
|
|
|
end
|
2020-01-24 19:08:59 -05:00
|
|
|
end
|