diff --git a/lib/onelogin/ruby-saml/utils.rb b/lib/onelogin/ruby-saml/utils.rb index 7fa8805db..78422d9b8 100644 --- a/lib/onelogin/ruby-saml/utils.rb +++ b/lib/onelogin/ruby-saml/utils.rb @@ -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 = [] diff --git a/test/certificates/certificate.der b/test/certificates/certificate.der new file mode 100644 index 000000000..756d248e2 Binary files /dev/null and b/test/certificates/certificate.der differ diff --git a/test/utils_test.rb b/test/utils_test.rb index 18252fa49..b1ccf972d 100644 --- a/test/utils_test.rb +++ b/test/utils_test.rb @@ -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)