Welcome to mirror list, hosted at ThFree Co, Russian Federation.

x509_issuer_crl_check_worker_spec.rb « workers « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 5564147d274e5c5bfa66b9803aea51281e4331fb (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
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe X509IssuerCrlCheckWorker do
  subject(:worker) { described_class.new }

  let(:project) { create(:project, :public, :repository) }
  let(:x509_signed_commit) { project.commit_by(oid: '189a6c924013fc3fe40d6f1ec1dc20214183bc97') }
  let(:revoked_x509_signed_commit) { project.commit_by(oid: 'ed775cc81e5477df30c2abba7b6fdbb5d0baadae') }

  describe '#perform' do
    context 'valid crl' do
      before do
        stub_request(:get, "http://ch.siemens.com/pki?ZZZZZZA6.crl")
          .to_return(status: 200, body: File.read('spec/fixtures/x509/ZZZZZZA6.crl'), headers: {})
      end

      it 'changes certificate status for revoked certificates' do
        revoked_x509_commit = Gitlab::X509::Commit.new(revoked_x509_signed_commit)
        x509_commit = Gitlab::X509::Commit.new(x509_signed_commit)
        issuer = revoked_x509_commit.signature.x509_certificate.x509_issuer

        expect(issuer).to eq(x509_commit.signature.x509_certificate.x509_issuer)
        expect(revoked_x509_commit.signature.x509_certificate.good?).to be_truthy
        expect(x509_commit.signature.x509_certificate.good?).to be_truthy

        worker.perform
        revoked_x509_commit.signature.reload

        expect(revoked_x509_commit.signature.x509_certificate.revoked?).to be_truthy
        expect(x509_commit.signature.x509_certificate.revoked?).to be_falsey
      end
    end

    context 'invalid crl' do
      before do
        stub_request(:get, "http://ch.siemens.com/pki?ZZZZZZA6.crl")
          .to_return(status: 200, body: "trash", headers: {})
      end

      it 'does not change certificate status' do
        revoked_x509_commit = Gitlab::X509::Commit.new(revoked_x509_signed_commit)

        expect(revoked_x509_commit.signature.x509_certificate.good?).to be_truthy

        worker.perform
        revoked_x509_commit.signature.reload

        expect(revoked_x509_commit.signature.x509_certificate.revoked?).to be_falsey
      end
    end

    context 'not found crl' do
      before do
        stub_request(:get, "http://ch.siemens.com/pki?ZZZZZZA6.crl")
          .to_return(status: 404, body: "not found", headers: {})
      end

      it 'does not change certificate status' do
        revoked_x509_commit = Gitlab::X509::Commit.new(revoked_x509_signed_commit)

        expect(revoked_x509_commit.signature.x509_certificate.good?).to be_truthy

        worker.perform
        revoked_x509_commit.signature.reload

        expect(revoked_x509_commit.signature.x509_certificate.revoked?).to be_falsey
      end
    end

    context 'unreachable crl' do
      before do
        stub_request(:get, "http://ch.siemens.com/pki?ZZZZZZA6.crl")
          .to_raise(SocketError.new('Some HTTP error'))
      end

      it 'does not change certificate status' do
        revoked_x509_commit = Gitlab::X509::Commit.new(revoked_x509_signed_commit)

        expect(revoked_x509_commit.signature.x509_certificate.good?).to be_truthy

        worker.perform
        revoked_x509_commit.signature.reload

        expect(revoked_x509_commit.signature.x509_certificate.revoked?).to be_falsey
      end
    end
  end
end