summaryrefslogtreecommitdiff
path: root/spec/workers
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2020-10-30 16:57:06 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2020-10-30 16:57:06 +0000
commitb4cf4027c64afc4f009452a9bfade231e2ff421a (patch)
treecfa307b5d1583471285709032f559ab2ac4be1d5 /spec/workers
parent0cb369aa5f70b59e5922d8f5431a3302fd93574e (diff)
downloadgitlab-ce-b4cf4027c64afc4f009452a9bfade231e2ff421a.tar.gz
Add latest changes from gitlab-org/security/gitlab@13-5-stable-ee
Diffstat (limited to 'spec/workers')
-rw-r--r--spec/workers/packages/nuget/extraction_worker_spec.rb78
1 files changed, 45 insertions, 33 deletions
diff --git a/spec/workers/packages/nuget/extraction_worker_spec.rb b/spec/workers/packages/nuget/extraction_worker_spec.rb
index 35b5f1baed5..4703afc9413 100644
--- a/spec/workers/packages/nuget/extraction_worker_spec.rb
+++ b/spec/workers/packages/nuget/extraction_worker_spec.rb
@@ -13,6 +13,18 @@ RSpec.describe Packages::Nuget::ExtractionWorker, type: :worker do
subject { described_class.new.perform(package_file_id) }
+ shared_examples 'handling the metadata error' do |exception_class: ::Packages::Nuget::UpdatePackageFromMetadataService::InvalidMetadataError|
+ it 'removes the package and the package file' do
+ expect(Gitlab::ErrorTracking).to receive(:log_exception).with(
+ instance_of(exception_class),
+ project_id: package.project_id
+ )
+ expect { subject }
+ .to change { Packages::Package.count }.by(-1)
+ .and change { Packages::PackageFile.count }.by(-1)
+ end
+ end
+
context 'with valid package file' do
it 'updates package and package file' do
expect { subject }
@@ -48,46 +60,46 @@ RSpec.describe Packages::Nuget::ExtractionWorker, type: :worker do
allow_any_instance_of(Zip::File).to receive(:glob).and_return([])
end
- it 'removes the package and the package file' do
- expect(Gitlab::ErrorTracking).to receive(:log_exception).with(
- instance_of(::Packages::Nuget::MetadataExtractionService::ExtractionError),
- project_id: package.project_id
- )
- expect { subject }
- .to change { Packages::Package.count }.by(-1)
- .and change { Packages::PackageFile.count }.by(-1)
- end
+ it_behaves_like 'handling the metadata error', exception_class: ::Packages::Nuget::MetadataExtractionService::ExtractionError
end
- context 'with package file with a blank package name' do
- before do
- allow_any_instance_of(::Packages::Nuget::UpdatePackageFromMetadataService).to receive(:package_name).and_return('')
- end
+ context 'with package with an invalid package name' do
+ invalid_names = [
+ '',
+ 'My/package',
+ '../../../my_package',
+ '%2e%2e%2fmy_package'
+ ]
- it 'removes the package and the package file' do
- expect(Gitlab::ErrorTracking).to receive(:log_exception).with(
- instance_of(::Packages::Nuget::UpdatePackageFromMetadataService::InvalidMetadataError),
- project_id: package.project_id
- )
- expect { subject }
- .to change { Packages::Package.count }.by(-1)
- .and change { Packages::PackageFile.count }.by(-1)
+ invalid_names.each do |invalid_name|
+ before do
+ allow_next_instance_of(::Packages::Nuget::UpdatePackageFromMetadataService) do |service|
+ allow(service).to receive(:package_name).and_return(invalid_name)
+ end
+ end
+
+ it_behaves_like 'handling the metadata error'
end
end
- context 'with package file with a blank package version' do
- before do
- allow_any_instance_of(::Packages::Nuget::UpdatePackageFromMetadataService).to receive(:package_version).and_return('')
- end
+ context 'with package with an invalid package version' do
+ invalid_versions = [
+ '',
+ '555',
+ '1.2',
+ '1./2.3',
+ '../../../../../1.2.3',
+ '%2e%2e%2f1.2.3'
+ ]
- it 'removes the package and the package file' do
- expect(Gitlab::ErrorTracking).to receive(:log_exception).with(
- instance_of(::Packages::Nuget::UpdatePackageFromMetadataService::InvalidMetadataError),
- project_id: package.project_id
- )
- expect { subject }
- .to change { Packages::Package.count }.by(-1)
- .and change { Packages::PackageFile.count }.by(-1)
+ invalid_versions.each do |invalid_version|
+ before do
+ allow_next_instance_of(::Packages::Nuget::UpdatePackageFromMetadataService) do |service|
+ allow(service).to receive(:package_version).and_return(invalid_version)
+ end
+ end
+
+ it_behaves_like 'handling the metadata error'
end
end
end