Skip to content

Commit

Permalink
feat(ssl): allow single certificates to be uploaded
Browse files Browse the repository at this point in the history
Fixes #194
  • Loading branch information
mefellows committed Feb 21, 2018
1 parent d189c93 commit 9417f10
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/pact_broker/certificates/service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
11 changes: 10 additions & 1 deletion spec/lib/pact_broker/certificates/service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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') }

Expand Down

0 comments on commit 9417f10

Please sign in to comment.