diff options
Diffstat (limited to 'spec/requests/api')
-rw-r--r-- | spec/requests/api/composer_packages_spec.rb | 29 | ||||
-rw-r--r-- | spec/requests/api/generic_packages_spec.rb | 27 | ||||
-rw-r--r-- | spec/requests/api/pypi_packages_spec.rb | 29 | ||||
-rw-r--r-- | spec/requests/api/terraform/modules/v1/packages_spec.rb | 22 |
4 files changed, 107 insertions, 0 deletions
diff --git a/spec/requests/api/composer_packages_spec.rb b/spec/requests/api/composer_packages_spec.rb index 21b4634ce25..bc30fc3b230 100644 --- a/spec/requests/api/composer_packages_spec.rb +++ b/spec/requests/api/composer_packages_spec.rb @@ -327,6 +327,35 @@ RSpec.describe API::ComposerPackages do it_behaves_like 'rejects Composer access with unknown project id' end + context 'with existing package' do + include_context 'Composer api project access', 'PRIVATE', :developer, true, true + + let_it_be_with_reload(:existing_package) { create(:composer_package, name: package_name, version: '1.2.99', project: project) } + + let(:params) { { tag: 'v1.2.99' } } + + before do + project.add_maintainer(user) + end + + it 'does not create a new package' do + expect { subject } + .to change { project.packages.composer.count }.by(0) + + expect(response).to have_gitlab_http_status(:created) + end + + context 'marked as pending_destruction' do + it 'does create a new package' do + existing_package.pending_destruction! + expect { subject } + .to change { project.packages.composer.count }.by(1) + + expect(response).to have_gitlab_http_status(:created) + end + end + end + context 'with no tag or branch params' do let(:headers) { basic_auth_header(user.username, personal_access_token.token) } diff --git a/spec/requests/api/generic_packages_spec.rb b/spec/requests/api/generic_packages_spec.rb index 1836233594d..e1d8a9f0229 100644 --- a/spec/requests/api/generic_packages_spec.rb +++ b/spec/requests/api/generic_packages_spec.rb @@ -426,6 +426,33 @@ RSpec.describe API::GenericPackages do it_behaves_like 'a package tracking event', described_class.name, 'push_package' end + context 'with existing package' do + let_it_be(:package_name) { 'mypackage' } + let_it_be(:package_version) { '1.2.3' } + let_it_be_with_reload(:existing_package) { create(:generic_package, name: package_name, version: package_version, project: project) } + + let(:headers) { workhorse_headers.merge(personal_access_token_header) } + + it 'does not create a new package' do + expect { upload_file(params, headers, package_name: package_name, package_version: package_version) } + .to change { project.packages.generic.count }.by(0) + .and change { Packages::PackageFile.count }.by(1) + + expect(response).to have_gitlab_http_status(:created) + end + + context 'marked as pending_destruction' do + it 'does create a new package' do + existing_package.pending_destruction! + expect { upload_file(params, headers, package_name: package_name, package_version: package_version) } + .to change { project.packages.generic.count }.by(1) + .and change { Packages::PackageFile.count }.by(1) + + expect(response).to have_gitlab_http_status(:created) + end + end + end + it 'rejects request without a file from workhorse' do headers = workhorse_headers.merge(personal_access_token_header) upload_file({}, headers) diff --git a/spec/requests/api/pypi_packages_spec.rb b/spec/requests/api/pypi_packages_spec.rb index c17d0600aca..fcd2d56e655 100644 --- a/spec/requests/api/pypi_packages_spec.rb +++ b/spec/requests/api/pypi_packages_spec.rb @@ -230,6 +230,35 @@ RSpec.describe API::PypiPackages do it_behaves_like 'returning response status', :bad_request end + + context 'with existing package' do + let_it_be_with_reload(:existing_package) { create(:pypi_package, name: 'sample-project', version: '1.0.0', project: project) } + + let(:headers) { basic_auth_header(user.username, personal_access_token.token).merge(workhorse_headers) } + + before do + project.add_maintainer(user) + end + + it 'does not create a new package', :aggregate_failures do + expect { subject } + .to change { project.packages.pypi.count }.by(0) + .and change { Packages::PackageFile.count }.by(1) + .and change { Packages::Pypi::Metadatum.count }.by(0) + expect(response).to have_gitlab_http_status(:created) + end + + context 'marked as pending_destruction' do + it 'does create a new package', :aggregate_failures do + existing_package.pending_destruction! + expect { subject } + .to change { project.packages.pypi.count }.by(1) + .and change { Packages::PackageFile.count }.by(1) + .and change { Packages::Pypi::Metadatum.count }.by(1) + expect(response).to have_gitlab_http_status(:created) + end + end + end end context 'file download endpoint' do diff --git a/spec/requests/api/terraform/modules/v1/packages_spec.rb b/spec/requests/api/terraform/modules/v1/packages_spec.rb index c0f04ba09be..8160113bbde 100644 --- a/spec/requests/api/terraform/modules/v1/packages_spec.rb +++ b/spec/requests/api/terraform/modules/v1/packages_spec.rb @@ -415,6 +415,28 @@ RSpec.describe API::Terraform::Modules::V1::Packages do .and change { Packages::PackageFile.count }.by(0) expect(response).to have_gitlab_http_status(:error) end + + context 'with an existing package' do + let_it_be_with_reload(:existing_package) { create(:terraform_module_package, name: 'mymodule/mysystem', version: '1.0.0', project: project) } + + it 'does not create a new package' do + expect { subject } + .to change { project.packages.count }.by(0) + .and change { Packages::PackageFile.count }.by(0) + expect(response).to have_gitlab_http_status(:forbidden) + end + + context 'marked as pending_destruction' do + it 'does create a new package' do + existing_package.pending_destruction! + + expect { subject } + .to change { project.packages.count }.by(1) + .and change { Packages::PackageFile.count }.by(1) + expect(response).to have_gitlab_http_status(:created) + end + end + end end end end |