debian-mirror-gitlab/spec/requests/api/debian_project_packages_spec.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

243 lines
12 KiB
Ruby
Raw Normal View History

2021-01-03 14:25:43 +05:30
# frozen_string_literal: true
require 'spec_helper'
2023-03-04 22:38:38 +05:30
RSpec.describe API::DebianProjectPackages, feature_category: :package_registry do
2021-01-03 14:25:43 +05:30
include HttpBasicAuthHelpers
include WorkhorseHelpers
2023-03-17 16:20:25 +05:30
include_context 'Debian repository shared context', :project, false do
2023-06-20 00:43:36 +05:30
shared_examples 'a Debian package tracking event' do |action|
include_context 'Debian repository access', :public, :developer, :basic do
let(:snowplow_gitlab_standard_context) do
{ project: container, namespace: container.namespace, user: user, property: 'i_package_debian_user' }
end
it_behaves_like 'a package tracking event', described_class.name, action
end
end
shared_examples 'not a Debian package tracking event' do
include_context 'Debian repository access', :public, :developer, :basic do
it_behaves_like 'not a package tracking event', described_class.name, /.*/
end
end
2023-03-17 16:20:25 +05:30
shared_examples 'accept GET request on private project with access to package registry for everyone' do
include_context 'Debian repository access', :private, :anonymous, :basic do
before do
container.project_feature.reload.update!(package_registry_access_level: ProjectFeature::PUBLIC)
end
it_behaves_like 'Debian packages GET request', :success
end
end
2021-10-27 15:23:28 +05:30
context 'with invalid parameter' do
let(:url) { "/projects/1/packages/debian/dists/with+space/InRelease" }
2021-12-11 22:18:48 +05:30
it_behaves_like 'Debian packages GET request', :bad_request, /^distribution is invalid$/
2023-06-20 00:43:36 +05:30
it_behaves_like 'not a Debian package tracking event'
2021-10-27 15:23:28 +05:30
end
2021-03-11 19:13:27 +05:30
describe 'GET projects/:id/packages/debian/dists/*distribution/Release.gpg' do
2021-09-04 01:27:46 +05:30
let(:url) { "/projects/#{container.id}/packages/debian/dists/#{distribution.codename}/Release.gpg" }
2021-01-03 14:25:43 +05:30
2021-12-11 22:18:48 +05:30
it_behaves_like 'Debian packages read endpoint', 'GET', :success, /^-----BEGIN PGP SIGNATURE-----/
2023-06-20 00:43:36 +05:30
it_behaves_like 'not a Debian package tracking event'
2023-03-17 16:20:25 +05:30
it_behaves_like 'accept GET request on private project with access to package registry for everyone'
2021-01-03 14:25:43 +05:30
end
2021-03-11 19:13:27 +05:30
describe 'GET projects/:id/packages/debian/dists/*distribution/Release' do
2021-09-04 01:27:46 +05:30
let(:url) { "/projects/#{container.id}/packages/debian/dists/#{distribution.codename}/Release" }
2021-01-03 14:25:43 +05:30
2021-12-11 22:18:48 +05:30
it_behaves_like 'Debian packages read endpoint', 'GET', :success, /^Codename: fixture-distribution\n$/
2023-06-20 00:43:36 +05:30
it_behaves_like 'a Debian package tracking event', 'list_package'
2023-03-17 16:20:25 +05:30
it_behaves_like 'accept GET request on private project with access to package registry for everyone'
2021-01-03 14:25:43 +05:30
end
2021-03-11 19:13:27 +05:30
describe 'GET projects/:id/packages/debian/dists/*distribution/InRelease' do
2021-09-04 01:27:46 +05:30
let(:url) { "/projects/#{container.id}/packages/debian/dists/#{distribution.codename}/InRelease" }
2021-01-03 14:25:43 +05:30
2021-12-11 22:18:48 +05:30
it_behaves_like 'Debian packages read endpoint', 'GET', :success, /^-----BEGIN PGP SIGNED MESSAGE-----/
2023-06-20 00:43:36 +05:30
it_behaves_like 'a Debian package tracking event', 'list_package'
2023-03-17 16:20:25 +05:30
it_behaves_like 'accept GET request on private project with access to package registry for everyone'
2021-01-03 14:25:43 +05:30
end
2021-03-11 19:13:27 +05:30
describe 'GET projects/:id/packages/debian/dists/*distribution/:component/binary-:architecture/Packages' do
2023-05-27 22:25:52 +05:30
let(:target_component_file) { component_file }
let(:target_component_name) { component.name }
let(:url) { "/projects/#{container.id}/packages/debian/dists/#{distribution.codename}/#{target_component_name}/binary-#{architecture.name}/Packages" }
2021-01-03 14:25:43 +05:30
2023-05-27 22:25:52 +05:30
it_behaves_like 'Debian packages index endpoint', /Description: This is an incomplete Packages file/
2023-06-20 00:43:36 +05:30
it_behaves_like 'a Debian package tracking event', 'list_package'
2023-03-17 16:20:25 +05:30
it_behaves_like 'accept GET request on private project with access to package registry for everyone'
2021-01-03 14:25:43 +05:30
end
2023-04-23 21:23:45 +05:30
describe 'GET projects/:id/packages/debian/dists/*distribution/:component/binary-:architecture/Packages.gz' do
let(:url) { "/projects/#{container.id}/packages/debian/dists/#{distribution.codename}/#{component.name}/binary-#{architecture.name}/Packages.gz" }
it_behaves_like 'Debian packages read endpoint', 'GET', :not_found, /Format gz is not supported/
2023-06-20 00:43:36 +05:30
it_behaves_like 'not a Debian package tracking event'
2023-04-23 21:23:45 +05:30
end
2022-10-11 01:57:18 +05:30
describe 'GET projects/:id/packages/debian/dists/*distribution/:component/binary-:architecture/by-hash/SHA256/:file_sha256' do
2023-05-27 22:25:52 +05:30
let(:target_component_file) { component_file_older_sha256 }
let(:target_component_name) { component.name }
let(:target_sha256) { target_component_file.file_sha256 }
let(:url) { "/projects/#{container.id}/packages/debian/dists/#{distribution.codename}/#{target_component_name}/binary-#{architecture.name}/by-hash/SHA256/#{target_sha256}" }
2022-10-11 01:57:18 +05:30
2023-05-27 22:25:52 +05:30
it_behaves_like 'Debian packages index sha256 endpoint', /^Other SHA256$/
2023-06-20 00:43:36 +05:30
it_behaves_like 'a Debian package tracking event', 'list_package'
2023-03-17 16:20:25 +05:30
it_behaves_like 'accept GET request on private project with access to package registry for everyone'
2022-10-11 01:57:18 +05:30
end
2023-03-17 16:20:25 +05:30
describe 'GET projects/:id/packages/debian/dists/*distribution/:component/source/Sources' do
2023-05-27 22:25:52 +05:30
let(:target_component_file) { component_file_sources }
let(:target_component_name) { component.name }
let(:url) { "/projects/#{container.id}/packages/debian/dists/#{distribution.codename}/#{target_component_name}/source/Sources" }
2022-10-11 01:57:18 +05:30
2023-05-27 22:25:52 +05:30
it_behaves_like 'Debian packages index endpoint', /^Description: This is an incomplete Sources file$/
2023-06-20 00:43:36 +05:30
it_behaves_like 'a Debian package tracking event', 'list_package'
2023-03-17 16:20:25 +05:30
it_behaves_like 'accept GET request on private project with access to package registry for everyone'
2022-10-11 01:57:18 +05:30
end
2023-03-17 16:20:25 +05:30
describe 'GET projects/:id/packages/debian/dists/*distribution/:component/source/by-hash/SHA256/:file_sha256' do
2023-05-27 22:25:52 +05:30
let(:target_component_file) { component_file_sources_older_sha256 }
let(:target_component_name) { component.name }
let(:target_sha256) { target_component_file.file_sha256 }
let(:url) { "/projects/#{container.id}/packages/debian/dists/#{distribution.codename}/#{target_component_name}/source/by-hash/SHA256/#{target_sha256}" }
2022-10-11 01:57:18 +05:30
2023-05-27 22:25:52 +05:30
it_behaves_like 'Debian packages index sha256 endpoint', /^Other SHA256$/
2023-06-20 00:43:36 +05:30
it_behaves_like 'a Debian package tracking event', 'list_package'
2023-03-17 16:20:25 +05:30
it_behaves_like 'accept GET request on private project with access to package registry for everyone'
2022-10-11 01:57:18 +05:30
end
describe 'GET projects/:id/packages/debian/dists/*distribution/:component/debian-installer/binary-:architecture/Packages' do
2023-05-27 22:25:52 +05:30
let(:target_component_file) { component_file_di }
let(:target_component_name) { component.name }
let(:url) { "/projects/#{container.id}/packages/debian/dists/#{distribution.codename}/#{target_component_name}/debian-installer/binary-#{architecture.name}/Packages" }
2022-10-11 01:57:18 +05:30
2023-05-27 22:25:52 +05:30
it_behaves_like 'Debian packages index endpoint', /Description: This is an incomplete D-I Packages file/
2023-06-20 00:43:36 +05:30
it_behaves_like 'a Debian package tracking event', 'list_package'
2023-03-17 16:20:25 +05:30
it_behaves_like 'accept GET request on private project with access to package registry for everyone'
2022-10-11 01:57:18 +05:30
end
2023-04-23 21:23:45 +05:30
describe 'GET projects/:id/packages/debian/dists/*distribution/:component/debian-installer/binary-:architecture/Packages.gz' do
let(:url) { "/projects/#{container.id}/packages/debian/dists/#{distribution.codename}/#{component.name}/debian-installer/binary-#{architecture.name}/Packages.gz" }
it_behaves_like 'Debian packages read endpoint', 'GET', :not_found, /Format gz is not supported/
2023-06-20 00:43:36 +05:30
it_behaves_like 'not a Debian package tracking event'
2023-04-23 21:23:45 +05:30
end
2022-10-11 01:57:18 +05:30
describe 'GET projects/:id/packages/debian/dists/*distribution/:component/debian-installer/binary-:architecture/by-hash/SHA256/:file_sha256' do
2023-05-27 22:25:52 +05:30
let(:target_component_file) { component_file_di_older_sha256 }
let(:target_component_name) { component.name }
let(:target_sha256) { target_component_file.file_sha256 }
let(:url) { "/projects/#{container.id}/packages/debian/dists/#{distribution.codename}/#{target_component_name}/debian-installer/binary-#{architecture.name}/by-hash/SHA256/#{target_sha256}" }
2022-10-11 01:57:18 +05:30
2023-05-27 22:25:52 +05:30
it_behaves_like 'Debian packages index sha256 endpoint', /^Other SHA256$/
2023-06-20 00:43:36 +05:30
it_behaves_like 'a Debian package tracking event', 'list_package'
2023-03-17 16:20:25 +05:30
it_behaves_like 'accept GET request on private project with access to package registry for everyone'
2022-10-11 01:57:18 +05:30
end
2021-10-27 15:23:28 +05:30
describe 'GET projects/:id/packages/debian/pool/:codename/:letter/:package_name/:package_version/:file_name' do
2022-10-11 01:57:18 +05:30
using RSpec::Parameterized::TableSyntax
2021-10-27 15:23:28 +05:30
let(:url) { "/projects/#{container.id}/packages/debian/pool/#{package.debian_distribution.codename}/#{letter}/#{package.name}/#{package.version}/#{file_name}" }
2021-12-11 22:18:48 +05:30
let(:file_name) { params[:file_name] }
2021-10-27 15:23:28 +05:30
where(:file_name, :success_body) do
'sample_1.2.3~alpha2.tar.xz' | /^.7zXZ/
'sample_1.2.3~alpha2.dsc' | /^Format: 3.0 \(native\)/
'libsample0_1.2.3~alpha2_amd64.deb' | /^!<arch>/
'sample-udeb_1.2.3~alpha2_amd64.udeb' | /^!<arch>/
2023-05-27 22:25:52 +05:30
'sample-ddeb_1.2.3~alpha2_amd64.ddeb' | /^!<arch>/
2021-10-27 15:23:28 +05:30
'sample_1.2.3~alpha2_amd64.buildinfo' | /Build-Tainted-By/
'sample_1.2.3~alpha2_amd64.changes' | /urgency=medium/
end
with_them do
2021-12-11 22:18:48 +05:30
it_behaves_like 'Debian packages read endpoint', 'GET', :success, params[:success_body]
2023-06-20 00:43:36 +05:30
it_behaves_like 'a Debian package tracking event', 'pull_package'
2022-10-11 01:57:18 +05:30
context 'for bumping last downloaded at' do
include_context 'Debian repository access', :public, :developer, :basic do
it_behaves_like 'bumping the package last downloaded at field'
end
end
2021-10-27 15:23:28 +05:30
end
2023-03-17 16:20:25 +05:30
it_behaves_like 'accept GET request on private project with access to package registry for everyone' do
let(:file_name) { 'sample_1.2.3~alpha2.dsc' }
end
2021-01-03 14:25:43 +05:30
end
2021-03-11 19:13:27 +05:30
describe 'PUT projects/:id/packages/debian/:file_name' do
2021-01-03 14:25:43 +05:30
let(:method) { :put }
2021-06-08 01:23:25 +05:30
let(:url) { "/projects/#{container.id}/packages/debian/#{file_name}" }
2021-01-03 14:25:43 +05:30
2021-09-04 01:27:46 +05:30
context 'with a deb' do
let(:file_name) { 'libsample0_1.2.3~alpha2_amd64.deb' }
2021-12-11 22:18:48 +05:30
it_behaves_like 'Debian packages write endpoint', 'upload', :created, nil
2023-07-09 08:55:56 +05:30
it_behaves_like 'Debian packages endpoint catching ObjectStorage::RemoteStoreError'
2023-06-20 00:43:36 +05:30
it_behaves_like 'a Debian package tracking event', 'push_package'
2023-04-23 21:23:45 +05:30
context 'with codename and component' do
let(:extra_params) { { distribution: distribution.codename, component: 'main' } }
it_behaves_like 'Debian packages write endpoint', 'upload', :created, nil
2023-06-20 00:43:36 +05:30
it_behaves_like 'a Debian package tracking event', 'push_package'
2023-04-23 21:23:45 +05:30
end
context 'with codename and without component' do
let(:extra_params) { { distribution: distribution.codename } }
include_context 'Debian repository access', :public, :developer, :basic do
it_behaves_like 'Debian packages GET request', :bad_request, /component is missing/
end
2023-06-20 00:43:36 +05:30
it_behaves_like 'not a Debian package tracking event'
2023-04-23 21:23:45 +05:30
end
end
context 'with a buildinfo' do
let(:file_name) { 'sample_1.2.3~alpha2_amd64.buildinfo' }
include_context 'Debian repository access', :public, :developer, :basic do
it_behaves_like "Debian packages upload request", :created, nil
2023-06-20 00:43:36 +05:30
end
2023-04-23 21:23:45 +05:30
2023-06-20 00:43:36 +05:30
it_behaves_like 'a Debian package tracking event', 'push_package'
2023-04-23 21:23:45 +05:30
2023-06-20 00:43:36 +05:30
context 'with codename and component' do
let(:extra_params) { { distribution: distribution.codename, component: 'main' } }
include_context 'Debian repository access', :public, :developer, :basic do
2023-04-23 21:23:45 +05:30
it_behaves_like "Debian packages upload request", :bad_request,
2023-05-27 22:25:52 +05:30
/^file_name Only debs, udebs and ddebs can be directly added to a distribution$/
2023-04-23 21:23:45 +05:30
end
2023-06-20 00:43:36 +05:30
it_behaves_like 'not a Debian package tracking event'
2023-04-23 21:23:45 +05:30
end
2021-09-04 01:27:46 +05:30
end
context 'with a changes file' do
let(:file_name) { 'sample_1.2.3~alpha2_amd64.changes' }
2021-12-11 22:18:48 +05:30
it_behaves_like 'Debian packages write endpoint', 'upload', :created, nil
2023-06-20 00:43:36 +05:30
it_behaves_like 'a Debian package tracking event', 'push_package'
2021-09-04 01:27:46 +05:30
end
2021-01-03 14:25:43 +05:30
end
2021-03-08 18:12:59 +05:30
2021-03-11 19:13:27 +05:30
describe 'PUT projects/:id/packages/debian/:file_name/authorize' do
2021-09-04 01:27:46 +05:30
let(:file_name) { 'libsample0_1.2.3~alpha2_amd64.deb' }
2021-03-08 18:12:59 +05:30
let(:method) { :put }
2021-06-08 01:23:25 +05:30
let(:url) { "/projects/#{container.id}/packages/debian/#{file_name}/authorize" }
2021-03-08 18:12:59 +05:30
2021-12-11 22:18:48 +05:30
it_behaves_like 'Debian packages write endpoint', 'upload authorize', :created, nil
2023-06-20 00:43:36 +05:30
it_behaves_like 'not a Debian package tracking event'
2021-03-08 18:12:59 +05:30
end
2021-01-03 14:25:43 +05:30
end
end