Skip to content

Commit

Permalink
Merge pull request SAML-Toolkits#39 from drywheattoast/error_on_multi…
Browse files Browse the repository at this point in the history
…ple_validations

Fixes bug with SignedDocument#validate_doc
  • Loading branch information
christianbpedersen committed Sep 17, 2012
2 parents 8d69f7a + e252342 commit 0df0438
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
10 changes: 6 additions & 4 deletions lib/xml_security.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ module XMLSecurity
class SignedDocument < REXML::Document
DSIG = "http://www.w3.org/2000/09/xmldsig#"

attr_accessor :signed_element_id
attr_accessor :signed_element_id, :sig_element

def initialize(response)
super(response)
Expand Down Expand Up @@ -73,9 +73,11 @@ def validate_doc(base64_cert, soft = true)
inclusive_namespaces = prefix_list.split(" ")
end

# remove signature node
sig_element = REXML::XPath.first(self, "//ds:Signature", {"ds"=>DSIG})
sig_element.remove
# store and remove signature node
self.sig_element ||= begin
element = REXML::XPath.first(self, "//ds:Signature", {"ds"=>DSIG})
element.remove
end

# check digests
REXML::XPath.each(sig_element, "//ds:Reference", {"ds"=>DSIG}) do |ref|
Expand Down
6 changes: 6 additions & 0 deletions test/xml_security_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@ class XmlSecurityTest < Test::Unit::TestCase
@document.validate_doc(@base64cert, false)
end
end

should "not raise an error when softly validating the document multiple times" do
assert_nothing_raised do
2.times { @document.validate_doc(@base64cert, true) }
end
end

should "should raise Fingerprint mismatch" do
exception = assert_raise(Onelogin::Saml::ValidationError) do
Expand Down

0 comments on commit 0df0438

Please sign in to comment.