Skip to content

Commit 9417f10

Browse files
committed
feat(ssl): allow single certificates to be uploaded
Fixes pact-foundation#194
1 parent d189c93 commit 9417f10

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

lib/pact_broker/certificates/service.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ def cert_store
2525

2626
def find_all_certificates
2727
Certificate.collect do | certificate |
28-
cert_arr = certificate.content.split(/(-----END [^\-]+-----)/).each_slice(2).map(&:join)
28+
cert_arr = certificate.content.split(/(-----END [^\-]+-----)/).each_slice(2).map(&:join).map(&:strip).select{|s| !s.empty?}
2929
cert_arr.collect do |c|
3030
begin
3131
OpenSSL::X509::Certificate.new(c)

spec/lib/pact_broker/certificates/service_spec.rb

+10-1
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,21 @@ module Certificates
3636

3737
subject { Service.find_all_certificates }
3838

39-
context "with a valid certificate file" do
39+
context "with a valid certificate chain" do
4040
it "returns all the X509 Certificate objects" do
4141
expect(subject.size).to eq 2
4242
end
4343
end
4444

45+
context "with a valid CA file" do
46+
let(:certificate_content) { File.read('spec/fixtures/certificates/cacert.pem') }
47+
48+
it "returns all the X509 Certificate objects" do
49+
expect(PactBroker.logger).to_not receive(:error).with(/Error.*1234/)
50+
expect(subject.size).to eq 1
51+
end
52+
end
53+
4554
context "with an invalid certificate file" do
4655
let(:certificate_content) { File.read('spec/fixtures/certificate-invalid.pem') }
4756

0 commit comments

Comments
 (0)