Commit 8f8428ee authored by Mathieu Parent's avatar Mathieu Parent

Debian: Do not use symbols in fields names

Don't use symbols as keys in metadata, following the review comment:
https://gitlab.com/gitlab-org/gitlab/-/merge_requests/55896#note_532350725
parent 60848600
...@@ -42,9 +42,9 @@ module Packages ...@@ -42,9 +42,9 @@ module Packages
def files def files
strong_memoize(:files) do strong_memoize(:files) do
raise ExtractionError.new("is not a changes file") unless file_type == :changes raise ExtractionError.new("is not a changes file") unless file_type == :changes
raise ExtractionError.new("Files field is missing") if fields[:Files].blank? raise ExtractionError.new("Files field is missing") if fields['Files'].blank?
raise ExtractionError.new("Checksums-Sha1 field is missing") if fields[:'Checksums-Sha1'].blank? raise ExtractionError.new("Checksums-Sha1 field is missing") if fields['Checksums-Sha1'].blank?
raise ExtractionError.new("Checksums-Sha256 field is missing") if fields[:'Checksums-Sha256'].blank? raise ExtractionError.new("Checksums-Sha256 field is missing") if fields['Checksums-Sha256'].blank?
init_entries_from_files init_entries_from_files
entries_from_checksums_sha1 entries_from_checksums_sha1
...@@ -56,7 +56,7 @@ module Packages ...@@ -56,7 +56,7 @@ module Packages
end end
def init_entries_from_files def init_entries_from_files
each_lines_for(:Files) do |line| each_lines_for('Files') do |line|
md5sum, size, section, priority, filename = line.split md5sum, size, section, priority, filename = line.split
entry = FileEntry.new( entry = FileEntry.new(
filename: filename, filename: filename,
...@@ -70,7 +70,7 @@ module Packages ...@@ -70,7 +70,7 @@ module Packages
end end
def entries_from_checksums_sha1 def entries_from_checksums_sha1
each_lines_for(:'Checksums-Sha1') do |line| each_lines_for('Checksums-Sha1') do |line|
sha1sum, size, filename = line.split sha1sum, size, filename = line.split
entry = @entries[filename] entry = @entries[filename]
raise ExtractionError.new("#{filename} is listed in Checksums-Sha1 but not in Files") unless entry raise ExtractionError.new("#{filename} is listed in Checksums-Sha1 but not in Files") unless entry
...@@ -81,7 +81,7 @@ module Packages ...@@ -81,7 +81,7 @@ module Packages
end end
def entries_from_checksums_sha256 def entries_from_checksums_sha256
each_lines_for(:'Checksums-Sha256') do |line| each_lines_for('Checksums-Sha256') do |line|
sha256sum, size, filename = line.split sha256sum, size, filename = line.split
entry = @entries[filename] entry = @entries[filename]
raise ExtractionError.new("#{filename} is listed in Checksums-Sha256 but not in Files") unless entry raise ExtractionError.new("#{filename} is listed in Checksums-Sha256 but not in Files") unless entry
......
...@@ -72,7 +72,7 @@ module Packages ...@@ -72,7 +72,7 @@ module Packages
def extract_metadata def extract_metadata
fields = extracted_fields fields = extracted_fields
architecture = fields.delete(:Architecture) if file_type_debian? architecture = fields.delete('Architecture') if file_type_debian?
{ {
file_type: file_type, file_type: file_type,
......
...@@ -26,7 +26,7 @@ module Packages ...@@ -26,7 +26,7 @@ module Packages
section[field] += line[1..] unless paragraph_separator?(line) section[field] += line[1..] unless paragraph_separator?(line)
elsif match = match_section_line(line) elsif match = match_section_line(line)
section_name = match[:name] if section_name.nil? section_name = match[:name] if section_name.nil?
field = match[:field].to_sym field = match[:field]
raise InvalidDebian822Error, "Duplicate field '#{field}' in section '#{section_name}'" if section.include?(field) raise InvalidDebian822Error, "Duplicate field '#{field}' in section '#{section_name}'" if section.include?(field)
......
...@@ -13,7 +13,7 @@ RSpec.describe Packages::Debian::ExtractChangesMetadataService do ...@@ -13,7 +13,7 @@ RSpec.describe Packages::Debian::ExtractChangesMetadataService do
context 'with valid package file' do context 'with valid package file' do
it 'extract metadata', :aggregate_failures do it 'extract metadata', :aggregate_failures do
expected_fields = { 'Architecture': 'source amd64', 'Binary': 'libsample0 sample-dev sample-udeb' } expected_fields = { 'Architecture' => 'source amd64', 'Binary' => 'libsample0 sample-dev sample-udeb' }
expect(subject[:file_type]).to eq(:changes) expect(subject[:file_type]).to eq(:changes)
expect(subject[:architecture]).to be_nil expect(subject[:architecture]).to be_nil
...@@ -40,7 +40,7 @@ RSpec.describe Packages::Debian::ExtractChangesMetadataService do ...@@ -40,7 +40,7 @@ RSpec.describe Packages::Debian::ExtractChangesMetadataService do
let(:sha256_dsc) { '844f79825b7e8aaa191e514b58a81f9ac1e58e2180134b0c9512fa66d896d7ba 671 sample_1.2.3~alpha2.dsc' } let(:sha256_dsc) { '844f79825b7e8aaa191e514b58a81f9ac1e58e2180134b0c9512fa66d896d7ba 671 sample_1.2.3~alpha2.dsc' }
let(:sha256_source) { 'b5a599e88e7cbdda3bde808160a21ba1dd1ec76b2ec8d4912aae769648d68362 864 sample_1.2.3~alpha2.tar.xz' } let(:sha256_source) { 'b5a599e88e7cbdda3bde808160a21ba1dd1ec76b2ec8d4912aae769648d68362 864 sample_1.2.3~alpha2.tar.xz' }
let(:sha256s) { "#{sha256_dsc}\n#{sha256_source}" } let(:sha256s) { "#{sha256_dsc}\n#{sha256_source}" }
let(:fields) { { Files: md5s, 'Checksums-Sha1': sha1s, 'Checksums-Sha256': sha256s } } let(:fields) { { 'Files' => md5s, 'Checksums-Sha1' => sha1s, 'Checksums-Sha256' => sha256s } }
let(:metadata) { { file_type: :changes, architecture: 'amd64', fields: fields } } let(:metadata) { { file_type: :changes, architecture: 'amd64', fields: fields } }
before do before do
......
...@@ -10,17 +10,17 @@ RSpec.describe Packages::Debian::ExtractDebMetadataService do ...@@ -10,17 +10,17 @@ RSpec.describe Packages::Debian::ExtractDebMetadataService do
context 'with correct file' do context 'with correct file' do
it 'return as expected' do it 'return as expected' do
expected = { expected = {
'Package': 'libsample0', 'Package' => 'libsample0',
'Source': 'sample', 'Source' => 'sample',
'Version': '1.2.3~alpha2', 'Version' => '1.2.3~alpha2',
'Architecture': 'amd64', 'Architecture' => 'amd64',
'Maintainer': 'John Doe <john.doe@example.com>', 'Maintainer' => 'John Doe <john.doe@example.com>',
'Installed-Size': '7', 'Installed-Size' => '7',
'Section': 'libs', 'Section' => 'libs',
'Priority': 'optional', 'Priority' => 'optional',
'Multi-Arch': 'same', 'Multi-Arch' => 'same',
'Homepage': 'https://gitlab.com/', 'Homepage' => 'https://gitlab.com/',
'Description': "Some mostly empty lib\nUsed in GitLab tests.\n\nTesting another paragraph." 'Description' => "Some mostly empty lib\nUsed in GitLab tests.\n\nTesting another paragraph."
} }
expect(subject.execute).to eq expected expect(subject.execute).to eq expected
......
...@@ -33,11 +33,11 @@ RSpec.describe Packages::Debian::ExtractMetadataService do ...@@ -33,11 +33,11 @@ RSpec.describe Packages::Debian::ExtractMetadataService do
where(:case_name, :trait, :expected_file_type, :expected_architecture, :expected_fields) do where(:case_name, :trait, :expected_file_type, :expected_architecture, :expected_fields) do
'with invalid' | :invalid | :unknown | nil | nil 'with invalid' | :invalid | :unknown | nil | nil
'with source' | :source | :source | nil | nil 'with source' | :source | :source | nil | nil
'with dsc' | :dsc | :dsc | nil | { 'Binary': 'sample-dev, libsample0, sample-udeb' } 'with dsc' | :dsc | :dsc | nil | { 'Binary' => 'sample-dev, libsample0, sample-udeb' }
'with deb' | :deb | :deb | 'amd64' | { 'Multi-Arch': 'same' } 'with deb' | :deb | :deb | 'amd64' | { 'Multi-Arch' => 'same' }
'with udeb' | :udeb | :udeb | 'amd64' | { 'Package': 'sample-udeb' } 'with udeb' | :udeb | :udeb | 'amd64' | { 'Package' => 'sample-udeb' }
'with buildinfo' | :buildinfo | :buildinfo | nil | { 'Architecture': 'amd64 source', 'Build-Architecture': 'amd64' } '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 changes' | :changes | :changes | nil | { 'Architecture' => 'source amd64', 'Binary' => 'libsample0 sample-dev sample-udeb' }
end end
with_them do with_them do
......
...@@ -27,17 +27,17 @@ RSpec.describe Packages::Debian::ParseDebian822Service do ...@@ -27,17 +27,17 @@ RSpec.describe Packages::Debian::ParseDebian822Service do
it 'return as expected, preserving order' do it 'return as expected, preserving order' do
expected = { expected = {
'Package: libsample0' => { 'Package: libsample0' => {
'Package': 'libsample0', 'Package' => 'libsample0',
'Source': 'sample', 'Source' => 'sample',
'Version': '1.2.3~alpha2', 'Version' => '1.2.3~alpha2',
'Architecture': 'amd64', 'Architecture' => 'amd64',
'Maintainer': 'John Doe <john.doe@example.com>', 'Maintainer' => 'John Doe <john.doe@example.com>',
'Installed-Size': '9', 'Installed-Size' => '9',
'Section': 'libs', 'Section' => 'libs',
'Priority': 'optional', 'Priority' => 'optional',
'Multi-Arch': 'same', 'Multi-Arch' => 'same',
'Homepage': 'https://gitlab.com/', 'Homepage' => 'https://gitlab.com/',
'Description': "Some mostly empty lib\nUsed in GitLab tests.\n\nTesting another paragraph." 'Description' => "Some mostly empty lib\nUsed in GitLab tests.\n\nTesting another paragraph."
} }
} }
...@@ -51,38 +51,38 @@ RSpec.describe Packages::Debian::ParseDebian822Service do ...@@ -51,38 +51,38 @@ RSpec.describe Packages::Debian::ParseDebian822Service do
it 'return as expected, preserving order' do it 'return as expected, preserving order' do
expected = { expected = {
'Source: sample' => { 'Source: sample' => {
'Source': 'sample', 'Source' => 'sample',
'Priority': 'optional', 'Priority' => 'optional',
'Maintainer': 'John Doe <john.doe@example.com>', 'Maintainer' => 'John Doe <john.doe@example.com>',
'Build-Depends': 'debhelper-compat (= 13)', 'Build-Depends' => 'debhelper-compat (= 13)',
'Standards-Version': '4.5.0', 'Standards-Version' => '4.5.0',
'Section': 'libs', 'Section' => 'libs',
'Homepage': 'https://gitlab.com/', 'Homepage' => 'https://gitlab.com/',
# 'Vcs-Browser': 'https://salsa.debian.org/debian/sample-1.2.3', # 'Vcs-Browser' => 'https://salsa.debian.org/debian/sample-1.2.3',
# '#Vcs-Git': 'https://salsa.debian.org/debian/sample-1.2.3.git', # '#Vcs-Git' => 'https://salsa.debian.org/debian/sample-1.2.3.git',
'Rules-Requires-Root': 'no' 'Rules-Requires-Root' => 'no'
}, },
'Package: sample-dev' => { 'Package: sample-dev' => {
'Package': 'sample-dev', 'Package' => 'sample-dev',
'Section': 'libdevel', 'Section' => 'libdevel',
'Architecture': 'any', 'Architecture' => 'any',
'Multi-Arch': 'same', 'Multi-Arch' => 'same',
'Depends': 'libsample0 (= ${binary:Version}), ${misc:Depends}', 'Depends' => 'libsample0 (= ${binary:Version}), ${misc:Depends}',
'Description': "Some mostly empty developpement files\nUsed in GitLab tests.\n\nTesting another paragraph." 'Description' => "Some mostly empty developpement files\nUsed in GitLab tests.\n\nTesting another paragraph."
}, },
'Package: libsample0' => { 'Package: libsample0' => {
'Package': 'libsample0', 'Package' => 'libsample0',
'Architecture': 'any', 'Architecture' => 'any',
'Multi-Arch': 'same', 'Multi-Arch' => 'same',
'Depends': '${shlibs:Depends}, ${misc:Depends}', 'Depends' => '${shlibs:Depends}, ${misc:Depends}',
'Description': "Some mostly empty lib\nUsed in GitLab tests.\n\nTesting another paragraph." 'Description' => "Some mostly empty lib\nUsed in GitLab tests.\n\nTesting another paragraph."
}, },
'Package: sample-udeb' => { 'Package: sample-udeb' => {
'Package': 'sample-udeb', 'Package' => 'sample-udeb',
'Package-Type': 'udeb', 'Package-Type' => 'udeb',
'Architecture': 'any', 'Architecture' => 'any',
'Depends': 'installed-base', 'Depends' => 'installed-base',
'Description': 'Some mostly empty udeb' 'Description' => 'Some mostly empty udeb'
} }
} }
......
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