Commit 74666988 authored by David Fernandez's avatar David Fernandez Committed by Igor Drozdov

Update the group permission check in packages finder helper

parent 70c9c973
...@@ -11,7 +11,7 @@ module Packages ...@@ -11,7 +11,7 @@ module Packages
def packages_visible_to_user(user, within_group:) def packages_visible_to_user(user, within_group:)
return ::Packages::Package.none unless within_group return ::Packages::Package.none unless within_group
return ::Packages::Package.none unless Ability.allowed?(user, :read_package, within_group) return ::Packages::Package.none unless Ability.allowed?(user, :read_group, within_group)
projects = projects_visible_to_reporters(user, within_group.self_and_descendants.select(:id)) projects = projects_visible_to_reporters(user, within_group.self_and_descendants.select(:id))
::Packages::Package.for_projects(projects.select(:id)) ::Packages::Package.for_projects(projects.select(:id))
...@@ -19,7 +19,7 @@ module Packages ...@@ -19,7 +19,7 @@ module Packages
def projects_visible_to_user(user, within_group:) def projects_visible_to_user(user, within_group:)
return ::Project.none unless within_group return ::Project.none unless within_group
return ::Project.none unless Ability.allowed?(user, :read_package, within_group) return ::Project.none unless Ability.allowed?(user, :read_group, within_group)
projects_visible_to_reporters(user, within_group.self_and_descendants.select(:id)) projects_visible_to_reporters(user, within_group.self_and_descendants.select(:id))
end end
......
---
title: Update the group permission check in packages finder helper
merge_request: 58329
author:
type: fixed
...@@ -420,6 +420,25 @@ RSpec.describe API::MavenPackages do ...@@ -420,6 +420,25 @@ RSpec.describe API::MavenPackages do
expect(response.media_type).to eq('application/octet-stream') expect(response.media_type).to eq('application/octet-stream')
end end
end end
context 'with a reporter from a subgroup accessing the root group' do
let_it_be(:root_group) { create(:group, :private) }
let_it_be(:group) { create(:group, :private, parent: root_group) }
subject { download_file_with_token(package_file.file_name, {}, headers_with_token, root_group.id) }
before do
project.update!(namespace: group)
group.add_reporter(user)
end
it 'returns the file' do
subject
expect(response).to have_gitlab_http_status(:ok)
expect(response.media_type).to eq('application/octet-stream')
end
end
end end
context 'maven metadata file' do context 'maven metadata file' do
...@@ -492,12 +511,12 @@ RSpec.describe API::MavenPackages do ...@@ -492,12 +511,12 @@ RSpec.describe API::MavenPackages do
it_behaves_like 'handling all conditions' it_behaves_like 'handling all conditions'
end end
def download_file(file_name, params = {}, request_headers = headers) def download_file(file_name, params = {}, request_headers = headers, group_id = group.id)
get api("/groups/#{group.id}/-/packages/maven/#{maven_metadatum.path}/#{file_name}"), params: params, headers: request_headers get api("/groups/#{group_id}/-/packages/maven/#{maven_metadatum.path}/#{file_name}"), params: params, headers: request_headers
end end
def download_file_with_token(file_name, params = {}, request_headers = headers_with_token) def download_file_with_token(file_name, params = {}, request_headers = headers_with_token, group_id = group.id)
download_file(file_name, params, request_headers) download_file(file_name, params, request_headers, group_id)
end end
end end
......
...@@ -113,6 +113,45 @@ RSpec.describe API::NugetGroupPackages do ...@@ -113,6 +113,45 @@ RSpec.describe API::NugetGroupPackages do
end end
end end
context 'with a reporter of subgroup' do
let_it_be(:package_name) { 'Dummy.Package' }
let_it_be(:package) { create(:nuget_package, :with_metadatum, name: package_name, project: project) }
let(:headers) { basic_auth_header(user.username, personal_access_token.token) }
subject { get api(url), headers: headers }
before do
subgroup.add_reporter(user)
project.update_column(:visibility_level, Gitlab::VisibilityLevel.level_value('private'))
subgroup.update_column(:visibility_level, Gitlab::VisibilityLevel.level_value('private'))
group.update_column(:visibility_level, Gitlab::VisibilityLevel.level_value('private'))
end
describe 'GET /api/v4/groups/:id/-/packages/nuget/metadata/*package_name/index' do
let(:url) { "/groups/#{group.id}/-/packages/nuget/metadata/#{package_name}/index.json" }
it_behaves_like 'returning response status', :forbidden
end
describe 'GET /api/v4/groups/:id/-/packages/nuget/metadata/*package_name/*package_version' do
let(:url) { "/groups/#{group.id}/-/packages/nuget/metadata/#{package_name}/#{package.version}.json" }
it_behaves_like 'returning response status', :forbidden
end
describe 'GET /api/v4/groups/:id/-/packages/nuget/query' do
let(:search_term) { 'uMmy' }
let(:take) { 26 }
let(:skip) { 0 }
let(:include_prereleases) { false }
let(:query_parameters) { { q: search_term, take: take, skip: skip, prerelease: include_prereleases } }
let(:url) { "/groups/#{group.id}/-/packages/nuget/query?#{query_parameters.to_query}" }
it_behaves_like 'returning response status', :forbidden
end
end
def update_visibility_to(visibility) def update_visibility_to(visibility)
project.update!(visibility_level: visibility) project.update!(visibility_level: visibility)
subgroup.update!(visibility_level: visibility) subgroup.update!(visibility_level: visibility)
......
...@@ -156,7 +156,7 @@ RSpec.shared_examples 'handling nuget metadata requests with package name and pa ...@@ -156,7 +156,7 @@ RSpec.shared_examples 'handling nuget metadata requests with package name and pa
include_context 'with expected presenters dependency groups' include_context 'with expected presenters dependency groups'
let_it_be(:package_name) { 'Dummy.Package' } let_it_be(:package_name) { 'Dummy.Package' }
let_it_be(:package) { create(:nuget_package, :with_metadatum, name: 'Dummy.Package', project: project) } let_it_be(:package) { create(:nuget_package, :with_metadatum, name: package_name, project: project) }
let_it_be(:tag) { create(:packages_tag, package: package, name: 'test') } let_it_be(:tag) { create(:packages_tag, package: package, name: 'test') }
subject { get api(url) } subject { get api(url) }
......
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