Commit b98e775
Changed files (2)
lib
saml
kit
spec
saml
kit
lib/saml/kit/document.rb
@@ -44,12 +44,12 @@ module Saml
# Returns the Destination of the SAML document.
def destination
- root.fetch('Destination', nil)
+ at_xpath('./*/@Destination').try(:value)
end
# Returns the Destination of the SAML document.
def issue_instant
- Time.parse(root['IssueInstant'])
+ Time.parse(at_xpath('./*/@IssueInstant').try(:value))
end
# Returns the SAML document returned as a Hash.
@@ -102,15 +102,12 @@ module Saml
# @param xml [String] the raw xml string.
# @param configuration [Saml::Kit::Configuration] the configuration to use for unpacking the document.
def to_saml_document(xml, configuration: Saml::Kit.configuration)
- xml_document = ::Xml::Kit::Document.new(xml, namespaces: {
- "samlp": ::Saml::Kit::Namespaces::PROTOCOL
- })
constructor = {
'AuthnRequest' => Saml::Kit::AuthenticationRequest,
'LogoutRequest' => Saml::Kit::LogoutRequest,
'LogoutResponse' => Saml::Kit::LogoutResponse,
'Response' => Saml::Kit::Response,
- }[xml_document.find_by(XPATH).name] || InvalidDocument
+ }[Nokogiri::XML(xml).at_xpath(XPATH, "samlp": ::Saml::Kit::Namespaces::PROTOCOL).name] || InvalidDocument
constructor.new(xml, configuration: configuration)
rescue StandardError => error
Saml::Kit.logger.error(error)
spec/saml/kit/document_spec.rb
@@ -3,15 +3,19 @@ RSpec.describe Saml::Kit::Document do
Saml::Kit::AuthenticationRequest.build do |x|
x.id = id
x.issuer = issuer
+ x.destination = destination
end
end
let(:id) { Xml::Kit::Id.generate }
let(:issuer) { FFaker::Internet.uri('https') }
+ let(:destination) { FFaker::Internet.uri('https') }
specify { expect(subject.id).to eql(id) }
specify { expect(subject.issuer).to eql(issuer) }
- specify { expect(subject.version).to eql("2.0") }
+ specify { expect(subject.version).to eql('2.0') }
+ specify { expect(subject.destination).to eql(destination) }
+ specify { expect(subject.issue_instant.to_i).to eql(Time.now.to_i) }
describe '.to_saml_document' do
subject { described_class }