Skip to content

Commit

Permalink
Merge pull request #434 from id4ho/jw-update-certificate-formatter
Browse files Browse the repository at this point in the history
Allow formatting of certificates that contain \r
  • Loading branch information
pitbulk authored Mar 21, 2019
2 parents 325a444 + 508816f commit 5d49768
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/onelogin/ruby-saml/utils.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class Utils
#
def self.format_cert(cert)
# don't try to format an encoded certificate or if is empty or nil
return cert if cert.nil? || cert.empty? || cert.match(/\x0d/)
return cert if cert.nil? || cert.empty? || !cert.ascii_only?

if cert.scan(/BEGIN CERTIFICATE/).length > 1
formatted_cert = []
Expand Down
Binary file added test/certificates/certificate.der
Binary file not shown.
5 changes: 5 additions & 0 deletions test/utils_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ class UtilsTest < Minitest::Test
assert_equal formatted_certificate, OneLogin::RubySaml::Utils.format_cert(invalid_certificate2)
end

it "returns the cert when it's encoded" do
encoded_certificate = read_certificate("certificate.der")
assert_equal encoded_certificate, OneLogin::RubySaml::Utils.format_cert(encoded_certificate)
end

it "reformats the certificate when there line breaks and no headers" do
invalid_certificate3 = read_certificate("invalid_certificate3")
assert_equal formatted_certificate, OneLogin::RubySaml::Utils.format_cert(invalid_certificate3)
Expand Down

0 comments on commit 5d49768

Please sign in to comment.