diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-04-20 23:50:22 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-04-20 23:50:22 +0000 |
commit | 9dc93a4519d9d5d7be48ff274127136236a3adb3 (patch) | |
tree | 70467ae3692a0e35e5ea56bcb803eb512a10bedb /spec/services/packages/debian | |
parent | 4b0f34b6d759d6299322b3a54453e930c6121ff0 (diff) | |
download | gitlab-ce-9dc93a4519d9d5d7be48ff274127136236a3adb3.tar.gz |
Add latest changes from gitlab-org/gitlab@13-11-stable-eev13.11.0-rc43
Diffstat (limited to 'spec/services/packages/debian')
5 files changed, 271 insertions, 53 deletions
diff --git a/spec/services/packages/debian/extract_changes_metadata_service_spec.rb b/spec/services/packages/debian/extract_changes_metadata_service_spec.rb new file mode 100644 index 00000000000..2a92b8ed26e --- /dev/null +++ b/spec/services/packages/debian/extract_changes_metadata_service_spec.rb @@ -0,0 +1,160 @@ +# frozen_string_literal: true +require 'spec_helper' + +RSpec.describe Packages::Debian::ExtractChangesMetadataService do + describe '#execute' do + let_it_be(:distribution) { create(:debian_project_distribution, codename: 'unstable') } + let_it_be(:incoming) { create(:debian_incoming, project: distribution.project) } + + let(:package_file) { incoming.package_files.last } + let(:service) { described_class.new(package_file) } + + subject { service.execute } + + context 'with valid package file' do + it 'extract metadata', :aggregate_failures do + expected_fields = { 'Architecture' => 'source amd64', 'Binary' => 'libsample0 sample-dev sample-udeb' } + + expect(subject[:file_type]).to eq(:changes) + expect(subject[:architecture]).to be_nil + expect(subject[:fields]).to include(expected_fields) + expect(subject[:files].count).to eq(6) + end + end + + context 'with invalid package file' do + let(:package_file) { incoming.package_files.first } + + it 'raise ArgumentError', :aggregate_failures do + expect { subject }.to raise_error(described_class::ExtractionError, "is not a changes file") + end + end + + context 'with invalid metadata' do + let(:md5_dsc) { '3b0817804f669e16cdefac583ad88f0e 671 libs optional sample_1.2.3~alpha2.dsc' } + let(:md5_source) { 'd79b34f58f61ff4ad696d9bd0b8daa68 864 libs optional sample_1.2.3~alpha2.tar.xz' } + let(:md5s) { "#{md5_dsc}\n#{md5_source}" } + let(:sha1_dsc) { '32ecbd674f0bfd310df68484d87752490685a8d6 671 sample_1.2.3~alpha2.dsc' } + let(:sha1_source) { '5f8bba5574eb01ac3b1f5e2988e8c29307788236 864 sample_1.2.3~alpha2.tar.xz' } + let(:sha1s) { "#{sha1_dsc}\n#{sha1_source}" } + let(:sha256_dsc) { '844f79825b7e8aaa191e514b58a81f9ac1e58e2180134b0c9512fa66d896d7ba 671 sample_1.2.3~alpha2.dsc' } + let(:sha256_source) { 'b5a599e88e7cbdda3bde808160a21ba1dd1ec76b2ec8d4912aae769648d68362 864 sample_1.2.3~alpha2.tar.xz' } + let(:sha256s) { "#{sha256_dsc}\n#{sha256_source}" } + let(:fields) { { 'Files' => md5s, 'Checksums-Sha1' => sha1s, 'Checksums-Sha256' => sha256s } } + let(:metadata) { { file_type: :changes, architecture: 'amd64', fields: fields } } + + before do + allow_next_instance_of(::Packages::Debian::ExtractMetadataService) do |extract_metadata_service| + allow(extract_metadata_service).to receive(:execute).and_return(metadata) + end + end + + context 'without Files field' do + let(:md5s) { nil } + + it 'raise ArgumentError', :aggregate_failures do + expect { subject }.to raise_error(described_class::ExtractionError, "Files field is missing") + end + end + + context 'without Checksums-Sha1 field' do + let(:sha1s) { nil } + + it 'raise ArgumentError', :aggregate_failures do + expect { subject }.to raise_error(described_class::ExtractionError, "Checksums-Sha1 field is missing") + end + end + + context 'without Checksums-Sha256 field' do + let(:sha256s) { nil } + + it 'raise ArgumentError', :aggregate_failures do + expect { subject }.to raise_error(described_class::ExtractionError, "Checksums-Sha256 field is missing") + end + end + + context 'with file in Checksums-Sha1 but not in Files' do + let(:md5_dsc) { '' } + + it 'raise ArgumentError', :aggregate_failures do + expect { subject }.to raise_error(described_class::ExtractionError, "sample_1.2.3~alpha2.dsc is listed in Checksums-Sha1 but not in Files") + end + end + + context 'with different size in Checksums-Sha1' do + let(:sha1_dsc) { '32ecbd674f0bfd310df68484d87752490685a8d6 42 sample_1.2.3~alpha2.dsc' } + + it 'raise ArgumentError', :aggregate_failures do + expect { subject }.to raise_error(described_class::ExtractionError, "Size for sample_1.2.3~alpha2.dsc in Files and Checksums-Sha1 differ") + end + end + + context 'with file in Checksums-Sha256 but not in Files' do + let(:md5_dsc) { '' } + let(:sha1_dsc) { '' } + + it 'raise ArgumentError', :aggregate_failures do + expect { subject }.to raise_error(described_class::ExtractionError, "sample_1.2.3~alpha2.dsc is listed in Checksums-Sha256 but not in Files") + end + end + + context 'with different size in Checksums-Sha256' do + let(:sha256_dsc) { '844f79825b7e8aaa191e514b58a81f9ac1e58e2180134b0c9512fa66d896d7ba 42 sample_1.2.3~alpha2.dsc' } + + it 'raise ArgumentError', :aggregate_failures do + expect { subject }.to raise_error(described_class::ExtractionError, "Size for sample_1.2.3~alpha2.dsc in Files and Checksums-Sha256 differ") + end + end + + context 'with file in Files but not in Checksums-Sha1' do + let(:sha1_dsc) { '' } + + it 'raise ArgumentError', :aggregate_failures do + expect { subject }.to raise_error(described_class::ExtractionError, "Validation failed: Sha1sum can't be blank") + end + end + + context 'with file in Files but not in Checksums-Sha256' do + let(:sha256_dsc) { '' } + + it 'raise ArgumentError', :aggregate_failures do + expect { subject }.to raise_error(described_class::ExtractionError, "Validation failed: Sha256sum can't be blank") + end + end + + context 'with invalid MD5' do + let(:md5_dsc) { '1234567890123456789012345678012 671 libs optional sample_1.2.3~alpha2.dsc' } + + it 'raise ArgumentError', :aggregate_failures do + expect { subject }.to raise_error(described_class::ExtractionError, "Validation failed: Md5sum mismatch for sample_1.2.3~alpha2.dsc: 3b0817804f669e16cdefac583ad88f0e != 1234567890123456789012345678012") + end + end + + context 'with invalid SHA1' do + let(:sha1_dsc) { '1234567890123456789012345678901234567890 671 sample_1.2.3~alpha2.dsc' } + + it 'raise ArgumentError', :aggregate_failures do + expect { subject }.to raise_error(described_class::ExtractionError, "Validation failed: Sha1sum mismatch for sample_1.2.3~alpha2.dsc: 32ecbd674f0bfd310df68484d87752490685a8d6 != 1234567890123456789012345678901234567890") + end + end + + context 'with invalid SHA256' do + let(:sha256_dsc) { '1234567890123456789012345678901234567890123456789012345678901234 671 sample_1.2.3~alpha2.dsc' } + + it 'raise ArgumentError', :aggregate_failures do + expect { subject }.to raise_error(described_class::ExtractionError, "Validation failed: Sha256sum mismatch for sample_1.2.3~alpha2.dsc: 844f79825b7e8aaa191e514b58a81f9ac1e58e2180134b0c9512fa66d896d7ba != 1234567890123456789012345678901234567890123456789012345678901234") + end + end + end + + context 'with missing package file' do + before do + incoming.package_files.first.destroy! + end + + it 'raise ArgumentError' do + expect { subject }.to raise_error(described_class::ExtractionError, "sample_1.2.3~alpha2.tar.xz is listed in Files but was not uploaded") + end + end + end +end diff --git a/spec/services/packages/debian/extract_deb_metadata_service_spec.rb b/spec/services/packages/debian/extract_deb_metadata_service_spec.rb index 33059adf8a2..ee3f3d179dc 100644 --- a/spec/services/packages/debian/extract_deb_metadata_service_spec.rb +++ b/spec/services/packages/debian/extract_deb_metadata_service_spec.rb @@ -10,17 +10,17 @@ RSpec.describe Packages::Debian::ExtractDebMetadataService do context 'with correct file' do it 'return as expected' do expected = { - 'Package': 'libsample0', - 'Source': 'sample', - 'Version': '1.2.3~alpha2', - 'Architecture': 'amd64', - 'Maintainer': 'John Doe <john.doe@example.com>', - 'Installed-Size': '7', - 'Section': 'libs', - 'Priority': 'optional', - 'Multi-Arch': 'same', - 'Homepage': 'https://gitlab.com/', - 'Description': "Some mostly empty lib\nUsed in GitLab tests.\n\nTesting another paragraph." + 'Package' => 'libsample0', + 'Source' => 'sample', + 'Version' => '1.2.3~alpha2', + 'Architecture' => 'amd64', + 'Maintainer' => 'John Doe <john.doe@example.com>', + 'Installed-Size' => '7', + 'Section' => 'libs', + 'Priority' => 'optional', + 'Multi-Arch' => 'same', + 'Homepage' => 'https://gitlab.com/', + 'Description' => "Some mostly empty lib\nUsed in GitLab tests.\n\nTesting another paragraph." } expect(subject.execute).to eq expected diff --git a/spec/services/packages/debian/extract_metadata_service_spec.rb b/spec/services/packages/debian/extract_metadata_service_spec.rb index 0aa9a67b263..e3911dbbfe0 100644 --- a/spec/services/packages/debian/extract_metadata_service_spec.rb +++ b/spec/services/packages/debian/extract_metadata_service_spec.rb @@ -33,11 +33,11 @@ RSpec.describe Packages::Debian::ExtractMetadataService do where(:case_name, :trait, :expected_file_type, :expected_architecture, :expected_fields) do 'with invalid' | :invalid | :unknown | nil | nil 'with source' | :source | :source | nil | nil - 'with dsc' | :dsc | :dsc | nil | { 'Binary': 'sample-dev, libsample0, sample-udeb' } - 'with deb' | :deb | :deb | 'amd64' | { 'Multi-Arch': 'same' } - 'with udeb' | :udeb | :udeb | 'amd64' | { 'Package': 'sample-udeb' } - 'with buildinfo' | :buildinfo | :buildinfo | nil | { 'Architecture': 'amd64 source', 'Build-Architecture': 'amd64' } - 'with changes' | :changes | :changes | nil | { 'Architecture': 'source amd64', 'Binary': 'libsample0 sample-dev sample-udeb' } + 'with dsc' | :dsc | :dsc | nil | { 'Binary' => 'sample-dev, libsample0, sample-udeb' } + 'with deb' | :deb | :deb | 'amd64' | { 'Multi-Arch' => 'same' } + 'with udeb' | :udeb | :udeb | 'amd64' | { 'Package' => 'sample-udeb' } + 'with buildinfo' | :buildinfo | :buildinfo | nil | { 'Architecture' => 'amd64 source', 'Build-Architecture' => 'amd64' } + 'with changes' | :changes | :changes | nil | { 'Architecture' => 'source amd64', 'Binary' => 'libsample0 sample-dev sample-udeb' } end with_them do diff --git a/spec/services/packages/debian/parse_debian822_service_spec.rb b/spec/services/packages/debian/parse_debian822_service_spec.rb index b67daca89c4..f43e38991ce 100644 --- a/spec/services/packages/debian/parse_debian822_service_spec.rb +++ b/spec/services/packages/debian/parse_debian822_service_spec.rb @@ -27,17 +27,17 @@ RSpec.describe Packages::Debian::ParseDebian822Service do it 'return as expected, preserving order' do expected = { 'Package: libsample0' => { - 'Package': 'libsample0', - 'Source': 'sample', - 'Version': '1.2.3~alpha2', - 'Architecture': 'amd64', - 'Maintainer': 'John Doe <john.doe@example.com>', - 'Installed-Size': '9', - 'Section': 'libs', - 'Priority': 'optional', - 'Multi-Arch': 'same', - 'Homepage': 'https://gitlab.com/', - 'Description': "Some mostly empty lib\nUsed in GitLab tests.\n\nTesting another paragraph." + 'Package' => 'libsample0', + 'Source' => 'sample', + 'Version' => '1.2.3~alpha2', + 'Architecture' => 'amd64', + 'Maintainer' => 'John Doe <john.doe@example.com>', + 'Installed-Size' => '9', + 'Section' => 'libs', + 'Priority' => 'optional', + 'Multi-Arch' => 'same', + 'Homepage' => 'https://gitlab.com/', + 'Description' => "Some mostly empty lib\nUsed in GitLab tests.\n\nTesting another paragraph." } } @@ -51,38 +51,38 @@ RSpec.describe Packages::Debian::ParseDebian822Service do it 'return as expected, preserving order' do expected = { 'Source: sample' => { - 'Source': 'sample', - 'Priority': 'optional', - 'Maintainer': 'John Doe <john.doe@example.com>', - 'Build-Depends': 'debhelper-compat (= 13)', - 'Standards-Version': '4.5.0', - 'Section': 'libs', - 'Homepage': 'https://gitlab.com/', - # 'Vcs-Browser': 'https://salsa.debian.org/debian/sample-1.2.3', - # '#Vcs-Git': 'https://salsa.debian.org/debian/sample-1.2.3.git', - 'Rules-Requires-Root': 'no' + 'Source' => 'sample', + 'Priority' => 'optional', + 'Maintainer' => 'John Doe <john.doe@example.com>', + 'Build-Depends' => 'debhelper-compat (= 13)', + 'Standards-Version' => '4.5.0', + 'Section' => 'libs', + 'Homepage' => 'https://gitlab.com/', + # 'Vcs-Browser' => 'https://salsa.debian.org/debian/sample-1.2.3', + # '#Vcs-Git' => 'https://salsa.debian.org/debian/sample-1.2.3.git', + 'Rules-Requires-Root' => 'no' }, 'Package: sample-dev' => { - 'Package': 'sample-dev', - 'Section': 'libdevel', - 'Architecture': 'any', - 'Multi-Arch': 'same', - 'Depends': 'libsample0 (= ${binary:Version}), ${misc:Depends}', - 'Description': "Some mostly empty developpement files\nUsed in GitLab tests.\n\nTesting another paragraph." + 'Package' => 'sample-dev', + 'Section' => 'libdevel', + 'Architecture' => 'any', + 'Multi-Arch' => 'same', + 'Depends' => 'libsample0 (= ${binary:Version}), ${misc:Depends}', + 'Description' => "Some mostly empty developpement files\nUsed in GitLab tests.\n\nTesting another paragraph." }, 'Package: libsample0' => { - 'Package': 'libsample0', - 'Architecture': 'any', - 'Multi-Arch': 'same', - 'Depends': '${shlibs:Depends}, ${misc:Depends}', - 'Description': "Some mostly empty lib\nUsed in GitLab tests.\n\nTesting another paragraph." + 'Package' => 'libsample0', + 'Architecture' => 'any', + 'Multi-Arch' => 'same', + 'Depends' => '${shlibs:Depends}, ${misc:Depends}', + 'Description' => "Some mostly empty lib\nUsed in GitLab tests.\n\nTesting another paragraph." }, 'Package: sample-udeb' => { - 'Package': 'sample-udeb', - 'Package-Type': 'udeb', - 'Architecture': 'any', - 'Depends': 'installed-base', - 'Description': 'Some mostly empty udeb' + 'Package' => 'sample-udeb', + 'Package-Type' => 'udeb', + 'Architecture' => 'any', + 'Depends' => 'installed-base', + 'Description' => 'Some mostly empty udeb' } } diff --git a/spec/services/packages/debian/process_changes_service_spec.rb b/spec/services/packages/debian/process_changes_service_spec.rb new file mode 100644 index 00000000000..98b531bde10 --- /dev/null +++ b/spec/services/packages/debian/process_changes_service_spec.rb @@ -0,0 +1,58 @@ +# frozen_string_literal: true +require 'spec_helper' + +RSpec.describe Packages::Debian::ProcessChangesService do + describe '#execute' do + let_it_be(:user) { create(:user) } + let_it_be_with_reload(:distribution) { create(:debian_project_distribution, :with_file, codename: 'unstable') } + let_it_be(:incoming) { create(:debian_incoming, project: distribution.project) } + + let(:package_file) { incoming.package_files.last } + + subject { described_class.new(package_file, user) } + + context 'with valid package file' do + it 'updates package and package file', :aggregate_failures do + expect { subject.execute } + .to change { Packages::Package.count }.from(1).to(2) + .and not_change { Packages::PackageFile.count } + .and change { incoming.package_files.count }.from(7).to(0) + + created_package = Packages::Package.last + expect(created_package.name).to eq 'sample' + expect(created_package.version).to eq '1.2.3~alpha2' + expect(created_package.creator).to eq user + end + end + + context 'with invalid package file' do + let(:package_file) { incoming.package_files.first } + + it 'raise ExtractionError', :aggregate_failures do + expect { subject.execute } + .to not_change { Packages::Package.count } + .and not_change { Packages::PackageFile.count } + .and not_change { incoming.package_files.count } + .and not_change { distribution.reload.needs_update? } + .and raise_error(Packages::Debian::ExtractChangesMetadataService::ExtractionError, 'is not a changes file') + end + end + + context 'when creating package fails' do + before do + allow_next_instance_of(::Packages::Debian::FindOrCreatePackageService) do |find_or_create_package_service| + expect(find_or_create_package_service).to receive(:execute).and_raise(ActiveRecord::ConnectionTimeoutError, 'connect timeout') + end + end + + it 'remove the package file', :aggregate_failures do + expect { subject.execute } + .to not_change { Packages::Package.count } + .and not_change { Packages::PackageFile.count } + .and not_change { incoming.package_files.count } + .and not_change { distribution.reload.needs_update? } + .and raise_error(ActiveRecord::ConnectionTimeoutError, 'connect timeout') + end + end + end +end |