2019-12-26 22:10:19 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-04-02 18:10:28 +05:30
|
|
|
require 'spec_helper'
|
|
|
|
|
2023-06-20 00:43:36 +05:30
|
|
|
RSpec.describe API::Ci::Runners, :aggregate_failures, feature_category: :runner_fleet do
|
2020-05-24 23:13:21 +05:30
|
|
|
let_it_be(:admin) { create(:user, :admin) }
|
|
|
|
let_it_be(:user) { create(:user) }
|
|
|
|
let_it_be(:user2) { create(:user) }
|
|
|
|
let_it_be(:group_guest) { create(:user) }
|
|
|
|
let_it_be(:group_reporter) { create(:user) }
|
|
|
|
let_it_be(:group_developer) { create(:user) }
|
|
|
|
let_it_be(:group_maintainer) { create(:user) }
|
|
|
|
|
|
|
|
let_it_be(:project) { create(:project, creator_id: user.id) }
|
|
|
|
let_it_be(:project2) { create(:project, creator_id: user.id) }
|
|
|
|
|
|
|
|
let_it_be(:group) { create(:group).tap { |group| group.add_owner(user) } }
|
|
|
|
let_it_be(:subgroup) { create(:group, parent: group) }
|
|
|
|
|
|
|
|
let_it_be(:shared_runner, reload: true) { create(:ci_runner, :instance, description: 'Shared runner') }
|
|
|
|
let_it_be(:project_runner, reload: true) { create(:ci_runner, :project, description: 'Project runner', projects: [project]) }
|
|
|
|
let_it_be(:two_projects_runner) { create(:ci_runner, :project, description: 'Two projects runner', projects: [project, project2]) }
|
|
|
|
let_it_be(:group_runner_a) { create(:ci_runner, :group, description: 'Group runner A', groups: [group]) }
|
|
|
|
let_it_be(:group_runner_b) { create(:ci_runner, :group, description: 'Group runner B', groups: [subgroup]) }
|
|
|
|
|
|
|
|
before_all do
|
|
|
|
group.add_guest(group_guest)
|
|
|
|
group.add_reporter(group_reporter)
|
|
|
|
group.add_developer(group_developer)
|
|
|
|
group.add_maintainer(group_maintainer)
|
|
|
|
project.add_maintainer(user)
|
|
|
|
project2.add_maintainer(user)
|
|
|
|
project.add_reporter(user2)
|
2016-04-02 18:10:28 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
describe 'GET /runners' do
|
|
|
|
context 'authorized user' do
|
2023-06-20 00:43:36 +05:30
|
|
|
it 'returns response status and headers' do
|
2016-04-02 18:10:28 +05:30
|
|
|
get api('/runners', user)
|
|
|
|
|
2020-04-08 14:13:33 +05:30
|
|
|
expect(response).to have_gitlab_http_status(:ok)
|
2017-08-17 22:00:37 +05:30
|
|
|
expect(response).to include_pagination_headers
|
2018-12-05 23:21:45 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns user available runners' do
|
|
|
|
get api('/runners', user)
|
|
|
|
|
|
|
|
expect(json_response).to match_array [
|
|
|
|
a_hash_including('description' => 'Project runner'),
|
|
|
|
a_hash_including('description' => 'Two projects runner'),
|
2020-04-22 19:07:51 +05:30
|
|
|
a_hash_including('description' => 'Group runner A'),
|
|
|
|
a_hash_including('description' => 'Group runner B')
|
2018-12-05 23:21:45 +05:30
|
|
|
]
|
2016-04-02 18:10:28 +05:30
|
|
|
end
|
|
|
|
|
2023-06-20 00:43:36 +05:30
|
|
|
it 'filters runners by scope' do
|
2018-12-05 23:21:45 +05:30
|
|
|
create(:ci_runner, :project, :inactive, description: 'Inactive project runner', projects: [project])
|
|
|
|
|
|
|
|
get api('/runners?scope=paused', user)
|
2016-04-02 18:10:28 +05:30
|
|
|
|
2020-04-08 14:13:33 +05:30
|
|
|
expect(response).to have_gitlab_http_status(:ok)
|
2017-08-17 22:00:37 +05:30
|
|
|
expect(response).to include_pagination_headers
|
2018-12-05 23:21:45 +05:30
|
|
|
|
|
|
|
expect(json_response).to match_array [
|
|
|
|
a_hash_including('description' => 'Inactive project runner')
|
|
|
|
]
|
2016-04-02 18:10:28 +05:30
|
|
|
end
|
|
|
|
|
2016-09-13 17:45:13 +05:30
|
|
|
it 'avoids filtering if scope is invalid' do
|
2016-04-02 18:10:28 +05:30
|
|
|
get api('/runners?scope=unknown', user)
|
2020-04-08 14:13:33 +05:30
|
|
|
expect(response).to have_gitlab_http_status(:bad_request)
|
2016-04-02 18:10:28 +05:30
|
|
|
end
|
2018-12-05 23:21:45 +05:30
|
|
|
|
|
|
|
it 'filters runners by type' do
|
|
|
|
get api('/runners?type=project_type', user)
|
|
|
|
|
|
|
|
expect(json_response).to match_array [
|
|
|
|
a_hash_including('description' => 'Project runner'),
|
|
|
|
a_hash_including('description' => 'Two projects runner')
|
|
|
|
]
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not filter by invalid type' do
|
|
|
|
get api('/runners?type=bogus', user)
|
|
|
|
|
2020-04-08 14:13:33 +05:30
|
|
|
expect(response).to have_gitlab_http_status(:bad_request)
|
2018-12-05 23:21:45 +05:30
|
|
|
end
|
|
|
|
|
2022-04-04 11:22:00 +05:30
|
|
|
context 'with an inactive runner' do
|
|
|
|
let_it_be(:runner) { create(:ci_runner, :project, :inactive, description: 'Inactive project runner', projects: [project]) }
|
2018-12-05 23:21:45 +05:30
|
|
|
|
2022-04-04 11:22:00 +05:30
|
|
|
it 'filters runners by paused state' do
|
|
|
|
get api('/runners?paused=true', user)
|
2018-12-05 23:21:45 +05:30
|
|
|
|
2022-04-04 11:22:00 +05:30
|
|
|
expect(json_response).to match_array [
|
|
|
|
a_hash_including('description' => 'Inactive project runner')
|
|
|
|
]
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'filters runners by status' do
|
|
|
|
get api('/runners?status=paused', user)
|
|
|
|
|
|
|
|
expect(json_response).to match_array [
|
|
|
|
a_hash_including('description' => 'Inactive project runner')
|
|
|
|
]
|
|
|
|
end
|
2018-12-05 23:21:45 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not filter by invalid status' do
|
|
|
|
get api('/runners?status=bogus', user)
|
|
|
|
|
2020-04-08 14:13:33 +05:30
|
|
|
expect(response).to have_gitlab_http_status(:bad_request)
|
2018-12-05 23:21:45 +05:30
|
|
|
end
|
2019-07-07 11:18:12 +05:30
|
|
|
|
2023-06-20 00:43:36 +05:30
|
|
|
it 'filters runners by tag_list' do
|
2019-07-07 11:18:12 +05:30
|
|
|
create(:ci_runner, :project, description: 'Runner tagged with tag1 and tag2', projects: [project], tag_list: %w[tag1 tag2])
|
|
|
|
create(:ci_runner, :project, description: 'Runner tagged with tag2', projects: [project], tag_list: ['tag2'])
|
|
|
|
|
|
|
|
get api('/runners?tag_list=tag1,tag2', user)
|
|
|
|
|
|
|
|
expect(json_response).to match_array [
|
2022-04-04 11:22:00 +05:30
|
|
|
a_hash_including('description' => 'Runner tagged with tag1 and tag2', 'active' => true, 'paused' => false)
|
2019-07-07 11:18:12 +05:30
|
|
|
]
|
|
|
|
end
|
2016-04-02 18:10:28 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
context 'unauthorized user' do
|
2016-09-13 17:45:13 +05:30
|
|
|
it 'does not return runners' do
|
2016-04-02 18:10:28 +05:30
|
|
|
get api('/runners')
|
|
|
|
|
2020-04-08 14:13:33 +05:30
|
|
|
expect(response).to have_gitlab_http_status(:unauthorized)
|
2016-04-02 18:10:28 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'GET /runners/all' do
|
2023-06-20 00:43:36 +05:30
|
|
|
let(:path) { '/runners/all' }
|
|
|
|
|
|
|
|
it_behaves_like 'GET request permissions for admin mode'
|
|
|
|
|
2016-04-02 18:10:28 +05:30
|
|
|
context 'authorized user' do
|
|
|
|
context 'with admin privileges' do
|
2018-12-05 23:21:45 +05:30
|
|
|
it 'returns response status and headers' do
|
2023-06-20 00:43:36 +05:30
|
|
|
get api(path, admin, admin_mode: true)
|
2018-12-05 23:21:45 +05:30
|
|
|
|
2020-04-08 14:13:33 +05:30
|
|
|
expect(response).to have_gitlab_http_status(:ok)
|
2018-12-05 23:21:45 +05:30
|
|
|
expect(response).to include_pagination_headers
|
|
|
|
end
|
|
|
|
|
2016-09-13 17:45:13 +05:30
|
|
|
it 'returns all runners' do
|
2023-06-20 00:43:36 +05:30
|
|
|
get api(path, admin, admin_mode: true)
|
2016-04-02 18:10:28 +05:30
|
|
|
|
2018-12-05 23:21:45 +05:30
|
|
|
expect(json_response).to match_array [
|
2022-04-04 11:22:00 +05:30
|
|
|
a_hash_including('description' => 'Project runner', 'is_shared' => false, 'active' => true, 'paused' => false, 'runner_type' => 'project_type'),
|
2021-09-04 01:27:46 +05:30
|
|
|
a_hash_including('description' => 'Two projects runner', 'is_shared' => false, 'runner_type' => 'project_type'),
|
|
|
|
a_hash_including('description' => 'Group runner A', 'is_shared' => false, 'runner_type' => 'group_type'),
|
|
|
|
a_hash_including('description' => 'Group runner B', 'is_shared' => false, 'runner_type' => 'group_type'),
|
|
|
|
a_hash_including('description' => 'Shared runner', 'is_shared' => true, 'runner_type' => 'instance_type')
|
2018-12-05 23:21:45 +05:30
|
|
|
]
|
|
|
|
end
|
|
|
|
|
2023-06-20 00:43:36 +05:30
|
|
|
it 'filters runners by scope' do
|
2023-05-27 22:25:52 +05:30
|
|
|
get api('/runners/all?scope=shared', admin, admin_mode: true)
|
2018-12-05 23:21:45 +05:30
|
|
|
|
|
|
|
shared = json_response.all? { |r| r['is_shared'] }
|
2020-04-08 14:13:33 +05:30
|
|
|
expect(response).to have_gitlab_http_status(:ok)
|
2017-08-17 22:00:37 +05:30
|
|
|
expect(response).to include_pagination_headers
|
2016-04-02 18:10:28 +05:30
|
|
|
expect(json_response).to be_an Array
|
2018-11-08 19:23:39 +05:30
|
|
|
expect(json_response[0]).to have_key('ip_address')
|
2016-04-02 18:10:28 +05:30
|
|
|
expect(shared).to be_truthy
|
|
|
|
end
|
|
|
|
|
2023-06-20 00:43:36 +05:30
|
|
|
it 'filters runners by scope' do
|
2023-05-27 22:25:52 +05:30
|
|
|
get api('/runners/all?scope=specific', admin, admin_mode: true)
|
2016-04-02 18:10:28 +05:30
|
|
|
|
2020-04-08 14:13:33 +05:30
|
|
|
expect(response).to have_gitlab_http_status(:ok)
|
2018-12-05 23:21:45 +05:30
|
|
|
expect(response).to include_pagination_headers
|
|
|
|
|
|
|
|
expect(json_response).to match_array [
|
|
|
|
a_hash_including('description' => 'Project runner'),
|
|
|
|
a_hash_including('description' => 'Two projects runner'),
|
2020-04-22 19:07:51 +05:30
|
|
|
a_hash_including('description' => 'Group runner A'),
|
|
|
|
a_hash_including('description' => 'Group runner B')
|
2018-12-05 23:21:45 +05:30
|
|
|
]
|
2016-04-02 18:10:28 +05:30
|
|
|
end
|
|
|
|
|
2018-12-05 23:21:45 +05:30
|
|
|
it 'avoids filtering if scope is invalid' do
|
2023-05-27 22:25:52 +05:30
|
|
|
get api('/runners/all?scope=unknown', admin, admin_mode: true)
|
2020-04-08 14:13:33 +05:30
|
|
|
expect(response).to have_gitlab_http_status(:bad_request)
|
2018-12-05 23:21:45 +05:30
|
|
|
end
|
2018-11-08 19:23:39 +05:30
|
|
|
|
2020-04-22 19:07:51 +05:30
|
|
|
it 'filters runners by project type' do
|
2023-05-27 22:25:52 +05:30
|
|
|
get api('/runners/all?type=project_type', admin, admin_mode: true)
|
2018-11-08 19:23:39 +05:30
|
|
|
|
2018-12-05 23:21:45 +05:30
|
|
|
expect(json_response).to match_array [
|
|
|
|
a_hash_including('description' => 'Project runner'),
|
|
|
|
a_hash_including('description' => 'Two projects runner')
|
|
|
|
]
|
|
|
|
end
|
2016-04-02 18:10:28 +05:30
|
|
|
|
2020-04-22 19:07:51 +05:30
|
|
|
it 'filters runners by group type' do
|
2023-05-27 22:25:52 +05:30
|
|
|
get api('/runners/all?type=group_type', admin, admin_mode: true)
|
2020-04-22 19:07:51 +05:30
|
|
|
|
|
|
|
expect(json_response).to match_array [
|
|
|
|
a_hash_including('description' => 'Group runner A'),
|
|
|
|
a_hash_including('description' => 'Group runner B')
|
|
|
|
]
|
|
|
|
end
|
|
|
|
|
2018-12-05 23:21:45 +05:30
|
|
|
it 'does not filter by invalid type' do
|
2023-05-27 22:25:52 +05:30
|
|
|
get api('/runners/all?type=bogus', admin, admin_mode: true)
|
2018-12-05 23:21:45 +05:30
|
|
|
|
2020-04-08 14:13:33 +05:30
|
|
|
expect(response).to have_gitlab_http_status(:bad_request)
|
2018-12-05 23:21:45 +05:30
|
|
|
end
|
|
|
|
|
2022-04-04 11:22:00 +05:30
|
|
|
context 'with an inactive runner' do
|
|
|
|
let_it_be(:runner) { create(:ci_runner, :project, :inactive, description: 'Inactive project runner', projects: [project]) }
|
2018-12-05 23:21:45 +05:30
|
|
|
|
2022-04-04 11:22:00 +05:30
|
|
|
it 'filters runners by status' do
|
2023-05-27 22:25:52 +05:30
|
|
|
get api('/runners/all?paused=true', admin, admin_mode: true)
|
2018-12-05 23:21:45 +05:30
|
|
|
|
2022-04-04 11:22:00 +05:30
|
|
|
expect(json_response).to match_array [
|
|
|
|
a_hash_including('description' => 'Inactive project runner')
|
|
|
|
]
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'filters runners by status' do
|
2023-05-27 22:25:52 +05:30
|
|
|
get api('/runners/all?status=paused', admin, admin_mode: true)
|
2022-04-04 11:22:00 +05:30
|
|
|
|
|
|
|
expect(json_response).to match_array [
|
|
|
|
a_hash_including('description' => 'Inactive project runner')
|
|
|
|
]
|
|
|
|
end
|
2018-12-05 23:21:45 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not filter by invalid status' do
|
2023-05-27 22:25:52 +05:30
|
|
|
get api('/runners/all?status=bogus', admin, admin_mode: true)
|
2018-12-05 23:21:45 +05:30
|
|
|
|
2020-04-08 14:13:33 +05:30
|
|
|
expect(response).to have_gitlab_http_status(:bad_request)
|
2018-12-05 23:21:45 +05:30
|
|
|
end
|
2019-07-07 11:18:12 +05:30
|
|
|
|
2023-06-20 00:43:36 +05:30
|
|
|
it 'filters runners by tag_list' do
|
2019-07-07 11:18:12 +05:30
|
|
|
create(:ci_runner, :project, description: 'Runner tagged with tag1 and tag2', projects: [project], tag_list: %w[tag1 tag2])
|
|
|
|
create(:ci_runner, :project, description: 'Runner tagged with tag2', projects: [project], tag_list: ['tag2'])
|
|
|
|
|
2023-05-27 22:25:52 +05:30
|
|
|
get api('/runners/all?tag_list=tag1,tag2', admin, admin_mode: true)
|
2019-07-07 11:18:12 +05:30
|
|
|
|
|
|
|
expect(json_response).to match_array [
|
|
|
|
a_hash_including('description' => 'Runner tagged with tag1 and tag2')
|
|
|
|
]
|
|
|
|
end
|
2016-04-02 18:10:28 +05:30
|
|
|
end
|
|
|
|
|
2018-12-05 23:21:45 +05:30
|
|
|
context 'without admin privileges' do
|
|
|
|
it 'does not return runners list' do
|
2023-06-20 00:43:36 +05:30
|
|
|
get api(path, user)
|
2018-12-05 23:21:45 +05:30
|
|
|
|
2020-04-08 14:13:33 +05:30
|
|
|
expect(response).to have_gitlab_http_status(:forbidden)
|
2018-12-05 23:21:45 +05:30
|
|
|
end
|
2016-04-02 18:10:28 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'unauthorized user' do
|
2016-09-13 17:45:13 +05:30
|
|
|
it 'does not return runners' do
|
2016-04-02 18:10:28 +05:30
|
|
|
get api('/runners')
|
|
|
|
|
2020-04-08 14:13:33 +05:30
|
|
|
expect(response).to have_gitlab_http_status(:unauthorized)
|
2016-04-02 18:10:28 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'GET /runners/:id' do
|
2023-06-20 00:43:36 +05:30
|
|
|
let(:path) { "/runners/#{project_runner.id}" }
|
|
|
|
|
|
|
|
it_behaves_like 'GET request permissions for admin mode'
|
|
|
|
|
2016-04-02 18:10:28 +05:30
|
|
|
context 'admin user' do
|
|
|
|
context 'when runner is shared' do
|
2023-06-20 00:43:36 +05:30
|
|
|
it "returns runner's details" do
|
2016-04-02 18:10:28 +05:30
|
|
|
get api("/runners/#{shared_runner.id}", admin)
|
|
|
|
|
2020-04-08 14:13:33 +05:30
|
|
|
expect(response).to have_gitlab_http_status(:ok)
|
2016-04-02 18:10:28 +05:30
|
|
|
expect(json_response['description']).to eq(shared_runner.description)
|
2018-05-09 12:01:36 +05:30
|
|
|
expect(json_response['maximum_timeout']).to be_nil
|
2022-07-16 23:28:13 +05:30
|
|
|
expect(json_response['status']).to eq('never_contacted')
|
2022-04-04 11:22:00 +05:30
|
|
|
expect(json_response['active']).to eq(true)
|
|
|
|
expect(json_response['paused']).to eq(false)
|
2016-04-02 18:10:28 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when runner is not shared' do
|
2018-11-08 19:23:39 +05:30
|
|
|
context 'when unused runner is present' do
|
|
|
|
let!(:unused_project_runner) { create(:ci_runner, :project, :without_projects) }
|
|
|
|
|
2023-06-20 00:43:36 +05:30
|
|
|
it 'deletes unused runner' do
|
2018-11-08 19:23:39 +05:30
|
|
|
expect do
|
2023-05-27 22:25:52 +05:30
|
|
|
delete api("/runners/#{unused_project_runner.id}", admin, admin_mode: true)
|
2018-11-08 19:23:39 +05:30
|
|
|
|
2020-04-08 14:13:33 +05:30
|
|
|
expect(response).to have_gitlab_http_status(:no_content)
|
2020-07-28 23:09:34 +05:30
|
|
|
end.to change { ::Ci::Runner.project_type.count }.by(-1)
|
2018-11-08 19:23:39 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2023-06-20 00:43:36 +05:30
|
|
|
it "returns runner's details" do
|
|
|
|
get api(path, admin, admin_mode: true)
|
2016-04-02 18:10:28 +05:30
|
|
|
|
2020-04-08 14:13:33 +05:30
|
|
|
expect(response).to have_gitlab_http_status(:ok)
|
2018-10-15 14:42:47 +05:30
|
|
|
expect(json_response['description']).to eq(project_runner.description)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "returns the project's details for a project runner" do
|
2023-06-20 00:43:36 +05:30
|
|
|
get api(path, admin, admin_mode: true)
|
2018-10-15 14:42:47 +05:30
|
|
|
|
|
|
|
expect(json_response['projects'].first['id']).to eq(project.id)
|
2016-04-02 18:10:28 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-07-28 23:09:34 +05:30
|
|
|
it 'returns 404 if runner does not exist' do
|
2023-06-20 00:43:36 +05:30
|
|
|
get api("/runners/#{non_existing_record_id}", admin, admin_mode: true)
|
2016-04-02 18:10:28 +05:30
|
|
|
|
2020-04-08 14:13:33 +05:30
|
|
|
expect(response).to have_gitlab_http_status(:not_found)
|
2016-04-02 18:10:28 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-11-18 22:05:49 +05:30
|
|
|
context 'when the runner is a group runner' do
|
2023-06-20 00:43:36 +05:30
|
|
|
it "returns the runner's details" do
|
2023-05-27 22:25:52 +05:30
|
|
|
get api("/runners/#{group_runner_a.id}", admin, admin_mode: true)
|
2021-11-18 22:05:49 +05:30
|
|
|
|
|
|
|
expect(response).to have_gitlab_http_status(:ok)
|
|
|
|
expect(json_response['description']).to eq(group_runner_a.description)
|
|
|
|
expect(json_response['groups'].first['id']).to eq(group.id)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-04-02 18:10:28 +05:30
|
|
|
context "runner project's administrative user" do
|
|
|
|
context 'when runner is not shared' do
|
2023-06-20 00:43:36 +05:30
|
|
|
it "returns runner's details" do
|
|
|
|
get api(path, user)
|
2016-04-02 18:10:28 +05:30
|
|
|
|
2020-04-08 14:13:33 +05:30
|
|
|
expect(response).to have_gitlab_http_status(:ok)
|
2018-10-15 14:42:47 +05:30
|
|
|
expect(json_response['description']).to eq(project_runner.description)
|
2016-04-02 18:10:28 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when runner is shared' do
|
2023-06-20 00:43:36 +05:30
|
|
|
it "returns runner's details" do
|
2016-04-02 18:10:28 +05:30
|
|
|
get api("/runners/#{shared_runner.id}", user)
|
|
|
|
|
2020-04-08 14:13:33 +05:30
|
|
|
expect(response).to have_gitlab_http_status(:ok)
|
2016-04-02 18:10:28 +05:30
|
|
|
expect(json_response['description']).to eq(shared_runner.description)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'other authorized user' do
|
2018-10-15 14:42:47 +05:30
|
|
|
it "does not return project runner's details" do
|
2023-06-20 00:43:36 +05:30
|
|
|
get api(path, user2)
|
2016-04-02 18:10:28 +05:30
|
|
|
|
2020-04-08 14:13:33 +05:30
|
|
|
expect(response).to have_gitlab_http_status(:forbidden)
|
2016-04-02 18:10:28 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'unauthorized user' do
|
2018-10-15 14:42:47 +05:30
|
|
|
it "does not return project runner's details" do
|
2023-06-20 00:43:36 +05:30
|
|
|
get api(path)
|
2016-04-02 18:10:28 +05:30
|
|
|
|
2020-04-08 14:13:33 +05:30
|
|
|
expect(response).to have_gitlab_http_status(:unauthorized)
|
2016-04-02 18:10:28 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'PUT /runners/:id' do
|
2023-06-20 00:43:36 +05:30
|
|
|
let(:path) { "/runners/#{project_runner.id}" }
|
|
|
|
|
|
|
|
it_behaves_like 'PUT request permissions for admin mode' do
|
|
|
|
let(:params) { { description: 'test' } }
|
|
|
|
end
|
|
|
|
|
2016-04-02 18:10:28 +05:30
|
|
|
context 'admin user' do
|
2019-12-04 20:38:33 +05:30
|
|
|
# see https://gitlab.com/gitlab-org/gitlab-foss/issues/48625
|
2018-11-18 11:00:15 +05:30
|
|
|
context 'single parameter update' do
|
|
|
|
it 'runner description' do
|
|
|
|
description = shared_runner.description
|
|
|
|
update_runner(shared_runner.id, admin, description: "#{description}_updated")
|
|
|
|
|
2020-04-08 14:13:33 +05:30
|
|
|
expect(response).to have_gitlab_http_status(:ok)
|
2018-11-18 11:00:15 +05:30
|
|
|
expect(shared_runner.reload.description).to eq("#{description}_updated")
|
|
|
|
end
|
|
|
|
|
2023-06-20 00:43:36 +05:30
|
|
|
it 'runner active state' do
|
2018-11-18 11:00:15 +05:30
|
|
|
active = shared_runner.active
|
|
|
|
update_runner(shared_runner.id, admin, active: !active)
|
|
|
|
|
2020-04-08 14:13:33 +05:30
|
|
|
expect(response).to have_gitlab_http_status(:ok)
|
2018-11-18 11:00:15 +05:30
|
|
|
expect(shared_runner.reload.active).to eq(!active)
|
|
|
|
end
|
|
|
|
|
2023-06-20 00:43:36 +05:30
|
|
|
it 'runner paused state' do
|
2022-04-04 11:22:00 +05:30
|
|
|
active = shared_runner.active
|
|
|
|
update_runner(shared_runner.id, admin, paused: active)
|
|
|
|
|
|
|
|
expect(response).to have_gitlab_http_status(:ok)
|
|
|
|
expect(shared_runner.reload.active).to eq(!active)
|
|
|
|
end
|
|
|
|
|
2023-06-20 00:43:36 +05:30
|
|
|
it 'runner tag list' do
|
2018-11-18 11:00:15 +05:30
|
|
|
update_runner(shared_runner.id, admin, tag_list: ['ruby2.1', 'pgsql', 'mysql'])
|
|
|
|
|
2020-04-08 14:13:33 +05:30
|
|
|
expect(response).to have_gitlab_http_status(:ok)
|
2018-11-18 11:00:15 +05:30
|
|
|
expect(shared_runner.reload.tag_list).to include('ruby2.1', 'pgsql', 'mysql')
|
|
|
|
end
|
|
|
|
|
2023-06-20 00:43:36 +05:30
|
|
|
it 'unrelated runner attribute on an existing runner with too many tags' do
|
2022-04-01 21:47:47 +05:30
|
|
|
# This test ensures that it is possible to update any attribute on a runner that currently fails the
|
|
|
|
# validation that ensures that there aren't too many tags associated with a runner
|
2023-01-13 00:05:48 +05:30
|
|
|
existing_invalid_shared_runner = build(:ci_runner, :instance, tag_list: (1..::Ci::Runner::TAG_LIST_MAX_LENGTH + 1).map { |i| "tag#{i}" })
|
2022-04-01 21:47:47 +05:30
|
|
|
existing_invalid_shared_runner.save!(validate: false)
|
|
|
|
|
|
|
|
active = existing_invalid_shared_runner.active
|
2022-04-04 11:22:00 +05:30
|
|
|
update_runner(existing_invalid_shared_runner.id, admin, paused: active)
|
2022-04-01 21:47:47 +05:30
|
|
|
|
|
|
|
expect(response).to have_gitlab_http_status(:ok)
|
|
|
|
expect(existing_invalid_shared_runner.reload.active).to eq(!active)
|
|
|
|
end
|
|
|
|
|
2023-06-20 00:43:36 +05:30
|
|
|
it 'runner untagged flag' do
|
2018-11-18 11:00:15 +05:30
|
|
|
# Ensure tag list is non-empty before setting untagged to false.
|
|
|
|
update_runner(shared_runner.id, admin, tag_list: ['ruby2.1', 'pgsql', 'mysql'])
|
|
|
|
update_runner(shared_runner.id, admin, run_untagged: 'false')
|
|
|
|
|
2020-04-08 14:13:33 +05:30
|
|
|
expect(response).to have_gitlab_http_status(:ok)
|
2018-11-18 11:00:15 +05:30
|
|
|
expect(shared_runner.reload.run_untagged?).to be(false)
|
|
|
|
end
|
|
|
|
|
2023-06-20 00:43:36 +05:30
|
|
|
it 'runner unlocked flag' do
|
2018-11-18 11:00:15 +05:30
|
|
|
update_runner(shared_runner.id, admin, locked: 'true')
|
|
|
|
|
2020-04-08 14:13:33 +05:30
|
|
|
expect(response).to have_gitlab_http_status(:ok)
|
2018-11-18 11:00:15 +05:30
|
|
|
expect(shared_runner.reload.locked?).to be(true)
|
|
|
|
end
|
|
|
|
|
2023-06-20 00:43:36 +05:30
|
|
|
it 'runner access level' do
|
2018-11-18 11:00:15 +05:30
|
|
|
update_runner(shared_runner.id, admin, access_level: 'ref_protected')
|
|
|
|
|
2020-04-08 14:13:33 +05:30
|
|
|
expect(response).to have_gitlab_http_status(:ok)
|
2018-11-18 11:00:15 +05:30
|
|
|
expect(shared_runner.reload.ref_protected?).to be_truthy
|
|
|
|
end
|
|
|
|
|
2023-06-20 00:43:36 +05:30
|
|
|
it 'runner maximum timeout' do
|
2018-11-18 11:00:15 +05:30
|
|
|
update_runner(shared_runner.id, admin, maximum_timeout: 1234)
|
|
|
|
|
2020-04-08 14:13:33 +05:30
|
|
|
expect(response).to have_gitlab_http_status(:ok)
|
2018-11-18 11:00:15 +05:30
|
|
|
expect(shared_runner.reload.maximum_timeout).to eq(1234)
|
|
|
|
end
|
|
|
|
|
2023-06-20 00:43:36 +05:30
|
|
|
it 'fails with no parameters' do
|
2018-11-18 11:00:15 +05:30
|
|
|
put api("/runners/#{shared_runner.id}", admin)
|
|
|
|
|
|
|
|
shared_runner.reload
|
2020-04-08 14:13:33 +05:30
|
|
|
expect(response).to have_gitlab_http_status(:bad_request)
|
2018-11-18 11:00:15 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-04-02 18:10:28 +05:30
|
|
|
context 'when runner is shared' do
|
2023-06-20 00:43:36 +05:30
|
|
|
it 'updates runner' do
|
2016-04-02 18:10:28 +05:30
|
|
|
description = shared_runner.description
|
|
|
|
active = shared_runner.active
|
2017-08-17 22:00:37 +05:30
|
|
|
runner_queue_value = shared_runner.ensure_runner_queue_value
|
2016-04-02 18:10:28 +05:30
|
|
|
|
2016-06-02 11:05:42 +05:30
|
|
|
update_runner(shared_runner.id, admin, description: "#{description}_updated",
|
|
|
|
active: !active,
|
|
|
|
tag_list: ['ruby2.1', 'pgsql', 'mysql'],
|
2016-06-22 15:30:34 +05:30
|
|
|
run_untagged: 'false',
|
2018-03-17 18:26:18 +05:30
|
|
|
locked: 'true',
|
2018-05-09 12:01:36 +05:30
|
|
|
access_level: 'ref_protected',
|
|
|
|
maximum_timeout: 1234)
|
2016-04-02 18:10:28 +05:30
|
|
|
shared_runner.reload
|
|
|
|
|
2020-04-08 14:13:33 +05:30
|
|
|
expect(response).to have_gitlab_http_status(:ok)
|
2016-04-02 18:10:28 +05:30
|
|
|
expect(shared_runner.description).to eq("#{description}_updated")
|
|
|
|
expect(shared_runner.active).to eq(!active)
|
|
|
|
expect(shared_runner.tag_list).to include('ruby2.1', 'pgsql', 'mysql')
|
2016-06-22 15:30:34 +05:30
|
|
|
expect(shared_runner.run_untagged?).to be(false)
|
|
|
|
expect(shared_runner.locked?).to be(true)
|
2018-03-17 18:26:18 +05:30
|
|
|
expect(shared_runner.ref_protected?).to be_truthy
|
2017-08-17 22:00:37 +05:30
|
|
|
expect(shared_runner.ensure_runner_queue_value)
|
|
|
|
.not_to eq(runner_queue_value)
|
2018-05-09 12:01:36 +05:30
|
|
|
expect(shared_runner.maximum_timeout).to eq(1234)
|
2016-04-02 18:10:28 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when runner is not shared' do
|
2023-06-20 00:43:36 +05:30
|
|
|
it 'updates runner' do
|
2018-10-15 14:42:47 +05:30
|
|
|
description = project_runner.description
|
|
|
|
runner_queue_value = project_runner.ensure_runner_queue_value
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2018-10-15 14:42:47 +05:30
|
|
|
update_runner(project_runner.id, admin, description: 'test')
|
|
|
|
project_runner.reload
|
2016-04-02 18:10:28 +05:30
|
|
|
|
2020-04-08 14:13:33 +05:30
|
|
|
expect(response).to have_gitlab_http_status(:ok)
|
2018-10-15 14:42:47 +05:30
|
|
|
expect(project_runner.description).to eq('test')
|
|
|
|
expect(project_runner.description).not_to eq(description)
|
|
|
|
expect(project_runner.ensure_runner_queue_value)
|
2017-08-17 22:00:37 +05:30
|
|
|
.not_to eq(runner_queue_value)
|
2016-04-02 18:10:28 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-07-28 23:09:34 +05:30
|
|
|
it 'returns 404 if runner does not exist' do
|
2023-06-20 00:43:36 +05:30
|
|
|
update_runner(non_existing_record_id, admin, description: 'test')
|
2016-04-02 18:10:28 +05:30
|
|
|
|
2020-04-08 14:13:33 +05:30
|
|
|
expect(response).to have_gitlab_http_status(:not_found)
|
2016-04-02 18:10:28 +05:30
|
|
|
end
|
2016-06-02 11:05:42 +05:30
|
|
|
|
|
|
|
def update_runner(id, user, args)
|
2023-05-27 22:25:52 +05:30
|
|
|
put api("/runners/#{id}", user, admin_mode: true), params: args
|
2016-06-02 11:05:42 +05:30
|
|
|
end
|
2016-04-02 18:10:28 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
context 'authorized user' do
|
2023-05-27 22:25:52 +05:30
|
|
|
let_it_be(:params) { { description: 'test' } }
|
|
|
|
|
2016-04-02 18:10:28 +05:30
|
|
|
context 'when runner is shared' do
|
2016-09-13 17:45:13 +05:30
|
|
|
it 'does not update runner' do
|
2023-05-27 22:25:52 +05:30
|
|
|
put api("/runners/#{shared_runner.id}", user), params: params
|
2016-04-02 18:10:28 +05:30
|
|
|
|
2020-04-08 14:13:33 +05:30
|
|
|
expect(response).to have_gitlab_http_status(:forbidden)
|
2016-04-02 18:10:28 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when runner is not shared' do
|
2018-10-15 14:42:47 +05:30
|
|
|
it 'does not update project runner without access to it' do
|
2023-06-20 00:43:36 +05:30
|
|
|
put api(path, user2), params: { description: 'test' }
|
2016-04-02 18:10:28 +05:30
|
|
|
|
2020-04-08 14:13:33 +05:30
|
|
|
expect(response).to have_gitlab_http_status(:forbidden)
|
2016-04-02 18:10:28 +05:30
|
|
|
end
|
|
|
|
|
2023-06-20 00:43:36 +05:30
|
|
|
it 'updates project runner with access to it' do
|
2018-10-15 14:42:47 +05:30
|
|
|
description = project_runner.description
|
2023-06-20 00:43:36 +05:30
|
|
|
put api(path, admin, admin_mode: true), params: params
|
2018-10-15 14:42:47 +05:30
|
|
|
project_runner.reload
|
2016-04-02 18:10:28 +05:30
|
|
|
|
2018-10-15 14:42:47 +05:30
|
|
|
expect(project_runner.description).to eq('test')
|
|
|
|
expect(project_runner.description).not_to eq(description)
|
2016-04-02 18:10:28 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'unauthorized user' do
|
2018-10-15 14:42:47 +05:30
|
|
|
it 'does not delete project runner' do
|
2023-06-20 00:43:36 +05:30
|
|
|
put api(path)
|
2016-04-02 18:10:28 +05:30
|
|
|
|
2020-04-08 14:13:33 +05:30
|
|
|
expect(response).to have_gitlab_http_status(:unauthorized)
|
2016-04-02 18:10:28 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'DELETE /runners/:id' do
|
2023-06-20 00:43:36 +05:30
|
|
|
let(:path) { "/runners/#{shared_runner.id}" }
|
|
|
|
|
|
|
|
it_behaves_like 'DELETE request permissions for admin mode'
|
|
|
|
|
2016-04-02 18:10:28 +05:30
|
|
|
context 'admin user' do
|
|
|
|
context 'when runner is shared' do
|
2023-06-20 00:43:36 +05:30
|
|
|
it 'deletes runner' do
|
2022-05-07 20:08:51 +05:30
|
|
|
expect_next_instance_of(Ci::Runners::UnregisterRunnerService, shared_runner, admin) do |service|
|
2022-04-04 11:22:00 +05:30
|
|
|
expect(service).to receive(:execute).once.and_call_original
|
|
|
|
end
|
|
|
|
|
2016-04-02 18:10:28 +05:30
|
|
|
expect do
|
2023-06-20 00:43:36 +05:30
|
|
|
delete api(path, admin, admin_mode: true)
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2020-04-08 14:13:33 +05:30
|
|
|
expect(response).to have_gitlab_http_status(:no_content)
|
2020-07-28 23:09:34 +05:30
|
|
|
end.to change { ::Ci::Runner.instance_type.count }.by(-1)
|
2018-03-17 18:26:18 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
it_behaves_like '412 response' do
|
2023-06-20 00:43:36 +05:30
|
|
|
let(:request) { api(path, admin, admin_mode: true) }
|
2016-04-02 18:10:28 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when runner is not shared' do
|
2023-06-20 00:43:36 +05:30
|
|
|
it 'deletes used project runner' do
|
2022-05-07 20:08:51 +05:30
|
|
|
expect_next_instance_of(Ci::Runners::UnregisterRunnerService, project_runner, admin) do |service|
|
2022-04-04 11:22:00 +05:30
|
|
|
expect(service).to receive(:execute).once.and_call_original
|
|
|
|
end
|
|
|
|
|
2016-04-02 18:10:28 +05:30
|
|
|
expect do
|
2023-05-27 22:25:52 +05:30
|
|
|
delete api("/runners/#{project_runner.id}", admin, admin_mode: true)
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2020-04-08 14:13:33 +05:30
|
|
|
expect(response).to have_gitlab_http_status(:no_content)
|
2020-07-28 23:09:34 +05:30
|
|
|
end.to change { ::Ci::Runner.project_type.count }.by(-1)
|
2016-04-02 18:10:28 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2023-06-20 00:43:36 +05:30
|
|
|
it 'returns 404 if runner does not exist' do
|
2022-05-07 20:08:51 +05:30
|
|
|
allow_next_instance_of(Ci::Runners::UnregisterRunnerService) do |service|
|
2022-04-04 11:22:00 +05:30
|
|
|
expect(service).not_to receive(:execute)
|
|
|
|
end
|
|
|
|
|
2023-06-20 00:43:36 +05:30
|
|
|
delete api("/runners/#{non_existing_record_id}", admin, admin_mode: true)
|
2016-04-02 18:10:28 +05:30
|
|
|
|
2020-04-08 14:13:33 +05:30
|
|
|
expect(response).to have_gitlab_http_status(:not_found)
|
2016-04-02 18:10:28 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'authorized user' do
|
|
|
|
context 'when runner is shared' do
|
2016-09-13 17:45:13 +05:30
|
|
|
it 'does not delete runner' do
|
2023-06-20 00:43:36 +05:30
|
|
|
delete api(path, user)
|
2020-04-08 14:13:33 +05:30
|
|
|
expect(response).to have_gitlab_http_status(:forbidden)
|
2016-04-02 18:10:28 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when runner is not shared' do
|
2016-09-13 17:45:13 +05:30
|
|
|
it 'does not delete runner without access to it' do
|
2018-10-15 14:42:47 +05:30
|
|
|
delete api("/runners/#{project_runner.id}", user2)
|
2020-04-08 14:13:33 +05:30
|
|
|
expect(response).to have_gitlab_http_status(:forbidden)
|
2016-04-02 18:10:28 +05:30
|
|
|
end
|
|
|
|
|
2018-10-15 14:42:47 +05:30
|
|
|
it 'does not delete project runner with more than one associated project' do
|
2016-04-02 18:10:28 +05:30
|
|
|
delete api("/runners/#{two_projects_runner.id}", user)
|
2020-04-08 14:13:33 +05:30
|
|
|
expect(response).to have_gitlab_http_status(:forbidden)
|
2016-04-02 18:10:28 +05:30
|
|
|
end
|
|
|
|
|
2023-06-20 00:43:36 +05:30
|
|
|
it 'deletes project runner for one owned project' do
|
2016-04-02 18:10:28 +05:30
|
|
|
expect do
|
2018-10-15 14:42:47 +05:30
|
|
|
delete api("/runners/#{project_runner.id}", user)
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2020-04-08 14:13:33 +05:30
|
|
|
expect(response).to have_gitlab_http_status(:no_content)
|
2020-07-28 23:09:34 +05:30
|
|
|
end.to change { ::Ci::Runner.project_type.count }.by(-1)
|
2018-03-17 18:26:18 +05:30
|
|
|
end
|
|
|
|
|
2020-04-22 19:07:51 +05:30
|
|
|
it 'does not delete group runner with guest access' do
|
|
|
|
delete api("/runners/#{group_runner_a.id}", group_guest)
|
|
|
|
|
|
|
|
expect(response).to have_gitlab_http_status(:forbidden)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not delete group runner with reporter access' do
|
|
|
|
delete api("/runners/#{group_runner_a.id}", group_reporter)
|
|
|
|
|
|
|
|
expect(response).to have_gitlab_http_status(:forbidden)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not delete group runner with developer access' do
|
|
|
|
delete api("/runners/#{group_runner_a.id}", group_developer)
|
|
|
|
|
|
|
|
expect(response).to have_gitlab_http_status(:forbidden)
|
|
|
|
end
|
|
|
|
|
2020-01-03 18:37:03 +05:30
|
|
|
it 'does not delete group runner with maintainer access' do
|
2020-04-22 19:07:51 +05:30
|
|
|
delete api("/runners/#{group_runner_a.id}", group_maintainer)
|
2020-01-03 18:37:03 +05:30
|
|
|
|
2020-04-08 14:13:33 +05:30
|
|
|
expect(response).to have_gitlab_http_status(:forbidden)
|
2020-01-03 18:37:03 +05:30
|
|
|
end
|
|
|
|
|
2020-04-22 19:07:51 +05:30
|
|
|
it 'deletes owned group runner with owner access' do
|
|
|
|
expect do
|
|
|
|
delete api("/runners/#{group_runner_a.id}", user)
|
|
|
|
|
|
|
|
expect(response).to have_gitlab_http_status(:no_content)
|
2020-07-28 23:09:34 +05:30
|
|
|
end.to change { ::Ci::Runner.group_type.count }.by(-1)
|
2020-04-22 19:07:51 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
it 'deletes inherited group runner with owner access' do
|
2020-01-03 18:37:03 +05:30
|
|
|
expect do
|
2020-04-22 19:07:51 +05:30
|
|
|
delete api("/runners/#{group_runner_b.id}", user)
|
2020-01-03 18:37:03 +05:30
|
|
|
|
2020-04-08 14:13:33 +05:30
|
|
|
expect(response).to have_gitlab_http_status(:no_content)
|
2020-07-28 23:09:34 +05:30
|
|
|
end.to change { ::Ci::Runner.group_type.count }.by(-1)
|
2020-01-03 18:37:03 +05:30
|
|
|
end
|
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
it_behaves_like '412 response' do
|
2018-10-15 14:42:47 +05:30
|
|
|
let(:request) { api("/runners/#{project_runner.id}", user) }
|
2016-04-02 18:10:28 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'unauthorized user' do
|
2023-06-20 00:43:36 +05:30
|
|
|
it 'does not delete project runner' do
|
2022-05-07 20:08:51 +05:30
|
|
|
allow_next_instance_of(Ci::Runners::UnregisterRunnerService) do |service|
|
2022-04-04 11:22:00 +05:30
|
|
|
expect(service).not_to receive(:execute)
|
|
|
|
end
|
|
|
|
|
2018-10-15 14:42:47 +05:30
|
|
|
delete api("/runners/#{project_runner.id}")
|
2016-04-02 18:10:28 +05:30
|
|
|
|
2020-04-08 14:13:33 +05:30
|
|
|
expect(response).to have_gitlab_http_status(:unauthorized)
|
2018-03-17 18:26:18 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-11-18 22:05:49 +05:30
|
|
|
describe 'POST /runners/:id/reset_authentication_token' do
|
2023-06-20 00:43:36 +05:30
|
|
|
let(:path) { "/runners/#{shared_runner.id}/reset_authentication_token" }
|
|
|
|
|
|
|
|
it_behaves_like 'POST request permissions for admin mode' do
|
|
|
|
let(:params) { {} }
|
|
|
|
end
|
|
|
|
|
2021-11-18 22:05:49 +05:30
|
|
|
context 'admin user' do
|
2023-06-20 00:43:36 +05:30
|
|
|
it 'resets shared runner authentication token' do
|
2021-11-18 22:05:49 +05:30
|
|
|
expect do
|
2023-06-20 00:43:36 +05:30
|
|
|
post api(path, admin, admin_mode: true)
|
2021-11-18 22:05:49 +05:30
|
|
|
|
|
|
|
expect(response).to have_gitlab_http_status(:success)
|
2022-04-04 11:22:00 +05:30
|
|
|
expect(json_response).to eq({ 'token' => shared_runner.reload.token, 'token_expires_at' => nil })
|
2021-11-18 22:05:49 +05:30
|
|
|
end.to change { shared_runner.reload.token }
|
|
|
|
end
|
|
|
|
|
2023-06-20 00:43:36 +05:30
|
|
|
it 'returns 404 if runner does not exist' do
|
|
|
|
post api("/runners/#{non_existing_record_id}/reset_authentication_token", admin, admin_mode: true)
|
2021-11-18 22:05:49 +05:30
|
|
|
|
|
|
|
expect(response).to have_gitlab_http_status(:not_found)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'authorized user' do
|
2023-06-20 00:43:36 +05:30
|
|
|
it 'does not reset project runner authentication token without access to it' do
|
2021-11-18 22:05:49 +05:30
|
|
|
expect do
|
|
|
|
post api("/runners/#{project_runner.id}/reset_authentication_token", user2)
|
|
|
|
expect(response).to have_gitlab_http_status(:forbidden)
|
|
|
|
end.not_to change { project_runner.reload.token }
|
|
|
|
end
|
|
|
|
|
2023-06-20 00:43:36 +05:30
|
|
|
it 'resets project runner authentication token for owned project' do
|
2021-11-18 22:05:49 +05:30
|
|
|
expect do
|
|
|
|
post api("/runners/#{project_runner.id}/reset_authentication_token", user)
|
|
|
|
|
|
|
|
expect(response).to have_gitlab_http_status(:success)
|
2022-04-04 11:22:00 +05:30
|
|
|
expect(json_response).to eq({ 'token' => project_runner.reload.token, 'token_expires_at' => nil })
|
2021-11-18 22:05:49 +05:30
|
|
|
end.to change { project_runner.reload.token }
|
|
|
|
end
|
|
|
|
|
2023-06-20 00:43:36 +05:30
|
|
|
it 'does not reset group runner authentication token with guest access' do
|
2021-11-18 22:05:49 +05:30
|
|
|
expect do
|
|
|
|
post api("/runners/#{group_runner_a.id}/reset_authentication_token", group_guest)
|
|
|
|
|
|
|
|
expect(response).to have_gitlab_http_status(:forbidden)
|
|
|
|
end.not_to change { group_runner_a.reload.token }
|
|
|
|
end
|
|
|
|
|
2023-06-20 00:43:36 +05:30
|
|
|
it 'does not reset group runner authentication token with reporter access' do
|
2021-11-18 22:05:49 +05:30
|
|
|
expect do
|
|
|
|
post api("/runners/#{group_runner_a.id}/reset_authentication_token", group_reporter)
|
|
|
|
|
|
|
|
expect(response).to have_gitlab_http_status(:forbidden)
|
|
|
|
end.not_to change { group_runner_a.reload.token }
|
|
|
|
end
|
|
|
|
|
2023-06-20 00:43:36 +05:30
|
|
|
it 'does not reset group runner authentication token with developer access' do
|
2021-11-18 22:05:49 +05:30
|
|
|
expect do
|
|
|
|
post api("/runners/#{group_runner_a.id}/reset_authentication_token", group_developer)
|
|
|
|
|
|
|
|
expect(response).to have_gitlab_http_status(:forbidden)
|
|
|
|
end.not_to change { group_runner_a.reload.token }
|
|
|
|
end
|
|
|
|
|
2023-06-20 00:43:36 +05:30
|
|
|
it 'does not reset group runner authentication token with maintainer access' do
|
2021-11-18 22:05:49 +05:30
|
|
|
expect do
|
|
|
|
post api("/runners/#{group_runner_a.id}/reset_authentication_token", group_maintainer)
|
|
|
|
|
|
|
|
expect(response).to have_gitlab_http_status(:forbidden)
|
|
|
|
end.not_to change { group_runner_a.reload.token }
|
|
|
|
end
|
|
|
|
|
2023-06-20 00:43:36 +05:30
|
|
|
it 'resets group runner authentication token with owner access' do
|
2021-11-18 22:05:49 +05:30
|
|
|
expect do
|
|
|
|
post api("/runners/#{group_runner_a.id}/reset_authentication_token", user)
|
|
|
|
|
|
|
|
expect(response).to have_gitlab_http_status(:success)
|
2022-04-04 11:22:00 +05:30
|
|
|
expect(json_response).to eq({ 'token' => group_runner_a.reload.token, 'token_expires_at' => nil })
|
|
|
|
end.to change { group_runner_a.reload.token }
|
|
|
|
end
|
|
|
|
|
2023-06-20 00:43:36 +05:30
|
|
|
it 'resets group runner authentication token with owner access with expiration time', :freeze_time do
|
2022-04-04 11:22:00 +05:30
|
|
|
expect(group_runner_a.reload.token_expires_at).to be_nil
|
|
|
|
|
|
|
|
group.update!(runner_token_expiration_interval: 5.days)
|
|
|
|
|
|
|
|
expect do
|
|
|
|
post api("/runners/#{group_runner_a.id}/reset_authentication_token", user)
|
|
|
|
group_runner_a.reload
|
|
|
|
|
|
|
|
expect(response).to have_gitlab_http_status(:success)
|
|
|
|
expect(json_response).to eq({ 'token' => group_runner_a.token, 'token_expires_at' => group_runner_a.token_expires_at.iso8601(3) })
|
|
|
|
expect(group_runner_a.token_expires_at).to eq(5.days.from_now)
|
2021-11-18 22:05:49 +05:30
|
|
|
end.to change { group_runner_a.reload.token }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'unauthorized user' do
|
2023-06-20 00:43:36 +05:30
|
|
|
it 'does not reset authentication token' do
|
2021-11-18 22:05:49 +05:30
|
|
|
expect do
|
2023-06-20 00:43:36 +05:30
|
|
|
post api(path)
|
2021-11-18 22:05:49 +05:30
|
|
|
|
|
|
|
expect(response).to have_gitlab_http_status(:unauthorized)
|
|
|
|
end.not_to change { shared_runner.reload.token }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
describe 'GET /runners/:id/jobs' do
|
2020-03-13 15:44:24 +05:30
|
|
|
let_it_be(:job_1) { create(:ci_build) }
|
2020-05-24 23:13:21 +05:30
|
|
|
let_it_be(:job_2) { create(:ci_build, :running, runner: shared_runner, project: project) }
|
|
|
|
let_it_be(:job_3) { create(:ci_build, :failed, runner: shared_runner, project: project) }
|
|
|
|
let_it_be(:job_4) { create(:ci_build, :running, runner: project_runner, project: project) }
|
|
|
|
let_it_be(:job_5) { create(:ci_build, :failed, runner: project_runner, project: project) }
|
2023-06-20 00:43:36 +05:30
|
|
|
let(:path) { "/runners/#{project_runner.id}/jobs" }
|
|
|
|
|
|
|
|
it_behaves_like 'GET request permissions for admin mode'
|
2018-03-17 18:26:18 +05:30
|
|
|
|
|
|
|
context 'admin user' do
|
|
|
|
context 'when runner exists' do
|
|
|
|
context 'when runner is shared' do
|
2023-06-20 00:43:36 +05:30
|
|
|
it 'return jobs' do
|
2023-05-27 22:25:52 +05:30
|
|
|
get api("/runners/#{shared_runner.id}/jobs", admin, admin_mode: true)
|
2018-03-17 18:26:18 +05:30
|
|
|
|
2020-04-08 14:13:33 +05:30
|
|
|
expect(response).to have_gitlab_http_status(:ok)
|
2018-03-17 18:26:18 +05:30
|
|
|
expect(response).to include_pagination_headers
|
|
|
|
|
|
|
|
expect(json_response).to be_an(Array)
|
|
|
|
expect(json_response.length).to eq(2)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2023-04-23 21:23:45 +05:30
|
|
|
context 'when runner is a project runner' do
|
2023-06-20 00:43:36 +05:30
|
|
|
it 'return jobs' do
|
|
|
|
get api(path, admin, admin_mode: true)
|
2018-03-17 18:26:18 +05:30
|
|
|
|
2020-04-08 14:13:33 +05:30
|
|
|
expect(response).to have_gitlab_http_status(:ok)
|
2018-03-17 18:26:18 +05:30
|
|
|
expect(response).to include_pagination_headers
|
|
|
|
|
|
|
|
expect(json_response).to be_an(Array)
|
|
|
|
expect(json_response.length).to eq(2)
|
|
|
|
end
|
2022-07-01 11:34:44 +05:30
|
|
|
|
|
|
|
context 'when user does not have authorization to see all jobs' do
|
2023-06-20 00:43:36 +05:30
|
|
|
it 'shows only jobs it has permission to see' do
|
2022-07-01 11:34:44 +05:30
|
|
|
create(:ci_build, :running, runner: two_projects_runner, project: project)
|
|
|
|
create(:ci_build, :running, runner: two_projects_runner, project: project2)
|
|
|
|
|
|
|
|
project.add_guest(user2)
|
|
|
|
project2.add_maintainer(user2)
|
|
|
|
get api("/runners/#{two_projects_runner.id}/jobs", user2)
|
|
|
|
|
|
|
|
expect(response).to have_gitlab_http_status(:ok)
|
|
|
|
expect(response).to include_pagination_headers
|
|
|
|
|
|
|
|
expect(json_response).to be_an(Array)
|
|
|
|
expect(json_response.length).to eq(1)
|
|
|
|
end
|
|
|
|
end
|
2018-03-17 18:26:18 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
context 'when valid status is provided' do
|
2023-06-20 00:43:36 +05:30
|
|
|
it 'return filtered jobs' do
|
2023-05-27 22:25:52 +05:30
|
|
|
get api("/runners/#{project_runner.id}/jobs?status=failed", admin, admin_mode: true)
|
2018-03-17 18:26:18 +05:30
|
|
|
|
2020-04-08 14:13:33 +05:30
|
|
|
expect(response).to have_gitlab_http_status(:ok)
|
2018-03-17 18:26:18 +05:30
|
|
|
expect(response).to include_pagination_headers
|
|
|
|
|
|
|
|
expect(json_response).to be_an(Array)
|
|
|
|
expect(json_response.length).to eq(1)
|
|
|
|
expect(json_response.first).to include('id' => job_5.id)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-09-30 21:07:59 +05:30
|
|
|
context 'when valid order_by is provided' do
|
|
|
|
context 'when sort order is not specified' do
|
2023-06-20 00:43:36 +05:30
|
|
|
it 'return jobs in descending order' do
|
2023-05-27 22:25:52 +05:30
|
|
|
get api("/runners/#{project_runner.id}/jobs?order_by=id", admin, admin_mode: true)
|
2019-09-30 21:07:59 +05:30
|
|
|
|
2020-04-08 14:13:33 +05:30
|
|
|
expect(response).to have_gitlab_http_status(:ok)
|
2019-09-30 21:07:59 +05:30
|
|
|
expect(response).to include_pagination_headers
|
|
|
|
|
|
|
|
expect(json_response).to be_an(Array)
|
|
|
|
expect(json_response.length).to eq(2)
|
|
|
|
expect(json_response.first).to include('id' => job_5.id)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when sort order is specified as asc' do
|
2023-06-20 00:43:36 +05:30
|
|
|
it 'return jobs sorted in ascending order' do
|
2023-05-27 22:25:52 +05:30
|
|
|
get api("/runners/#{project_runner.id}/jobs?order_by=id&sort=asc", admin, admin_mode: true)
|
2019-09-30 21:07:59 +05:30
|
|
|
|
2020-04-08 14:13:33 +05:30
|
|
|
expect(response).to have_gitlab_http_status(:ok)
|
2019-09-30 21:07:59 +05:30
|
|
|
expect(response).to include_pagination_headers
|
|
|
|
|
|
|
|
expect(json_response).to be_an(Array)
|
|
|
|
expect(json_response.length).to eq(2)
|
|
|
|
expect(json_response.first).to include('id' => job_4.id)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
context 'when invalid status is provided' do
|
|
|
|
it 'return 400' do
|
2023-05-27 22:25:52 +05:30
|
|
|
get api("/runners/#{project_runner.id}/jobs?status=non-existing", admin, admin_mode: true)
|
2018-03-17 18:26:18 +05:30
|
|
|
|
2020-04-08 14:13:33 +05:30
|
|
|
expect(response).to have_gitlab_http_status(:bad_request)
|
2018-03-17 18:26:18 +05:30
|
|
|
end
|
|
|
|
end
|
2019-09-30 21:07:59 +05:30
|
|
|
|
|
|
|
context 'when invalid order_by is provided' do
|
|
|
|
it 'return 400' do
|
2023-05-27 22:25:52 +05:30
|
|
|
get api("/runners/#{project_runner.id}/jobs?order_by=non-existing", admin, admin_mode: true)
|
2019-09-30 21:07:59 +05:30
|
|
|
|
2020-04-08 14:13:33 +05:30
|
|
|
expect(response).to have_gitlab_http_status(:bad_request)
|
2019-09-30 21:07:59 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when invalid sort is provided' do
|
|
|
|
it 'return 400' do
|
2023-05-27 22:25:52 +05:30
|
|
|
get api("/runners/#{project_runner.id}/jobs?sort=non-existing", admin, admin_mode: true)
|
2019-09-30 21:07:59 +05:30
|
|
|
|
2020-04-08 14:13:33 +05:30
|
|
|
expect(response).to have_gitlab_http_status(:bad_request)
|
2019-09-30 21:07:59 +05:30
|
|
|
end
|
|
|
|
end
|
2018-03-17 18:26:18 +05:30
|
|
|
end
|
|
|
|
|
2022-10-11 01:57:18 +05:30
|
|
|
it 'avoids N+1 DB queries' do
|
2023-05-27 22:25:52 +05:30
|
|
|
get api("/runners/#{shared_runner.id}/jobs", admin, admin_mode: true)
|
2022-10-11 01:57:18 +05:30
|
|
|
|
|
|
|
control = ActiveRecord::QueryRecorder.new do
|
2023-05-27 22:25:52 +05:30
|
|
|
get api("/runners/#{shared_runner.id}/jobs", admin, admin_mode: true)
|
2022-10-11 01:57:18 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
create(:ci_build, :failed, runner: shared_runner, project: project)
|
|
|
|
|
|
|
|
expect do
|
2023-05-27 22:25:52 +05:30
|
|
|
get api("/runners/#{shared_runner.id}/jobs", admin, admin_mode: true)
|
2022-10-11 01:57:18 +05:30
|
|
|
end.not_to exceed_query_limit(control.count)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'batches loading of commits' do
|
|
|
|
shared_runner = create(:ci_runner, :instance, description: 'Shared runner')
|
|
|
|
|
|
|
|
project_with_repo = create(:project, :repository)
|
|
|
|
|
|
|
|
pipeline = create(:ci_pipeline, project: project_with_repo, sha: 'ddd0f15ae83993f5cb66a927a28673882e99100b')
|
|
|
|
create(:ci_build, :running, runner: shared_runner, project: project_with_repo, pipeline: pipeline)
|
|
|
|
|
|
|
|
pipeline = create(:ci_pipeline, project: project_with_repo, sha: 'c1c67abbaf91f624347bb3ae96eabe3a1b742478')
|
|
|
|
create(:ci_build, :failed, runner: shared_runner, project: project_with_repo, pipeline: pipeline)
|
|
|
|
|
|
|
|
pipeline = create(:ci_pipeline, project: project_with_repo, sha: '1a0b36b3cdad1d2ee32457c102a8c0b7056fa863')
|
|
|
|
create(:ci_build, :failed, runner: shared_runner, project: project_with_repo, pipeline: pipeline)
|
|
|
|
|
|
|
|
expect_next_instance_of(Repository) do |repo|
|
2022-11-25 23:54:43 +05:30
|
|
|
expect(repo).to receive(:commits_by).with(oids:
|
|
|
|
%w[
|
|
|
|
1a0b36b3cdad1d2ee32457c102a8c0b7056fa863
|
|
|
|
c1c67abbaf91f624347bb3ae96eabe3a1b742478
|
|
|
|
]).once.and_call_original
|
2022-10-11 01:57:18 +05:30
|
|
|
end
|
|
|
|
|
2023-05-27 22:25:52 +05:30
|
|
|
get api("/runners/#{shared_runner.id}/jobs", admin, admin_mode: true), params: { per_page: 2, order_by: 'id', sort: 'desc' }
|
2022-10-11 01:57:18 +05:30
|
|
|
end
|
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
context "when runner doesn't exist" do
|
|
|
|
it 'returns 404' do
|
2023-05-27 22:25:52 +05:30
|
|
|
get api('/runners/0/jobs', admin, admin_mode: true)
|
2018-03-17 18:26:18 +05:30
|
|
|
|
2020-04-08 14:13:33 +05:30
|
|
|
expect(response).to have_gitlab_http_status(:not_found)
|
2018-03-17 18:26:18 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "runner project's administrative user" do
|
|
|
|
context 'when runner exists' do
|
|
|
|
context 'when runner is shared' do
|
|
|
|
it 'returns 403' do
|
|
|
|
get api("/runners/#{shared_runner.id}/jobs", user)
|
|
|
|
|
2020-04-08 14:13:33 +05:30
|
|
|
expect(response).to have_gitlab_http_status(:forbidden)
|
2018-03-17 18:26:18 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2023-04-23 21:23:45 +05:30
|
|
|
context 'when runner is a project runner' do
|
2023-06-20 00:43:36 +05:30
|
|
|
it 'return jobs' do
|
|
|
|
get api(path, user)
|
2018-03-17 18:26:18 +05:30
|
|
|
|
2020-04-08 14:13:33 +05:30
|
|
|
expect(response).to have_gitlab_http_status(:ok)
|
2018-03-17 18:26:18 +05:30
|
|
|
expect(response).to include_pagination_headers
|
|
|
|
|
|
|
|
expect(json_response).to be_an(Array)
|
|
|
|
expect(json_response.length).to eq(2)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when valid status is provided' do
|
2023-06-20 00:43:36 +05:30
|
|
|
it 'return filtered jobs' do
|
2018-10-15 14:42:47 +05:30
|
|
|
get api("/runners/#{project_runner.id}/jobs?status=failed", user)
|
2018-03-17 18:26:18 +05:30
|
|
|
|
2020-04-08 14:13:33 +05:30
|
|
|
expect(response).to have_gitlab_http_status(:ok)
|
2018-03-17 18:26:18 +05:30
|
|
|
expect(response).to include_pagination_headers
|
|
|
|
|
|
|
|
expect(json_response).to be_an(Array)
|
|
|
|
expect(json_response.length).to eq(1)
|
|
|
|
expect(json_response.first).to include('id' => job_5.id)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when invalid status is provided' do
|
|
|
|
it 'return 400' do
|
2018-10-15 14:42:47 +05:30
|
|
|
get api("/runners/#{project_runner.id}/jobs?status=non-existing", user)
|
2018-03-17 18:26:18 +05:30
|
|
|
|
2020-04-08 14:13:33 +05:30
|
|
|
expect(response).to have_gitlab_http_status(:bad_request)
|
2018-03-17 18:26:18 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "when runner doesn't exist" do
|
|
|
|
it 'returns 404' do
|
2019-07-07 11:18:12 +05:30
|
|
|
get api('/runners/0/jobs', user)
|
2018-03-17 18:26:18 +05:30
|
|
|
|
2020-04-08 14:13:33 +05:30
|
|
|
expect(response).to have_gitlab_http_status(:not_found)
|
2018-03-17 18:26:18 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'other authorized user' do
|
|
|
|
it 'does not return jobs' do
|
2023-06-20 00:43:36 +05:30
|
|
|
get api(path, user2)
|
2018-03-17 18:26:18 +05:30
|
|
|
|
2020-04-08 14:13:33 +05:30
|
|
|
expect(response).to have_gitlab_http_status(:forbidden)
|
2018-03-17 18:26:18 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'unauthorized user' do
|
|
|
|
it 'does not return jobs' do
|
2023-06-20 00:43:36 +05:30
|
|
|
get api(path)
|
2018-03-17 18:26:18 +05:30
|
|
|
|
2020-04-08 14:13:33 +05:30
|
|
|
expect(response).to have_gitlab_http_status(:unauthorized)
|
2016-04-02 18:10:28 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-04-22 19:07:51 +05:30
|
|
|
shared_examples_for 'unauthorized access to runners list' do
|
|
|
|
context 'authorized user without maintainer privileges' do
|
|
|
|
it "does not return group's runners" do
|
|
|
|
get api("/#{entity_type}/#{entity.id}/runners", user2)
|
|
|
|
|
|
|
|
expect(response).to have_gitlab_http_status(:forbidden)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'unauthorized user' do
|
|
|
|
it "does not return project's runners" do
|
|
|
|
get api("/#{entity_type}/#{entity.id}/runners")
|
|
|
|
|
|
|
|
expect(response).to have_gitlab_http_status(:unauthorized)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-04-02 18:10:28 +05:30
|
|
|
describe 'GET /projects/:id/runners' do
|
2018-11-18 11:00:15 +05:30
|
|
|
context 'authorized user with maintainer privileges' do
|
2023-06-20 00:43:36 +05:30
|
|
|
it 'returns response status and headers' do
|
2023-05-27 22:25:52 +05:30
|
|
|
get api('/runners/all', admin, admin_mode: true)
|
2018-12-05 23:21:45 +05:30
|
|
|
|
2020-04-08 14:13:33 +05:30
|
|
|
expect(response).to have_gitlab_http_status(:ok)
|
2018-12-05 23:21:45 +05:30
|
|
|
expect(response).to include_pagination_headers
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns all runners' do
|
2016-04-02 18:10:28 +05:30
|
|
|
get api("/projects/#{project.id}/runners", user)
|
|
|
|
|
2018-12-05 23:21:45 +05:30
|
|
|
expect(json_response).to match_array [
|
2022-04-04 11:22:00 +05:30
|
|
|
a_hash_including('description' => 'Project runner', 'active' => true, 'paused' => false),
|
|
|
|
a_hash_including('description' => 'Two projects runner', 'active' => true, 'paused' => false),
|
|
|
|
a_hash_including('description' => 'Shared runner', 'active' => true, 'paused' => false)
|
2018-12-05 23:21:45 +05:30
|
|
|
]
|
|
|
|
end
|
|
|
|
|
2023-06-20 00:43:36 +05:30
|
|
|
it 'filters runners by scope' do
|
2018-12-05 23:21:45 +05:30
|
|
|
get api("/projects/#{project.id}/runners?scope=specific", user)
|
|
|
|
|
2020-04-08 14:13:33 +05:30
|
|
|
expect(response).to have_gitlab_http_status(:ok)
|
2017-08-17 22:00:37 +05:30
|
|
|
expect(response).to include_pagination_headers
|
2018-12-05 23:21:45 +05:30
|
|
|
|
|
|
|
expect(json_response).to match_array [
|
|
|
|
a_hash_including('description' => 'Project runner'),
|
|
|
|
a_hash_including('description' => 'Two projects runner')
|
|
|
|
]
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'avoids filtering if scope is invalid' do
|
|
|
|
get api("/projects/#{project.id}/runners?scope=unknown", user)
|
2020-04-08 14:13:33 +05:30
|
|
|
expect(response).to have_gitlab_http_status(:bad_request)
|
2018-12-05 23:21:45 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
it 'filters runners by type' do
|
|
|
|
get api("/projects/#{project.id}/runners?type=project_type", user)
|
|
|
|
|
|
|
|
expect(json_response).to match_array [
|
|
|
|
a_hash_including('description' => 'Project runner'),
|
|
|
|
a_hash_including('description' => 'Two projects runner')
|
|
|
|
]
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not filter by invalid type' do
|
|
|
|
get api("/projects/#{project.id}/runners?type=bogus", user)
|
|
|
|
|
2020-04-08 14:13:33 +05:30
|
|
|
expect(response).to have_gitlab_http_status(:bad_request)
|
2018-12-05 23:21:45 +05:30
|
|
|
end
|
|
|
|
|
2022-04-04 11:22:00 +05:30
|
|
|
context 'with an inactive runner' do
|
|
|
|
let_it_be(:runner) { create(:ci_runner, :project, :inactive, description: 'Inactive project runner', projects: [project]) }
|
2018-12-05 23:21:45 +05:30
|
|
|
|
2022-04-04 11:22:00 +05:30
|
|
|
it 'filters runners by status' do
|
|
|
|
get api("/projects/#{project.id}/runners?paused=true", user)
|
2018-12-05 23:21:45 +05:30
|
|
|
|
2022-04-04 11:22:00 +05:30
|
|
|
expect(json_response).to match_array [
|
|
|
|
a_hash_including('description' => 'Inactive project runner')
|
|
|
|
]
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'filters runners by status' do
|
|
|
|
get api("/projects/#{project.id}/runners?status=paused", user)
|
|
|
|
|
|
|
|
expect(json_response).to match_array [
|
|
|
|
a_hash_including('description' => 'Inactive project runner')
|
|
|
|
]
|
|
|
|
end
|
2018-12-05 23:21:45 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not filter by invalid status' do
|
|
|
|
get api("/projects/#{project.id}/runners?status=bogus", user)
|
|
|
|
|
2020-04-08 14:13:33 +05:30
|
|
|
expect(response).to have_gitlab_http_status(:bad_request)
|
2016-04-02 18:10:28 +05:30
|
|
|
end
|
2019-07-07 11:18:12 +05:30
|
|
|
|
2023-06-20 00:43:36 +05:30
|
|
|
it 'filters runners by tag_list' do
|
2019-07-07 11:18:12 +05:30
|
|
|
create(:ci_runner, :project, description: 'Runner tagged with tag1 and tag2', projects: [project], tag_list: %w[tag1 tag2])
|
|
|
|
create(:ci_runner, :project, description: 'Runner tagged with tag2', projects: [project], tag_list: ['tag2'])
|
|
|
|
|
|
|
|
get api("/projects/#{project.id}/runners?tag_list=tag1,tag2", user)
|
|
|
|
|
|
|
|
expect(json_response).to match_array [
|
|
|
|
a_hash_including('description' => 'Runner tagged with tag1 and tag2')
|
|
|
|
]
|
|
|
|
end
|
2016-04-02 18:10:28 +05:30
|
|
|
end
|
|
|
|
|
2020-04-22 19:07:51 +05:30
|
|
|
it_behaves_like 'unauthorized access to runners list' do
|
|
|
|
let(:entity_type) { 'projects' }
|
|
|
|
let(:entity) { project }
|
|
|
|
end
|
|
|
|
end
|
2016-04-02 18:10:28 +05:30
|
|
|
|
2022-04-04 11:22:00 +05:30
|
|
|
describe 'GET /groups/:id/runners' do
|
2020-04-22 19:07:51 +05:30
|
|
|
context 'authorized user with maintainer privileges' do
|
|
|
|
it 'returns all runners' do
|
|
|
|
get api("/groups/#{group.id}/runners", user)
|
|
|
|
|
2022-11-25 23:54:43 +05:30
|
|
|
expect(json_response).to match_array(
|
|
|
|
[
|
|
|
|
a_hash_including('description' => 'Group runner A', 'active' => true, 'paused' => false),
|
|
|
|
a_hash_including('description' => 'Shared runner', 'active' => true, 'paused' => false)
|
|
|
|
])
|
2016-04-02 18:10:28 +05:30
|
|
|
end
|
|
|
|
|
2020-04-22 19:07:51 +05:30
|
|
|
context 'filter by type' do
|
|
|
|
it 'returns record when valid and present' do
|
|
|
|
get api("/groups/#{group.id}/runners?type=group_type", user)
|
2016-04-02 18:10:28 +05:30
|
|
|
|
2022-11-25 23:54:43 +05:30
|
|
|
expect(json_response).to match_array([a_hash_including('description' => 'Group runner A')])
|
2020-04-22 19:07:51 +05:30
|
|
|
end
|
|
|
|
|
2022-04-04 11:22:00 +05:30
|
|
|
it 'returns instance runners when instance_type is specified' do
|
|
|
|
get api("/groups/#{group.id}/runners?type=instance_type", user)
|
|
|
|
|
2022-11-25 23:54:43 +05:30
|
|
|
expect(json_response).to match_array([a_hash_including('description' => 'Shared runner')])
|
2022-04-04 11:22:00 +05:30
|
|
|
end
|
|
|
|
|
2022-11-25 23:54:43 +05:30
|
|
|
# TODO: Remove when REST API v5 is implemented (https://gitlab.com/gitlab-org/gitlab/-/issues/351466)
|
2020-04-22 19:07:51 +05:30
|
|
|
it 'returns empty result when type does not match' do
|
|
|
|
get api("/groups/#{group.id}/runners?type=project_type", user)
|
|
|
|
|
|
|
|
expect(json_response).to be_empty
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not filter by invalid type' do
|
|
|
|
get api("/groups/#{group.id}/runners?type=bogus", user)
|
|
|
|
|
|
|
|
expect(response).to have_gitlab_http_status(:bad_request)
|
|
|
|
end
|
2016-04-02 18:10:28 +05:30
|
|
|
end
|
2020-04-22 19:07:51 +05:30
|
|
|
|
2022-04-04 11:22:00 +05:30
|
|
|
context 'with an inactive runner' do
|
|
|
|
let_it_be(:runner) { create(:ci_runner, :group, :inactive, description: 'Inactive group runner', groups: [group]) }
|
2020-04-22 19:07:51 +05:30
|
|
|
|
2022-04-04 11:22:00 +05:30
|
|
|
it 'returns runners by paused state' do
|
|
|
|
get api("/groups/#{group.id}/runners?paused=true", user)
|
2020-04-22 19:07:51 +05:30
|
|
|
|
2022-11-25 23:54:43 +05:30
|
|
|
expect(json_response).to match_array([a_hash_including('description' => 'Inactive group runner')])
|
2020-04-22 19:07:51 +05:30
|
|
|
end
|
|
|
|
|
2022-04-04 11:22:00 +05:30
|
|
|
context 'filter runners by status' do
|
|
|
|
it 'returns runners by valid status' do
|
|
|
|
get api("/groups/#{group.id}/runners?status=paused", user)
|
2020-04-22 19:07:51 +05:30
|
|
|
|
2022-11-25 23:54:43 +05:30
|
|
|
expect(json_response).to match_array([a_hash_including('description' => 'Inactive group runner')])
|
2022-04-04 11:22:00 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not filter by invalid status' do
|
|
|
|
get api("/groups/#{group.id}/runners?status=bogus", user)
|
|
|
|
|
|
|
|
expect(response).to have_gitlab_http_status(:bad_request)
|
|
|
|
end
|
2020-04-22 19:07:51 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2023-06-20 00:43:36 +05:30
|
|
|
it 'filters runners by tag_list' do
|
2020-04-22 19:07:51 +05:30
|
|
|
create(:ci_runner, :group, description: 'Runner tagged with tag1 and tag2', groups: [group], tag_list: %w[tag1 tag2])
|
|
|
|
create(:ci_runner, :group, description: 'Runner tagged with tag2', groups: [group], tag_list: %w[tag1])
|
|
|
|
|
|
|
|
get api("/groups/#{group.id}/runners?tag_list=tag1,tag2", user)
|
|
|
|
|
2022-11-25 23:54:43 +05:30
|
|
|
expect(json_response).to match_array([a_hash_including('description' => 'Runner tagged with tag1 and tag2')])
|
2020-04-22 19:07:51 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
it_behaves_like 'unauthorized access to runners list' do
|
|
|
|
let(:entity_type) { 'groups' }
|
|
|
|
let(:entity) { group }
|
2016-04-02 18:10:28 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'POST /projects/:id/runners' do
|
2023-06-20 00:43:36 +05:30
|
|
|
let(:path) { "/projects/#{project.id}/runners" }
|
|
|
|
|
|
|
|
it_behaves_like 'POST request permissions for admin mode' do
|
|
|
|
let!(:new_project_runner) { create(:ci_runner, :project) }
|
|
|
|
let(:params) { { runner_id: new_project_runner.id } }
|
|
|
|
let(:failed_status_code) { :not_found }
|
|
|
|
end
|
|
|
|
|
2016-04-02 18:10:28 +05:30
|
|
|
context 'authorized user' do
|
2020-05-24 23:13:21 +05:30
|
|
|
let_it_be(:project_runner2) { create(:ci_runner, :project, projects: [project2]) }
|
2016-04-02 18:10:28 +05:30
|
|
|
|
2023-06-20 00:43:36 +05:30
|
|
|
it 'enables project runner' do
|
2016-04-02 18:10:28 +05:30
|
|
|
expect do
|
2023-06-20 00:43:36 +05:30
|
|
|
post api(path, user), params: { runner_id: project_runner2.id }
|
2018-03-17 18:26:18 +05:30
|
|
|
end.to change { project.runners.count }.by(+1)
|
2020-04-08 14:13:33 +05:30
|
|
|
expect(response).to have_gitlab_http_status(:created)
|
2016-04-02 18:10:28 +05:30
|
|
|
end
|
|
|
|
|
2023-06-20 00:43:36 +05:30
|
|
|
it 'avoids changes when enabling already enabled runner' do
|
2016-04-02 18:10:28 +05:30
|
|
|
expect do
|
2023-06-20 00:43:36 +05:30
|
|
|
post api(path, user), params: { runner_id: project_runner.id }
|
2018-03-17 18:26:18 +05:30
|
|
|
end.to change { project.runners.count }.by(0)
|
2020-04-08 14:13:33 +05:30
|
|
|
expect(response).to have_gitlab_http_status(:bad_request)
|
2016-06-22 15:30:34 +05:30
|
|
|
end
|
|
|
|
|
2023-06-20 00:43:36 +05:30
|
|
|
it 'does not enable locked runner' do
|
2020-07-28 23:09:34 +05:30
|
|
|
project_runner2.update!(locked: true)
|
2016-06-22 15:30:34 +05:30
|
|
|
|
|
|
|
expect do
|
2023-06-20 00:43:36 +05:30
|
|
|
post api(path, user), params: { runner_id: project_runner2.id }
|
2018-03-17 18:26:18 +05:30
|
|
|
end.to change { project.runners.count }.by(0)
|
2016-06-22 15:30:34 +05:30
|
|
|
|
2020-04-08 14:13:33 +05:30
|
|
|
expect(response).to have_gitlab_http_status(:forbidden)
|
2016-04-02 18:10:28 +05:30
|
|
|
end
|
|
|
|
|
2016-09-13 17:45:13 +05:30
|
|
|
it 'does not enable shared runner' do
|
2023-06-20 00:43:36 +05:30
|
|
|
post api(path, user), params: { runner_id: shared_runner.id }
|
2016-04-02 18:10:28 +05:30
|
|
|
|
2020-04-08 14:13:33 +05:30
|
|
|
expect(response).to have_gitlab_http_status(:forbidden)
|
2016-04-02 18:10:28 +05:30
|
|
|
end
|
|
|
|
|
2018-10-15 14:42:47 +05:30
|
|
|
it 'does not enable group runner' do
|
2023-06-20 00:43:36 +05:30
|
|
|
post api(path, user), params: { runner_id: group_runner_a.id }
|
2018-10-15 14:42:47 +05:30
|
|
|
|
2020-04-08 14:13:33 +05:30
|
|
|
expect(response).to have_gitlab_http_status(:forbidden)
|
2018-10-15 14:42:47 +05:30
|
|
|
end
|
|
|
|
|
2016-04-02 18:10:28 +05:30
|
|
|
context 'user is admin' do
|
2018-11-08 19:23:39 +05:30
|
|
|
context 'when project runner is used' do
|
|
|
|
let!(:new_project_runner) { create(:ci_runner, :project) }
|
|
|
|
|
2023-06-20 00:43:36 +05:30
|
|
|
it 'enables any project runner' do
|
2018-11-08 19:23:39 +05:30
|
|
|
expect do
|
2023-06-20 00:43:36 +05:30
|
|
|
post api(path, admin, admin_mode: true), params: { runner_id: new_project_runner.id }
|
2018-11-08 19:23:39 +05:30
|
|
|
end.to change { project.runners.count }.by(+1)
|
2020-04-08 14:13:33 +05:30
|
|
|
expect(response).to have_gitlab_http_status(:created)
|
2018-11-08 19:23:39 +05:30
|
|
|
end
|
2021-06-08 01:23:25 +05:30
|
|
|
|
|
|
|
context 'when it exceeds the application limits' do
|
|
|
|
before do
|
|
|
|
create(:plan_limits, :default_plan, ci_registered_project_runners: 1)
|
|
|
|
end
|
|
|
|
|
2023-06-20 00:43:36 +05:30
|
|
|
it 'does not enable project runner' do
|
2022-01-26 12:08:38 +05:30
|
|
|
expect do
|
2023-06-20 00:43:36 +05:30
|
|
|
post api(path, admin, admin_mode: true), params: { runner_id: new_project_runner.id }
|
2022-01-26 12:08:38 +05:30
|
|
|
end.not_to change { project.runners.count }
|
|
|
|
expect(response).to have_gitlab_http_status(:bad_request)
|
2021-06-08 01:23:25 +05:30
|
|
|
end
|
|
|
|
end
|
2016-04-02 18:10:28 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-09-13 17:45:13 +05:30
|
|
|
it 'raises an error when no runner_id param is provided' do
|
2023-06-20 00:43:36 +05:30
|
|
|
post api(path, admin, admin_mode: true)
|
2016-04-02 18:10:28 +05:30
|
|
|
|
2020-04-08 14:13:33 +05:30
|
|
|
expect(response).to have_gitlab_http_status(:bad_request)
|
2016-04-02 18:10:28 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-11-08 19:23:39 +05:30
|
|
|
context 'user is not admin' do
|
|
|
|
let!(:new_project_runner) { create(:ci_runner, :project) }
|
|
|
|
|
|
|
|
it 'does not enable runner without access to' do
|
2023-06-20 00:43:36 +05:30
|
|
|
post api(path, user), params: { runner_id: new_project_runner.id }
|
2018-11-08 19:23:39 +05:30
|
|
|
|
2020-04-08 14:13:33 +05:30
|
|
|
expect(response).to have_gitlab_http_status(:forbidden)
|
2018-11-08 19:23:39 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-04-02 18:10:28 +05:30
|
|
|
context 'authorized user without permissions' do
|
2016-09-13 17:45:13 +05:30
|
|
|
it 'does not enable runner' do
|
2023-06-20 00:43:36 +05:30
|
|
|
post api(path, user2)
|
2016-04-02 18:10:28 +05:30
|
|
|
|
2020-04-08 14:13:33 +05:30
|
|
|
expect(response).to have_gitlab_http_status(:forbidden)
|
2016-04-02 18:10:28 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'unauthorized user' do
|
2016-09-13 17:45:13 +05:30
|
|
|
it 'does not enable runner' do
|
2023-06-20 00:43:36 +05:30
|
|
|
post api(path)
|
2016-04-02 18:10:28 +05:30
|
|
|
|
2020-04-08 14:13:33 +05:30
|
|
|
expect(response).to have_gitlab_http_status(:unauthorized)
|
2016-04-02 18:10:28 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'DELETE /projects/:id/runners/:runner_id' do
|
|
|
|
context 'authorized user' do
|
|
|
|
context 'when runner have more than one associated projects' do
|
2016-09-13 17:45:13 +05:30
|
|
|
it "disables project's runner" do
|
2016-04-02 18:10:28 +05:30
|
|
|
expect do
|
|
|
|
delete api("/projects/#{project.id}/runners/#{two_projects_runner.id}", user)
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2020-04-08 14:13:33 +05:30
|
|
|
expect(response).to have_gitlab_http_status(:no_content)
|
2018-03-17 18:26:18 +05:30
|
|
|
end.to change { project.runners.count }.by(-1)
|
|
|
|
end
|
|
|
|
|
|
|
|
it_behaves_like '412 response' do
|
|
|
|
let(:request) { api("/projects/#{project.id}/runners/#{two_projects_runner.id}", user) }
|
2016-04-02 18:10:28 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when runner have one associated projects' do
|
2023-06-20 00:43:36 +05:30
|
|
|
it "does not disable project's runner" do
|
2016-04-02 18:10:28 +05:30
|
|
|
expect do
|
2018-10-15 14:42:47 +05:30
|
|
|
delete api("/projects/#{project.id}/runners/#{project_runner.id}", user)
|
2018-03-17 18:26:18 +05:30
|
|
|
end.to change { project.runners.count }.by(0)
|
2020-04-08 14:13:33 +05:30
|
|
|
expect(response).to have_gitlab_http_status(:forbidden)
|
2016-04-02 18:10:28 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-09-13 17:45:13 +05:30
|
|
|
it 'returns 404 is runner is not found' do
|
2019-07-07 11:18:12 +05:30
|
|
|
delete api("/projects/#{project.id}/runners/0", user)
|
2016-04-02 18:10:28 +05:30
|
|
|
|
2020-04-08 14:13:33 +05:30
|
|
|
expect(response).to have_gitlab_http_status(:not_found)
|
2016-04-02 18:10:28 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'authorized user without permissions' do
|
2016-09-13 17:45:13 +05:30
|
|
|
it "does not disable project's runner" do
|
2018-10-15 14:42:47 +05:30
|
|
|
delete api("/projects/#{project.id}/runners/#{project_runner.id}", user2)
|
2016-04-02 18:10:28 +05:30
|
|
|
|
2020-04-08 14:13:33 +05:30
|
|
|
expect(response).to have_gitlab_http_status(:forbidden)
|
2016-04-02 18:10:28 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'unauthorized user' do
|
2016-09-13 17:45:13 +05:30
|
|
|
it "does not disable project's runner" do
|
2018-10-15 14:42:47 +05:30
|
|
|
delete api("/projects/#{project.id}/runners/#{project_runner.id}")
|
2016-04-02 18:10:28 +05:30
|
|
|
|
2020-04-08 14:13:33 +05:30
|
|
|
expect(response).to have_gitlab_http_status(:unauthorized)
|
2016-04-02 18:10:28 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|