Commit 97f541e
Changed files (2)
lib
saml
kit
spec
saml
lib/saml/kit/signature.rb
@@ -15,20 +15,15 @@ module Saml
@xml_hash = item
else
@node = item
+ @xml_hash = @node ? Hash.from_xml(@node.to_s)["Signature"] : {}
end
end
# Returns the embedded X509 Certificate
def certificate
- if @xml_hash
- value = to_h.fetch('KeyInfo', {}).fetch('X509Data', {}).fetch('X509Certificate', nil)
- return if value.nil?
- ::Xml::Kit::Certificate.new(value, use: :signing)
- else
- return if @node.nil?
- item = @node.at_xpath("//ds:KeyInfo/ds:X509Data/ds:X509Certificate", "ds": ::Xml::Kit::Namespaces::XMLDSIG)
- ::Xml::Kit::Certificate.new(item.text, use: :signing)
- end
+ value = to_h.fetch('KeyInfo', {}).fetch('X509Data', {}).fetch('X509Certificate', nil)
+ return if value.nil?
+ ::Xml::Kit::Certificate.new(value, use: :signing)
end
# Returns true when the fingerprint of the certificate matches one of the certificates registered in the metadata.
spec/saml/signature_spec.rb
@@ -60,5 +60,12 @@ RSpec.describe Saml::Kit::Signature do
end
end
end
+
+ describe "#to_h" do
+ it 'returns a hash representation of the signature' do
+ expected = Hash.from_xml(signed_document.to_s)['AuthnRequest']['Signature']
+ expect(subject.to_h).to eql(expected)
+ end
+ end
end
end