summaryrefslogtreecommitdiff
path: root/spec/support/shared_examples/models/packages/debian/distribution_key_shared_examples.rb
blob: 26794c837362b045f62e20e923415669fc6582f5 (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
# frozen_string_literal: true

require 'spec_helper'

RSpec.shared_examples 'Debian Distribution Key' do |container|
  let_it_be_with_refind(:distribution_key) { create("debian_#{container}_distribution_key") } # rubocop:disable Rails/SaveBang

  subject { distribution_key }

  describe 'relationships' do
    it { is_expected.to belong_to(:distribution).class_name("Packages::Debian::#{container.capitalize}Distribution").inverse_of(:key) }
  end

  describe 'validations' do
    describe "#distribution" do
      it { is_expected.to validate_presence_of(:distribution) }
    end

    describe '#private_key' do
      it { is_expected.to validate_presence_of(:private_key) }

      it { is_expected.to allow_value("-----BEGIN PGP PRIVATE KEY BLOCK-----\n...").for(:private_key) }
      it { is_expected.not_to allow_value('A').for(:private_key).with_message('must be ASCII armored') }
    end

    describe '#passphrase' do
      it { is_expected.to validate_presence_of(:passphrase) }

      it { is_expected.to allow_value('P@$$w0rd').for(:passphrase) }
      it { is_expected.to allow_value('A' * 255).for(:passphrase) }
      it { is_expected.not_to allow_value('A' * 256).for(:passphrase) }
    end

    describe '#public_key' do
      it { is_expected.to validate_presence_of(:public_key) }

      it { is_expected.to allow_value("-----BEGIN PGP PUBLIC KEY BLOCK-----\n...").for(:public_key) }
      it { is_expected.not_to allow_value('A').for(:public_key).with_message('must be ASCII armored') }
    end

    describe '#fingerprint' do
      it { is_expected.to validate_presence_of(:passphrase) }

      it { is_expected.to allow_value('abc').for(:passphrase) }
      it { is_expected.to allow_value('A' * 255).for(:passphrase) }
      it { is_expected.not_to allow_value('A' * 256).for(:passphrase) }
    end
  end
end