2019-07-25 01:24:42 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2015-09-28 05:01:45 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-06-03 14:08:28 -04:00
|
|
|
RSpec.describe 'Runners' do
|
2022-09-16 11:14:12 -04:00
|
|
|
let_it_be(:user) { create(:user) }
|
2017-06-14 14:18:56 -04:00
|
|
|
|
2018-07-05 02:32:05 -04:00
|
|
|
before do
|
2017-06-21 19:44:10 -04:00
|
|
|
sign_in(user)
|
2017-06-14 14:18:56 -04:00
|
|
|
end
|
2015-09-28 05:01:45 -04:00
|
|
|
|
2018-02-21 11:09:06 -05:00
|
|
|
context 'when user opens runners page' do
|
2018-07-05 02:32:05 -04:00
|
|
|
let(:project) { create(:project) }
|
2018-02-21 11:09:06 -05:00
|
|
|
|
2018-07-05 02:32:05 -04:00
|
|
|
before do
|
2018-07-11 10:36:08 -04:00
|
|
|
project.add_maintainer(user)
|
2018-02-21 11:09:06 -05:00
|
|
|
end
|
|
|
|
|
2021-07-27 05:10:08 -04:00
|
|
|
it 'user can see a link with instructions on how to install GitLab Runner' do
|
2018-04-09 21:28:21 -04:00
|
|
|
visit project_runners_path(project)
|
2018-02-21 11:09:06 -05:00
|
|
|
|
2021-07-27 05:10:08 -04:00
|
|
|
expect(page).to have_link('Install GitLab Runner and ensure it\'s running.', href: "https://docs.gitlab.com/runner/install/")
|
2018-02-21 11:09:06 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-08-21 10:22:17 -04:00
|
|
|
context 'when a project has enabled shared_runners' do
|
2022-09-16 11:14:12 -04:00
|
|
|
let_it_be(:project) { create(:project) }
|
2015-09-28 05:01:45 -04:00
|
|
|
|
2018-07-05 02:32:05 -04:00
|
|
|
before do
|
2018-07-11 10:36:08 -04:00
|
|
|
project.add_maintainer(user)
|
2017-08-23 08:58:45 -04:00
|
|
|
end
|
|
|
|
|
2018-05-11 06:03:40 -04:00
|
|
|
context 'when a project_type runner is activated on the project' do
|
2022-09-16 11:14:12 -04:00
|
|
|
let_it_be(:project_runner) { create(:ci_runner, :project, projects: [project]) }
|
2015-11-16 07:24:36 -05:00
|
|
|
|
2018-07-05 02:32:05 -04:00
|
|
|
it 'user sees the specific runner' do
|
2018-04-09 21:28:21 -04:00
|
|
|
visit project_runners_path(project)
|
2015-09-28 05:01:45 -04:00
|
|
|
|
2017-08-21 10:22:17 -04:00
|
|
|
within '.activated-specific-runners' do
|
2022-09-16 11:14:12 -04:00
|
|
|
expect(page).to have_content(project_runner.display_name)
|
2017-08-21 10:22:17 -04:00
|
|
|
end
|
2015-09-28 05:01:45 -04:00
|
|
|
|
2022-09-16 11:14:12 -04:00
|
|
|
click_on project_runner.short_sha
|
2015-11-16 07:24:36 -05:00
|
|
|
|
2022-09-16 11:14:12 -04:00
|
|
|
expect(page).to have_content(project_runner.platform)
|
2015-09-28 05:01:45 -04:00
|
|
|
end
|
|
|
|
|
2018-07-05 02:32:05 -04:00
|
|
|
it 'user can pause and resume the specific runner' do
|
2018-04-09 21:28:21 -04:00
|
|
|
visit project_runners_path(project)
|
2017-12-19 16:24:36 -05:00
|
|
|
|
|
|
|
within '.activated-specific-runners' do
|
2021-04-15 14:09:01 -04:00
|
|
|
expect(page).to have_link('Pause')
|
2017-12-19 16:24:36 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
click_on 'Pause'
|
|
|
|
|
|
|
|
within '.activated-specific-runners' do
|
2021-04-15 14:09:01 -04:00
|
|
|
expect(page).to have_link('Resume')
|
2017-12-19 16:24:36 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
click_on 'Resume'
|
|
|
|
|
|
|
|
within '.activated-specific-runners' do
|
2021-04-15 14:09:01 -04:00
|
|
|
expect(page).to have_link('Pause')
|
2017-12-19 16:24:36 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-07-05 02:32:05 -04:00
|
|
|
it 'user removes an activated specific runner if this is last project for that runners' do
|
2018-04-09 21:28:21 -04:00
|
|
|
visit project_runners_path(project)
|
2015-09-28 05:01:45 -04:00
|
|
|
|
2017-08-21 10:22:17 -04:00
|
|
|
within '.activated-specific-runners' do
|
2021-01-12 16:10:47 -05:00
|
|
|
click_on 'Remove runner'
|
2017-08-21 10:22:17 -04:00
|
|
|
end
|
2015-09-28 05:01:45 -04:00
|
|
|
|
2022-09-16 11:14:12 -04:00
|
|
|
expect(page).not_to have_content(project_runner.display_name)
|
2015-09-28 05:01:45 -04:00
|
|
|
end
|
|
|
|
|
2018-07-05 02:32:05 -04:00
|
|
|
it 'user edits the runner to be protected' do
|
2018-04-09 21:28:21 -04:00
|
|
|
visit project_runners_path(project)
|
2017-08-25 04:46:38 -04:00
|
|
|
|
|
|
|
within '.activated-specific-runners' do
|
2021-04-08 17:09:13 -04:00
|
|
|
first('[data-testid="edit-runner-link"]').click
|
2017-08-25 04:46:38 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
expect(page.find_field('runner[access_level]')).not_to be_checked
|
|
|
|
|
|
|
|
check 'runner_access_level'
|
|
|
|
click_button 'Save changes'
|
|
|
|
|
|
|
|
expect(page).to have_content 'Protected Yes'
|
|
|
|
end
|
|
|
|
|
2017-08-21 10:22:17 -04:00
|
|
|
context 'when a runner has a tag' do
|
2018-07-05 02:32:05 -04:00
|
|
|
before do
|
2022-09-16 11:14:12 -04:00
|
|
|
project_runner.update!(tag_list: ['tag'])
|
2017-08-21 10:22:17 -04:00
|
|
|
end
|
2015-09-28 05:01:45 -04:00
|
|
|
|
2018-07-05 02:32:05 -04:00
|
|
|
it 'user edits runner not to run untagged jobs' do
|
2018-04-09 21:28:21 -04:00
|
|
|
visit project_runners_path(project)
|
2015-09-28 05:01:45 -04:00
|
|
|
|
2017-08-21 10:22:17 -04:00
|
|
|
within '.activated-specific-runners' do
|
2021-04-08 17:09:13 -04:00
|
|
|
first('[data-testid="edit-runner-link"]').click
|
2017-08-21 10:22:17 -04:00
|
|
|
end
|
2015-09-28 05:01:45 -04:00
|
|
|
|
2017-08-21 10:22:17 -04:00
|
|
|
expect(page.find_field('runner[run_untagged]')).to be_checked
|
2015-09-28 05:01:45 -04:00
|
|
|
|
2017-08-21 10:22:17 -04:00
|
|
|
uncheck 'runner_run_untagged'
|
|
|
|
click_button 'Save changes'
|
2015-09-28 05:01:45 -04:00
|
|
|
|
2017-08-21 10:22:17 -04:00
|
|
|
expect(page).to have_content 'Can run untagged jobs No'
|
|
|
|
end
|
|
|
|
end
|
2016-04-15 09:51:41 -04:00
|
|
|
|
2017-08-23 08:58:45 -04:00
|
|
|
context 'when a shared runner is activated on the project' do
|
2018-07-05 02:32:05 -04:00
|
|
|
let!(:shared_runner) { create(:ci_runner, :instance) }
|
2016-04-15 09:51:41 -04:00
|
|
|
|
2018-07-05 02:32:05 -04:00
|
|
|
it 'user sees CI/CD setting page' do
|
2018-04-09 21:28:21 -04:00
|
|
|
visit project_runners_path(project)
|
2015-09-28 05:01:45 -04:00
|
|
|
|
2017-08-23 08:58:45 -04:00
|
|
|
expect(page.find('.available-shared-runners')).to have_content(shared_runner.display_name)
|
|
|
|
end
|
|
|
|
end
|
2016-05-05 06:20:33 -04:00
|
|
|
|
2022-09-16 11:14:12 -04:00
|
|
|
context 'when multiple runners are configured' do
|
|
|
|
let!(:project_runner_2) { create(:ci_runner, :project, projects: [project]) }
|
2020-11-10 19:08:58 -05:00
|
|
|
|
2022-09-16 11:14:12 -04:00
|
|
|
it 'adds pagination to the runner list' do
|
|
|
|
stub_const('Projects::Settings::CiCdController::NUMBER_OF_RUNNERS_PER_PAGE', 1)
|
2020-11-10 19:08:58 -05:00
|
|
|
|
2022-09-16 11:14:12 -04:00
|
|
|
visit project_runners_path(project)
|
2020-11-10 19:08:58 -05:00
|
|
|
|
2022-09-16 11:14:12 -04:00
|
|
|
expect(find('.pagination')).not_to be_nil
|
|
|
|
end
|
2020-11-10 19:08:58 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-08-23 08:58:45 -04:00
|
|
|
context 'when a specific runner exists in another project' do
|
2018-07-05 02:32:05 -04:00
|
|
|
let(:another_project) { create(:project) }
|
2022-09-16 11:14:12 -04:00
|
|
|
let!(:project_runner) { create(:ci_runner, :project, projects: [another_project]) }
|
2016-05-05 06:20:33 -04:00
|
|
|
|
2018-07-05 02:32:05 -04:00
|
|
|
before do
|
2018-07-11 10:36:08 -04:00
|
|
|
another_project.add_maintainer(user)
|
2017-08-21 10:22:17 -04:00
|
|
|
end
|
|
|
|
|
2018-07-05 02:32:05 -04:00
|
|
|
it 'user enables and disables a specific runner' do
|
2018-04-09 21:28:21 -04:00
|
|
|
visit project_runners_path(project)
|
2016-05-05 06:20:33 -04:00
|
|
|
|
2017-08-23 08:58:45 -04:00
|
|
|
within '.available-specific-runners' do
|
|
|
|
click_on 'Enable for this project'
|
|
|
|
end
|
2017-08-21 10:22:17 -04:00
|
|
|
|
2022-09-16 11:14:12 -04:00
|
|
|
expect(page.find('.activated-specific-runners')).to have_content(project_runner.display_name)
|
2017-08-23 08:58:45 -04:00
|
|
|
|
|
|
|
within '.activated-specific-runners' do
|
|
|
|
click_on 'Disable for this project'
|
2017-08-21 10:22:17 -04:00
|
|
|
end
|
2017-08-23 08:58:45 -04:00
|
|
|
|
2022-09-16 11:14:12 -04:00
|
|
|
expect(page.find('.available-specific-runners')).to have_content(project_runner.display_name)
|
2017-08-21 10:22:17 -04:00
|
|
|
end
|
2016-05-05 06:20:33 -04:00
|
|
|
end
|
|
|
|
|
2021-05-04 11:10:36 -04:00
|
|
|
context 'shared runner text' do
|
|
|
|
context 'when application settings have shared_runners_text' do
|
|
|
|
let(:shared_runners_text) { 'custom **shared** runners description' }
|
|
|
|
let(:shared_runners_html) { 'custom shared runners description' }
|
|
|
|
|
|
|
|
before do
|
|
|
|
stub_application_setting(shared_runners_text: shared_runners_text)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'user sees shared runners description' do
|
|
|
|
visit project_runners_path(project)
|
|
|
|
|
|
|
|
page.within("[data-testid='shared-runners-description']") do
|
|
|
|
expect(page).not_to have_content('The same shared runner executes code from multiple projects')
|
|
|
|
expect(page).to have_content(shared_runners_html)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when application settings have an unsafe link in shared_runners_text' do
|
|
|
|
let(:shared_runners_text) { '<a href="javascript:alert(\'xss\')">link</a>' }
|
|
|
|
|
|
|
|
before do
|
|
|
|
stub_application_setting(shared_runners_text: shared_runners_text)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'user sees no link' do
|
|
|
|
visit project_runners_path(project)
|
|
|
|
|
|
|
|
page.within("[data-testid='shared-runners-description']") do
|
|
|
|
expect(page).to have_content('link')
|
|
|
|
expect(page).not_to have_link('link')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2016-05-06 02:41:51 -04:00
|
|
|
|
2021-05-04 11:10:36 -04:00
|
|
|
context 'when application settings have an unsafe image in shared_runners_text' do
|
|
|
|
let(:shared_runners_text) { '<img src="404.png" onerror="alert(\'xss\')"/>' }
|
|
|
|
|
|
|
|
before do
|
|
|
|
stub_application_setting(shared_runners_text: shared_runners_text)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'user sees image safely' do
|
|
|
|
visit project_runners_path(project)
|
|
|
|
|
|
|
|
page.within("[data-testid='shared-runners-description']") do
|
|
|
|
expect(page).to have_css('img')
|
|
|
|
expect(page).not_to have_css('img[onerror]')
|
|
|
|
end
|
|
|
|
end
|
2016-05-06 02:41:51 -04:00
|
|
|
end
|
2016-05-05 06:20:33 -04:00
|
|
|
end
|
|
|
|
end
|
2017-08-21 10:22:17 -04:00
|
|
|
|
2021-05-10 23:10:35 -04:00
|
|
|
context 'enable shared runners in project settings', :js do
|
|
|
|
before do
|
|
|
|
project.add_maintainer(user)
|
2020-12-11 04:09:48 -05:00
|
|
|
|
2021-05-10 23:10:35 -04:00
|
|
|
visit project_runners_path(project)
|
|
|
|
end
|
2020-12-11 04:09:48 -05:00
|
|
|
|
2021-05-10 23:10:35 -04:00
|
|
|
context 'when a project has enabled shared_runners' do
|
|
|
|
let(:project) { create(:project, shared_runners_enabled: true) }
|
2020-12-11 04:09:48 -05:00
|
|
|
|
2021-05-10 23:10:35 -04:00
|
|
|
it 'shared runners toggle is on' do
|
|
|
|
expect(page).to have_selector('[data-testid="toggle-shared-runners"]')
|
|
|
|
expect(page).to have_selector('[data-testid="toggle-shared-runners"] .is-checked')
|
2020-12-11 04:09:48 -05:00
|
|
|
end
|
2017-08-21 10:22:17 -04:00
|
|
|
end
|
|
|
|
|
2021-05-10 23:10:35 -04:00
|
|
|
context 'when a project has disabled shared_runners' do
|
|
|
|
let(:project) { create(:project, shared_runners_enabled: false) }
|
2017-08-23 08:58:45 -04:00
|
|
|
|
2021-05-10 23:10:35 -04:00
|
|
|
it 'shared runners toggle is off' do
|
|
|
|
expect(page).not_to have_selector('[data-testid="toggle-shared-runners"] .is-checked')
|
2020-12-11 04:09:48 -05:00
|
|
|
end
|
2017-08-21 10:22:17 -04:00
|
|
|
end
|
|
|
|
end
|
2017-10-04 07:59:51 -04:00
|
|
|
|
2018-04-10 00:29:06 -04:00
|
|
|
context 'group runners in project settings' do
|
2018-07-05 02:32:05 -04:00
|
|
|
before do
|
2018-07-11 10:36:08 -04:00
|
|
|
project.add_maintainer(user)
|
2017-10-04 07:59:51 -04:00
|
|
|
end
|
|
|
|
|
2022-09-16 11:14:12 -04:00
|
|
|
let_it_be(:group) { create :group }
|
|
|
|
let_it_be(:project) { create :project, group: group }
|
2017-10-04 07:59:51 -04:00
|
|
|
|
2018-06-03 21:32:57 -04:00
|
|
|
context 'as project and group maintainer' do
|
2018-07-05 02:32:05 -04:00
|
|
|
before do
|
2018-07-11 10:36:08 -04:00
|
|
|
group.add_maintainer(user)
|
2017-12-19 12:04:33 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'project with a group but no group runner' do
|
2018-07-05 02:32:05 -04:00
|
|
|
it 'group runners are not available' do
|
2018-04-09 21:28:21 -04:00
|
|
|
visit project_runners_path(project)
|
2017-10-04 07:59:51 -04:00
|
|
|
|
2022-08-10 11:11:53 -04:00
|
|
|
expect(page).not_to have_content 'To register them, go to the group\'s Runners page.'
|
2022-01-10 22:16:07 -05:00
|
|
|
expect(page).to have_content 'Ask your group owner to set up a group runner'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'as project maintainer and group owner' do
|
|
|
|
before do
|
|
|
|
group.add_owner(user)
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'project with a group but no group runner' do
|
|
|
|
it 'group runners are available' do
|
|
|
|
visit project_runners_path(project)
|
|
|
|
|
2021-01-12 16:10:47 -05:00
|
|
|
expect(page).to have_content 'This group does not have any group runners yet.'
|
2017-12-19 12:04:33 -05:00
|
|
|
|
2022-08-10 11:11:53 -04:00
|
|
|
expect(page).to have_content 'To register them, go to the group\'s Runners page.'
|
2022-01-10 22:16:07 -05:00
|
|
|
expect(page).not_to have_content 'Ask your group owner to set up a group runner'
|
2017-12-19 12:04:33 -05:00
|
|
|
end
|
2017-10-04 07:59:51 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-06-03 21:32:57 -04:00
|
|
|
context 'as project maintainer' do
|
2017-12-19 12:04:33 -05:00
|
|
|
context 'project without a group' do
|
2018-07-05 02:32:05 -04:00
|
|
|
let(:project) { create :project }
|
2017-10-04 07:59:51 -04:00
|
|
|
|
2018-07-05 02:32:05 -04:00
|
|
|
it 'group runners are not available' do
|
2018-04-09 21:28:21 -04:00
|
|
|
visit project_runners_path(project)
|
2017-10-04 07:59:51 -04:00
|
|
|
|
2021-01-12 16:10:47 -05:00
|
|
|
expect(page).to have_content 'This project does not belong to a group and cannot make use of group runners.'
|
2017-12-19 12:04:33 -05:00
|
|
|
end
|
2017-10-04 07:59:51 -04:00
|
|
|
end
|
|
|
|
|
2022-09-16 11:14:12 -04:00
|
|
|
context 'with group project' do
|
|
|
|
let_it_be(:group) { create(:group) }
|
|
|
|
let_it_be(:project) { create(:project, group: group) }
|
2017-10-04 07:59:51 -04:00
|
|
|
|
2022-09-16 11:14:12 -04:00
|
|
|
context 'project with a group but no group runner' do
|
|
|
|
it 'group runners are not available' do
|
|
|
|
visit project_runners_path(project)
|
2017-12-19 12:04:33 -05:00
|
|
|
|
2022-09-16 11:14:12 -04:00
|
|
|
expect(page).to have_content 'This group does not have any group runners yet.'
|
2017-10-04 07:59:51 -04:00
|
|
|
|
2022-09-16 11:14:12 -04:00
|
|
|
expect(page).not_to have_content 'To register them, go to the group\'s Runners page.'
|
|
|
|
expect(page).to have_content 'Ask your group owner to set up a group runner.'
|
|
|
|
end
|
2017-12-19 12:04:33 -05:00
|
|
|
end
|
2017-10-05 03:55:01 -04:00
|
|
|
|
2022-09-16 11:14:12 -04:00
|
|
|
context 'project with a group and a group runner' do
|
|
|
|
let_it_be(:ci_runner) do
|
|
|
|
create(:ci_runner, :group, groups: [group], description: 'group-runner')
|
|
|
|
end
|
2017-12-19 12:04:33 -05:00
|
|
|
|
2022-09-16 11:14:12 -04:00
|
|
|
it 'group runners are available' do
|
|
|
|
visit project_runners_path(project)
|
2017-12-19 12:04:33 -05:00
|
|
|
|
2022-09-16 11:14:12 -04:00
|
|
|
expect(page).to have_content 'Available group runners: 1'
|
|
|
|
expect(page).to have_content 'group-runner'
|
|
|
|
end
|
2017-10-05 03:55:01 -04:00
|
|
|
|
2022-09-16 11:14:12 -04:00
|
|
|
it 'group runners may be disabled for a project' do
|
|
|
|
visit project_runners_path(project)
|
2017-12-19 12:04:33 -05:00
|
|
|
|
2022-09-16 11:14:12 -04:00
|
|
|
click_on 'Disable group runners'
|
2017-10-05 03:55:01 -04:00
|
|
|
|
2022-09-16 11:14:12 -04:00
|
|
|
expect(page).to have_content 'Enable group runners'
|
|
|
|
expect(project.reload.group_runners_enabled).to be false
|
2017-10-05 03:55:01 -04:00
|
|
|
|
2022-09-16 11:14:12 -04:00
|
|
|
click_on 'Enable group runners'
|
2017-10-05 03:55:01 -04:00
|
|
|
|
2022-09-16 11:14:12 -04:00
|
|
|
expect(page).to have_content 'Disable group runners'
|
|
|
|
expect(project.reload.group_runners_enabled).to be true
|
|
|
|
end
|
2017-12-19 12:04:33 -05:00
|
|
|
end
|
2017-10-05 03:55:01 -04:00
|
|
|
end
|
2017-10-04 07:59:51 -04:00
|
|
|
end
|
|
|
|
end
|
2015-09-28 05:01:45 -04:00
|
|
|
end
|