From 9417f1052f47c152fced1aac4d2375b0403f8e5d Mon Sep 17 00:00:00 2001 From: Matt Fellows Date: Wed, 21 Feb 2018 12:07:15 +1100 Subject: [PATCH] feat(ssl): allow single certificates to be uploaded Fixes #194 --- lib/pact_broker/certificates/service.rb | 2 +- spec/lib/pact_broker/certificates/service_spec.rb | 11 ++++++++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/lib/pact_broker/certificates/service.rb b/lib/pact_broker/certificates/service.rb index 34a09679d..8b73937e6 100644 --- a/lib/pact_broker/certificates/service.rb +++ b/lib/pact_broker/certificates/service.rb @@ -25,7 +25,7 @@ def cert_store def find_all_certificates Certificate.collect do | certificate | - cert_arr = certificate.content.split(/(-----END [^\-]+-----)/).each_slice(2).map(&:join) + cert_arr = certificate.content.split(/(-----END [^\-]+-----)/).each_slice(2).map(&:join).map(&:strip).select{|s| !s.empty?} cert_arr.collect do |c| begin OpenSSL::X509::Certificate.new(c) diff --git a/spec/lib/pact_broker/certificates/service_spec.rb b/spec/lib/pact_broker/certificates/service_spec.rb index 542224038..fa866e036 100644 --- a/spec/lib/pact_broker/certificates/service_spec.rb +++ b/spec/lib/pact_broker/certificates/service_spec.rb @@ -36,12 +36,21 @@ module Certificates subject { Service.find_all_certificates } - context "with a valid certificate file" do + context "with a valid certificate chain" do it "returns all the X509 Certificate objects" do expect(subject.size).to eq 2 end end + context "with a valid CA file" do + let(:certificate_content) { File.read('spec/fixtures/certificates/cacert.pem') } + + it "returns all the X509 Certificate objects" do + expect(PactBroker.logger).to_not receive(:error).with(/Error.*1234/) + expect(subject.size).to eq 1 + end + end + context "with an invalid certificate file" do let(:certificate_content) { File.read('spec/fixtures/certificate-invalid.pem') }