Skip to content

Commit

Permalink
Added an explicit validation error when the X509Certificate is missin…
Browse files Browse the repository at this point in the history
…g from the SAML Reponse
  • Loading branch information
Merlyn Albery-Speyer committed Feb 11, 2013
1 parent 5cbac3d commit 35e4c00
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/xml_security.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ def initialize(response)
def validate(idp_cert_fingerprint, soft = true)
# get cert from response
cert_element = REXML::XPath.first(self, "//ds:X509Certificate", { "ds"=>DSIG })
raise Onelogin::Saml::ValidationError.new("Certificate element missing in response (ds:X509Certificate)") unless cert_element
base64_cert = cert_element.text
cert_text = Base64.decode64(base64_cert)
cert = OpenSSL::X509::Certificate.new(cert_text)
Expand Down
10 changes: 10 additions & 0 deletions test/xml_security_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,16 @@ class XmlSecurityTest < Test::Unit::TestCase
end
assert_equal("Key validation error", exception.message)
end

should "raise validation error when the X509Certificate is missing" do
response = Base64.decode64(response_document)
response.sub!(/<ds:X509Certificate>.*<\/ds:X509Certificate>/, "")
document = XMLSecurity::SignedDocument.new(response)
exception = assert_raise(Onelogin::Saml::ValidationError) do
document.validate("a fingerprint", false) # The fingerprint isn't relevant to this test
end
assert_equal("Certificate element missing in response (ds:X509Certificate)", exception.message)
end
end

context "Algorithms" do
Expand Down

0 comments on commit 35e4c00

Please sign in to comment.