summaryrefslogtreecommitdiff
path: root/spec/models/packages/debian/file_entry_spec.rb
blob: ed6372f2873dc58633bcd100d115b0f3200420c4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
# 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 }
  let(:md5sum) { package_file.file_md5 }
  let(:section) { 'libs' }
  let(:priority) { 'optional' }
  let(:sha1sum) { package_file.file_sha1 }
  let(:sha256sum) { package_file.file_sha256 }

  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 }

    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

    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) }
      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") }
    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) }
      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") }
    end

    describe '#sha256sum' do
      it { is_expected.to validate_presence_of(:sha256sum) }
      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") }
    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