debian-mirror-gitlab/spec/models/packages/debian/file_entry_spec.rb

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

106 lines
3 KiB
Ruby
Raw Normal View History

2021-04-29 21:17:54 +05:30
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe Packages::Debian::FileEntry, type: :model do
let_it_be(:package_file) { create(:debian_package_file, :dsc) }
let(:filename) { 'sample_1.2.3~alpha2.dsc' }
let(:size) { 671 }
2021-09-04 01:27:46 +05:30
let(:md5sum) { package_file.file_md5 }
2021-04-29 21:17:54 +05:30
let(:section) { 'libs' }
let(:priority) { 'optional' }
2021-09-04 01:27:46 +05:30
let(:sha1sum) { package_file.file_sha1 }
let(:sha256sum) { package_file.file_sha256 }
2021-04-29 21:17:54 +05:30
let(:file_entry) do
described_class.new(
filename: filename,
size: size,
md5sum: md5sum,
section: section,
priority: priority,
sha1sum: sha1sum,
sha256sum: sha256sum,
package_file: package_file
)
end
subject { file_entry }
describe 'validations' do
it { is_expected.to be_valid }
2022-08-13 15:12:31 +05:30
context 'with FIPS mode', :fips_mode do
it 'raises an error' do
expect { subject.validate! }
.to raise_error(::Packages::FIPS::DisabledError, 'Debian registry is not FIPS compliant')
end
end
2021-04-29 21:17:54 +05:30
describe '#filename' do
it { is_expected.to validate_presence_of(:filename) }
it { is_expected.not_to allow_value('Hé').for(:filename) }
end
describe '#size' do
it { is_expected.to validate_presence_of(:size) }
end
describe '#md5sum' do
it { is_expected.to validate_presence_of(:md5sum) }
2021-09-04 01:27:46 +05:30
it { is_expected.not_to allow_value('12345678901234567890123456789012').for(:md5sum).with_message("mismatch for sample_1.2.3~alpha2.dsc: #{package_file.file_md5} != 12345678901234567890123456789012") }
2021-04-29 21:17:54 +05:30
end
describe '#section' do
it { is_expected.to validate_presence_of(:section) }
end
describe '#priority' do
it { is_expected.to validate_presence_of(:priority) }
end
describe '#sha1sum' do
it { is_expected.to validate_presence_of(:sha1sum) }
2021-09-04 01:27:46 +05:30
it { is_expected.not_to allow_value('1234567890123456789012345678901234567890').for(:sha1sum).with_message("mismatch for sample_1.2.3~alpha2.dsc: #{package_file.file_sha1} != 1234567890123456789012345678901234567890") }
2021-04-29 21:17:54 +05:30
end
describe '#sha256sum' do
it { is_expected.to validate_presence_of(:sha256sum) }
2021-09-04 01:27:46 +05:30
it { is_expected.not_to allow_value('1234567890123456789012345678901234567890123456789012345678901234').for(:sha256sum).with_message("mismatch for sample_1.2.3~alpha2.dsc: #{package_file.file_sha256} != 1234567890123456789012345678901234567890123456789012345678901234") }
2021-04-29 21:17:54 +05:30
end
describe '#package_file' do
it { is_expected.to validate_presence_of(:package_file) }
end
end
describe '#component' do
subject { file_entry.component }
context 'without section' do
let(:section) { nil }
it { is_expected.to eq 'main' }
end
context 'with empty section' do
let(:section) { '' }
it { is_expected.to eq 'main' }
end
context 'with ruby section' do
let(:section) { 'ruby' }
it { is_expected.to eq 'main' }
end
context 'with contrib/ruby section' do
let(:section) { 'contrib/ruby' }
it { is_expected.to eq 'contrib' }
end
end
end