diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2023-01-18 22:00:14 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2023-01-18 22:00:14 +0300 |
commit | 05f0ebba3a2c8ddf39e436f412dc2ab5bf1353b2 (patch) | |
tree | 11d0f2a6ec31c7793c184106cedc2ded3d9a2cc5 /spec/features/runners_spec.rb | |
parent | ec73467c23693d0db63a797d10194da9e72a74af (diff) |
Add latest changes from gitlab-org/gitlab@15-8-stable-eev15.8.0-rc42
Diffstat (limited to 'spec/features/runners_spec.rb')
-rw-r--r-- | spec/features/runners_spec.rb | 476 |
1 files changed, 254 insertions, 222 deletions
diff --git a/spec/features/runners_spec.rb b/spec/features/runners_spec.rb index 40ba0fa9ebb..e7c2452af93 100644 --- a/spec/features/runners_spec.rb +++ b/spec/features/runners_spec.rb @@ -9,370 +9,402 @@ RSpec.describe 'Runners', feature_category: :runner_fleet do sign_in(user) end - context 'when user opens runners page' do - let(:project) { create(:project) } - + context 'when project_runners_vue_ui is disabled' do before do - project.add_maintainer(user) + stub_feature_flags(project_runners_vue_ui: false) end - it 'user can see a link with instructions on how to install GitLab Runner' do - visit project_runners_path(project) + context 'when user opens runners page' do + let(:project) { create(:project) } - expect(page).to have_link('Install GitLab Runner and ensure it\'s running.', href: "https://docs.gitlab.com/runner/install/") - end - end + before do + project.add_maintainer(user) + end - context 'when a project has enabled shared_runners' do - let_it_be(:project) { create(:project) } + it 'user can see a link with instructions on how to install GitLab Runner' do + visit project_runners_path(project) - before do - project.add_maintainer(user) - end + expect(page).to have_link('Install GitLab Runner and ensure it\'s running.', href: "https://docs.gitlab.com/runner/install/") + end - context 'when a project_type runner is activated on the project' do - let_it_be(:project_runner) { create(:ci_runner, :project, projects: [project]) } + describe 'runners registration token' do + let!(:token) { project.runners_token } - it 'user sees the specific runner' do - visit project_runners_path(project) + context 'when project_runners_vue_ui is disabled' do + before do + visit project_runners_path(project) + end - within '.activated-specific-runners' do - expect(page).to have_content(project_runner.display_name) - end + it 'has a registration token' do + expect(page.find('#registration_token')).to have_content(token) + end - click_on project_runner.short_sha + describe 'reload registration token' do + let(:page_token) { find('#registration_token').text } - expect(page).to have_content(project_runner.platform) + before do + click_link 'Reset registration token' + end + + it 'changes registration token' do + expect(page_token).not_to eq token + end + end + end end + end - it 'user can pause and resume the specific runner' do - visit project_runners_path(project) + context 'when a project has enabled shared_runners' do + let_it_be(:project) { create(:project) } - within '.activated-specific-runners' do - expect(page).to have_link('Pause') - end + before do + project.add_maintainer(user) + end - click_on 'Pause' + context 'when a project_type runner is activated on the project' do + let_it_be(:project_runner) { create(:ci_runner, :project, projects: [project]) } - within '.activated-specific-runners' do - expect(page).to have_link('Resume') - end + it 'user sees the specific runner' do + visit project_runners_path(project) - click_on 'Resume' + within '.activated-specific-runners' do + expect(page).to have_content(project_runner.display_name) + end + + click_on project_runner.short_sha - within '.activated-specific-runners' do - expect(page).to have_link('Pause') + expect(page).to have_content(project_runner.platform) end - end - it 'user removes an activated specific runner if this is last project for that runners' do - visit project_runners_path(project) + it 'user can pause and resume the specific runner' do + visit project_runners_path(project) - within '.activated-specific-runners' do - click_on 'Remove runner' - end + within '.activated-specific-runners' do + expect(page).to have_link('Pause') + end - expect(page).not_to have_content(project_runner.display_name) - end + click_on 'Pause' - it 'user edits the runner to be protected' do - visit project_runners_path(project) + within '.activated-specific-runners' do + expect(page).to have_link('Resume') + end - within '.activated-specific-runners' do - first('[data-testid="edit-runner-link"]').click - end + click_on 'Resume' - expect(page.find_field('runner[access_level]')).not_to be_checked + within '.activated-specific-runners' do + expect(page).to have_link('Pause') + end + end - check 'runner_access_level' - click_button 'Save changes' + it 'user removes an activated specific runner if this is last project for that runners' do + visit project_runners_path(project) - expect(page).to have_content 'Protected Yes' - end + within '.activated-specific-runners' do + click_on 'Remove runner' + end - context 'when a runner has a tag' do - before do - project_runner.update!(tag_list: ['tag']) + expect(page).not_to have_content(project_runner.display_name) end - it 'user edits runner not to run untagged jobs' do + it 'user edits the runner to be protected' do visit project_runners_path(project) within '.activated-specific-runners' do first('[data-testid="edit-runner-link"]').click end - expect(page.find_field('runner[run_untagged]')).to be_checked + expect(page.find_field('runner[access_level]')).not_to be_checked - uncheck 'runner_run_untagged' + check 'runner_access_level' click_button 'Save changes' - expect(page).to have_content 'Can run untagged jobs No' + expect(page).to have_content 'Protected Yes' end - end - - context 'when a shared runner is activated on the project' do - let!(:shared_runner) { create(:ci_runner, :instance) } - it 'user sees CI/CD setting page' do - visit project_runners_path(project) - - within '[data-testid="available-shared-runners"]' do - expect(page).to have_content(shared_runner.display_name) + context 'when a runner has a tag' do + before do + project_runner.update!(tag_list: ['tag']) end - end - context 'when multiple shared runners are configured' do - let_it_be(:shared_runner_2) { create(:ci_runner, :instance) } - - it 'shows the runner count' do + it 'user edits runner not to run untagged jobs' do visit project_runners_path(project) - within '[data-testid="available-shared-runners"]' do - expect(page).to have_content format(_('Available shared runners: %{count}'), { count: 2 }) + within '.activated-specific-runners' do + first('[data-testid="edit-runner-link"]').click end + + expect(page.find_field('runner[run_untagged]')).to be_checked + + uncheck 'runner_run_untagged' + click_button 'Save changes' + + expect(page).to have_content 'Can run untagged jobs No' end + end - it 'adds pagination to the shared runner list' do - stub_const('Projects::Settings::CiCdController::NUMBER_OF_RUNNERS_PER_PAGE', 1) + context 'when a shared runner is activated on the project' do + let!(:shared_runner) { create(:ci_runner, :instance) } + it 'user sees CI/CD setting page' do visit project_runners_path(project) within '[data-testid="available-shared-runners"]' do - expect(find('.pagination')).not_to be_nil + expect(page).to have_content(shared_runner.display_name) end end - end - end - context 'when multiple project runners are configured' do - let!(:project_runner_2) { create(:ci_runner, :project, projects: [project]) } + context 'when multiple shared runners are configured' do + let_it_be(:shared_runner_2) { create(:ci_runner, :instance) } - it 'adds pagination to the runner list' do - stub_const('Projects::Settings::CiCdController::NUMBER_OF_RUNNERS_PER_PAGE', 1) + it 'shows the runner count' do + visit project_runners_path(project) - visit project_runners_path(project) + within '[data-testid="available-shared-runners"]' do + expect(page).to have_content format(_('Available shared runners: %{count}'), { count: 2 }) + end + end - expect(find('.pagination')).not_to be_nil - end - end - end + it 'adds pagination to the shared runner list' do + stub_const('Projects::Settings::CiCdController::NUMBER_OF_RUNNERS_PER_PAGE', 1) - context 'when a specific runner exists in another project' do - let(:another_project) { create(:project) } - let!(:project_runner) { create(:ci_runner, :project, projects: [another_project]) } + visit project_runners_path(project) - before do - another_project.add_maintainer(user) - end + within '[data-testid="available-shared-runners"]' do + expect(find('.pagination')).not_to be_nil + end + end + end + end - it 'user enables and disables a specific runner' do - visit project_runners_path(project) + context 'when multiple project runners are configured' do + let!(:project_runner_2) { create(:ci_runner, :project, projects: [project]) } - within '.available-specific-runners' do - click_on 'Enable for this project' - end + it 'adds pagination to the runner list' do + stub_const('Projects::Settings::CiCdController::NUMBER_OF_RUNNERS_PER_PAGE', 1) - expect(page.find('.activated-specific-runners')).to have_content(project_runner.display_name) + visit project_runners_path(project) - within '.activated-specific-runners' do - click_on 'Disable for this project' + expect(find('.pagination')).not_to be_nil + end end - - expect(page.find('.available-specific-runners')).to have_content(project_runner.display_name) end - end - 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' } + context 'when a specific runner exists in another project' do + let(:another_project) { create(:project) } + let!(:project_runner) { create(:ci_runner, :project, projects: [another_project]) } before do - stub_application_setting(shared_runners_text: shared_runners_text) + another_project.add_maintainer(user) end - it 'user sees shared runners description' do + it 'user enables and disables a specific runner' 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) + within '.available-specific-runners' do + click_on 'Enable for this project' + end + + expect(page.find('.activated-specific-runners')).to have_content(project_runner.display_name) + + within '.activated-specific-runners' do + click_on 'Disable for this project' end + + expect(page.find('.available-specific-runners')).to have_content(project_runner.display_name) 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>' } + 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 + before do + stub_application_setting(shared_runners_text: shared_runners_text) + end - it 'user sees no link' do - visit project_runners_path(project) + it 'user sees shared runners description' 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') + 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 - end - context 'when application settings have an unsafe image in shared_runners_text' do - let(:shared_runners_text) { '<img src="404.png" onerror="alert(\'xss\')"/>' } + 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 + before do + stub_application_setting(shared_runners_text: shared_runners_text) + end - it 'user sees image safely' do - visit project_runners_path(project) + it 'user sees no link' 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]') + page.within("[data-testid='shared-runners-description']") do + expect(page).to have_content('link') + expect(page).not_to have_link('link') + end end end - end - end - end - context 'enable shared runners in project settings', :js do - before do - project.add_maintainer(user) + context 'when application settings have an unsafe image in shared_runners_text' do + let(:shared_runners_text) { '<img src="404.png" onerror="alert(\'xss\')"/>' } - visit project_runners_path(project) - end + before do + stub_application_setting(shared_runners_text: shared_runners_text) + end - context 'when a project has enabled shared_runners' do - let(:project) { create(:project, shared_runners_enabled: true) } + it 'user sees image safely' do + visit project_runners_path(project) - 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') + page.within("[data-testid='shared-runners-description']") do + expect(page).to have_css('img') + expect(page).not_to have_css('img[onerror]') + end + end + end end end - context 'when a project has disabled shared_runners' do - let(:project) { create(:project, shared_runners_enabled: false) } + context 'enable shared runners in project settings', :js do + before do + project.add_maintainer(user) - it 'shared runners toggle is off' do - expect(page).not_to have_selector('[data-testid="toggle-shared-runners"] .is-checked') + visit project_runners_path(project) end - end - end - - context 'group runners in project settings' do - before do - project.add_maintainer(user) - end - let_it_be(:group) { create :group } - let_it_be(:project) { create :project, group: group } + context 'when a project has enabled shared_runners' do + let(:project) { create(:project, shared_runners_enabled: true) } - context 'as project and group maintainer' do - before do - group.add_maintainer(user) + 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') + end end - context 'project with a group but no group runner' do - it 'group runners are not available' do - visit project_runners_path(project) + context 'when a project has disabled shared_runners' do + let(:project) { create(:project, shared_runners_enabled: false) } - 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' + it 'shared runners toggle is off' do + expect(page).not_to have_selector('[data-testid="toggle-shared-runners"] .is-checked') end end end - context 'as project maintainer and group owner' do + context 'group runners in project settings' do before do - group.add_owner(user) + project.add_maintainer(user) end - context 'project with a group but no group runner' do - it 'group runners are available' do - visit project_runners_path(project) - - expect(page).to have_content 'This group does not have any group runners yet.' + let_it_be(:group) { create :group } + let_it_be(:project) { create :project, group: group } - expect(page).to have_content 'To register them, go to the group\'s Runners page.' - expect(page).not_to have_content 'Ask your group owner to set up a group runner' + context 'as project and group maintainer' do + before do + group.add_maintainer(user) end - end - end - - context 'as project maintainer' do - context 'project without a group' do - let(:project) { create :project } - it 'group runners are not available' do - visit project_runners_path(project) + context 'project with a group but no group runner' do + it 'group runners are not available' do + visit project_runners_path(project) - expect(page).to have_content 'This project does not belong to a group and cannot make use of group runners.' + 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 end end - context 'with group project' do - let_it_be(:group) { create(:group) } - let_it_be(:project) { create(:project, group: group) } + 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 not available' do + it 'group runners are available' do visit project_runners_path(project) expect(page).to have_content 'This group does not have any group runners yet.' - 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.' + expect(page).to have_content 'To register them, go to the group\'s Runners page.' + expect(page).not_to have_content 'Ask your group owner to set up a group runner' end end + end - context 'project with a group and a group runner' do - let_it_be(:group_runner) do - create(:ci_runner, :group, groups: [group], description: 'group-runner') - end + context 'as project maintainer' do + context 'project without a group' do + let(:project) { create :project } - it 'group runners are available' do + it 'group runners are not available' do visit project_runners_path(project) - expect(page).to have_content 'Available group runners: 1' - expect(page).to have_content 'group-runner' + expect(page).to have_content 'This project does not belong to a group and cannot make use of group runners.' end + end - it 'group runners may be disabled for a project' do - visit project_runners_path(project) - - click_on 'Disable group runners' + context 'with group project' do + let_it_be(:group) { create(:group) } + let_it_be(:project) { create(:project, group: group) } - expect(page).to have_content 'Enable group runners' - expect(project.reload.group_runners_enabled).to be false + context 'project with a group but no group runner' do + it 'group runners are not available' do + visit project_runners_path(project) - click_on 'Enable group runners' + expect(page).to have_content 'This group does not have any group runners yet.' - expect(page).to have_content 'Disable group runners' - expect(project.reload.group_runners_enabled).to be true + 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 end - context 'when multiple group runners are configured' do - let_it_be(:group_runner_2) { create(:ci_runner, :group, groups: [group]) } + context 'project with a group and a group runner' do + let_it_be(:group_runner) do + create(:ci_runner, :group, groups: [group], description: 'group-runner') + end - it 'shows the runner count' do + it 'group runners are available' do visit project_runners_path(project) - within '[data-testid="group-runners"]' do - expect(page).to have_content format(_('Available group runners: %{runners}'), { runners: 2 }) - end + expect(page).to have_content 'Available group runners: 1' + expect(page).to have_content 'group-runner' end - it 'adds pagination to the group runner list' do - stub_const('Projects::Settings::CiCdController::NUMBER_OF_RUNNERS_PER_PAGE', 1) - + it 'group runners may be disabled for a project' do visit project_runners_path(project) - within '[data-testid="group-runners"]' do - expect(find('.pagination')).not_to be_nil + click_on 'Disable group runners' + + expect(page).to have_content 'Enable group runners' + expect(project.reload.group_runners_enabled).to be false + + click_on 'Enable group runners' + + expect(page).to have_content 'Disable group runners' + expect(project.reload.group_runners_enabled).to be true + end + + context 'when multiple group runners are configured' do + let_it_be(:group_runner_2) { create(:ci_runner, :group, groups: [group]) } + + it 'shows the runner count' do + visit project_runners_path(project) + + within '[data-testid="group-runners"]' do + expect(page).to have_content format(_('Available group runners: %{runners}'), { runners: 2 }) + end + end + + it 'adds pagination to the group runner list' do + stub_const('Projects::Settings::CiCdController::NUMBER_OF_RUNNERS_PER_PAGE', 1) + + visit project_runners_path(project) + + within '[data-testid="group-runners"]' do + expect(find('.pagination')).not_to be_nil + end end end end |