Commit a8f2a3d2 authored by GitLab Release Tools Bot's avatar GitLab Release Tools Bot

Merge branch 'security-357963-prevent-editing-group-labels-14-10' into '14-10-stable-ee'

Fix permissions in the project labels API

See merge request gitlab-org/security/gitlab!2534
parents aee1cf9a f2c71f64
...@@ -82,8 +82,14 @@ module API ...@@ -82,8 +82,14 @@ module API
params.delete(:label_id) params.delete(:label_id)
params.delete(:name) params.delete(:name)
label = ::Labels::UpdateService.new(declared_params(include_missing: false)).execute(label) update_params = declared_params(include_missing: false)
if update_params.present?
authorize! :admin_label, label
label = ::Labels::UpdateService.new(update_params).execute(label)
render_validation_error!(label) unless label.valid? render_validation_error!(label) unless label.valid?
end
if parent.is_a?(Project) && update_priority if parent.is_a?(Project) && update_priority
if priority.nil? if priority.nil?
...@@ -97,10 +103,10 @@ module API ...@@ -97,10 +103,10 @@ module API
end end
def delete_label(parent) def delete_label(parent)
authorize! :admin_label, parent
label = find_label(parent, params_id_or_title, include_ancestor_groups: false) label = find_label(parent, params_id_or_title, include_ancestor_groups: false)
authorize! :admin_label, label
destroy_conditionally!(label) destroy_conditionally!(label)
end end
......
...@@ -483,6 +483,29 @@ RSpec.describe API::Labels do ...@@ -483,6 +483,29 @@ RSpec.describe API::Labels do
let(:request) { api("/projects/#{project.id}/labels", user) } let(:request) { api("/projects/#{project.id}/labels", user) }
let(:params) { { name: valid_label_title_1 } } let(:params) { { name: valid_label_title_1 } }
end end
context 'with group label' do
let_it_be(:group) { create(:group) }
let_it_be(:group_label) { create(:group_label, title: valid_group_label_title_1, group: group) }
before do
project.update!(group: group)
end
it 'returns 401 if user does not have access' do
delete api("/projects/#{project.id}/labels/#{group_label.id}", user)
expect(response).to have_gitlab_http_status(:forbidden)
end
it 'returns 204 if user has access' do
group.add_developer(user)
delete api("/projects/#{project.id}/labels/#{group_label.id}", user)
expect(response).to have_gitlab_http_status(:no_content)
end
end
end end
describe 'PUT /projects/:id/labels' do describe 'PUT /projects/:id/labels' do
...@@ -537,6 +560,44 @@ RSpec.describe API::Labels do ...@@ -537,6 +560,44 @@ RSpec.describe API::Labels do
expect(response).to have_gitlab_http_status(:bad_request) expect(response).to have_gitlab_http_status(:bad_request)
end end
context 'with group label' do
let_it_be(:group) { create(:group) }
let_it_be(:group_label) { create(:group_label, title: valid_group_label_title_1, group: group) }
before do
project.update!(group: group)
end
it 'allows updating of group label priority' do
put api("/projects/#{project.id}/labels/#{group_label.id}", user), params: { priority: 5 }
expect(response).to have_gitlab_http_status(:ok)
expect(json_response['priority']).to eq(5)
end
it 'returns 401 when updating other fields' do
put api("/projects/#{project.id}/labels/#{group_label.id}", user), params: {
priority: 5,
new_name: 'new label name'
}
expect(response).to have_gitlab_http_status(:forbidden)
end
it 'returns 200 when user has access to the group label' do
group.add_developer(user)
put api("/projects/#{project.id}/labels/#{group_label.id}", user), params: {
priority: 5,
new_name: 'new label name'
}
expect(response).to have_gitlab_http_status(:ok)
expect(json_response['priority']).to eq(5)
expect(json_response['name']).to eq('new label name')
end
end
end end
describe 'PUT /projects/:id/labels/promote' do describe 'PUT /projects/:id/labels/promote' do
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment