Sha256: f413ba461a61692db892dfb74ff7700c886e6498c2177fbe0dc59e238ac3a18e

Contents?: true

Size: 1.76 KB

Versions: 3

Compression:

Stored size: 1.76 KB

Contents

require 'pact_broker/certificates/service'

module PactBroker
  module Certificates
    describe Service do
      let(:certificate_content) { File.read('spec/fixtures/certificate.pem') }

      describe "#cert_store" do
        subject { Service.cert_store }

        it "returns an OpenSSL::X509::Store" do
          expect(subject).to be_instance_of(OpenSSL::X509::Store)
        end

        context "when there is a duplicate certificate" do
          before do
            Certificate.create(uuid: '1234', content: certificate_content)
            Certificate.create(uuid: '5678', content: certificate_content)
          end

          it "logs the error" do
            expect(PactBroker.logger).to receive(:error).with(/Error adding certificate/).at_least(1).times
            subject
          end

          it "returns an OpenSSL::X509::Store" do
            expect(subject).to be_instance_of(OpenSSL::X509::Store)
          end
        end
      end

      describe "#find_all_certificates" do
        let!(:certificate) do
          Certificate.create(uuid: '1234', content: certificate_content)
        end

        subject { Service.find_all_certificates }

        context "with a valid certificate file" do
          it "returns all the X509 Certificate objects" do
            expect(subject.size).to eq 2
          end
        end

        context "with an invalid certificate file" do
          let(:certificate_content) { File.read('spec/fixtures/certificate-invalid.pem') }

          it "logs an error" do
            expect(PactBroker.logger).to receive(:error).with(/Error.*1234/)
            subject
          end

          it "returns all the valid X509 Certificate objects" do
            expect(subject.size).to eq 1
          end
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
pact_broker-2.14.0 spec/lib/pact_broker/certificates/service_spec.rb
pact_broker-2.13.1 spec/lib/pact_broker/certificates/service_spec.rb
pact_broker-2.13.0 spec/lib/pact_broker/certificates/service_spec.rb