Commit b99e2695 authored by Dmytro Zaporozhets (DZ)'s avatar Dmytro Zaporozhets (DZ)

Merge branch '290288-add-sha-to-composer' into 'master'

Adds sha checksum to composer URL

See merge request gitlab-org/gitlab!49511
parents 96cad01e 39510f8a
...@@ -11,7 +11,7 @@ module Packages ...@@ -11,7 +11,7 @@ module Packages
end end
def root def root
path = api_v4_group___packages_composer_package_name_path({ id: @group.id, package_name: '%package%', format: '.json' }, true) path = api_v4_group___packages_composer_package_name_path({ id: @group.id, package_name: '%package%$%hash%', format: '.json' }, true)
{ 'packages' => [], 'provider-includes' => { 'p/%hash%.json' => { 'sha256' => provider_sha } }, 'providers-url' => path } { 'packages' => [], 'provider-includes' => { 'p/%hash%.json' => { 'sha256' => provider_sha } }, 'providers-url' => path }
end end
......
---
title: Adds sha checksum to composer URL
merge_request: 49511
author:
type: added
...@@ -38,6 +38,8 @@ module API ...@@ -38,6 +38,8 @@ module API
packages = ::Packages::Composer::PackagesFinder.new(current_user, user_group).execute packages = ::Packages::Composer::PackagesFinder.new(current_user, user_group).execute
if params[:package_name].present? if params[:package_name].present?
params[:package_name], params[:sha] = params[:package_name].split('$')
packages = packages.with_name(params[:package_name]) packages = packages.with_name(params[:package_name])
end end
...@@ -93,6 +95,7 @@ module API ...@@ -93,6 +95,7 @@ module API
get ':id/-/packages/composer/*package_name', requirements: COMPOSER_ENDPOINT_REQUIREMENTS, file_path: true do get ':id/-/packages/composer/*package_name', requirements: COMPOSER_ENDPOINT_REQUIREMENTS, file_path: true do
not_found! if packages.empty? not_found! if packages.empty?
not_found! if params[:sha].blank?
presenter.package_versions presenter.package_versions
end end
......
...@@ -67,7 +67,7 @@ RSpec.describe ::Packages::Composer::PackagesPresenter do ...@@ -67,7 +67,7 @@ RSpec.describe ::Packages::Composer::PackagesPresenter do
{ {
'packages' => [], 'packages' => [],
'provider-includes' => { 'p/%hash%.json' => { 'sha256' => /^\h+$/ } }, 'provider-includes' => { 'p/%hash%.json' => { 'sha256' => /^\h+$/ } },
'providers-url' => "/api/v4/group/#{group.id}/-/packages/composer/%package%.json" 'providers-url' => "/api/v4/group/#{group.id}/-/packages/composer/%package%$%hash%.json"
} }
end end
......
...@@ -167,7 +167,8 @@ RSpec.describe API::ComposerPackages do ...@@ -167,7 +167,8 @@ RSpec.describe API::ComposerPackages do
describe 'GET /api/v4/group/:id/-/packages/composer/*package_name.json' do describe 'GET /api/v4/group/:id/-/packages/composer/*package_name.json' do
let(:package_name) { 'foobar' } let(:package_name) { 'foobar' }
let(:url) { "/group/#{group.id}/-/packages/composer/#{package_name}.json" } let(:sha) { '$1234' }
let(:url) { "/group/#{group.id}/-/packages/composer/#{package_name}#{sha}.json" }
subject { get api(url), headers: headers } subject { get api(url), headers: headers }
...@@ -206,6 +207,16 @@ RSpec.describe API::ComposerPackages do ...@@ -206,6 +207,16 @@ RSpec.describe API::ComposerPackages do
it_behaves_like params[:shared_examples_name], params[:user_role], params[:expected_status], params[:member] it_behaves_like params[:shared_examples_name], params[:user_role], params[:expected_status], params[:member]
end end
end end
context 'without a sha' do
let(:sha) { '' }
include_context 'Composer api group access', 'PRIVATE', :developer, true do
include_context 'Composer user type', :developer, true do
it_behaves_like 'process Composer api request', :developer, :not_found, true
end
end
end
end end
it_behaves_like 'rejects Composer access with unknown group id' it_behaves_like 'rejects Composer access with unknown group id'
......
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