Skip to content

Commit

Permalink
Fixes bug with SignedDocument#validate_doc
Browse files Browse the repository at this point in the history
calling this method more than once would result in an exception being
thrown because the signature node is removed from the root document in the first
invocation.

this node is being stored in an attr_accessor because subsequent calls to
the #validate_doc method need it to function properly.
  • Loading branch information
sonnysideup-bot committed May 9, 2012
1 parent 9067278 commit e252342
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 e252342

Please sign in to comment.