Commit a2c76e5
Changed files (2)
lib
saml
kit
spec
saml
lib/saml/kit/signature.rb
@@ -17,7 +17,7 @@ module Saml
# Returns the embedded X509 Certificate
def certificate
- value = to_h.fetch('KeyInfo', {}).fetch('X509Data', {}).fetch('X509Certificate', nil)
+ value = at_xpath('./ds:KeyInfo/ds:X509Data/ds:X509Certificate').try(:text)
return if value.nil?
::Xml::Kit::Certificate.new(value, use: :signing)
end
@@ -90,6 +90,7 @@ module Saml
end
def at_xpath(xpath)
+ return nil unless node
node.at_xpath(xpath, Saml::Kit::Document::NAMESPACES)
end
end
spec/saml/signature_spec.rb
@@ -14,6 +14,10 @@ RSpec.describe Saml::Kit::Signature do
specify { expect(subject.signature_method).to eql(xml_hash['Signature']['SignedInfo']['SignatureMethod']['Algorithm']) }
specify { expect(subject.canonicalization_method).to eql(xml_hash['Signature']['SignedInfo']['CanonicalizationMethod']['Algorithm']) }
specify { expect(subject.transforms).to eql(xml_hash['Signature']['SignedInfo']['Reference']['Transforms']['Transform'].map { |x| x['Algorithm'] }) }
+ specify do
+ expected = ::Xml::Kit::Certificate.new(xml_hash['Signature']['KeyInfo']['X509Data']['X509Certificate'], use: :signing)
+ expect(subject.certificate).to eql(expected)
+ end
describe "#valid?" do
it 'returns true when the signature is valid' do