lib/saml/kit/xml.rb in saml-kit-0.2.17 vs lib/saml/kit/xml.rb in saml-kit-0.2.18

- old
+ new

@@ -1,7 +1,8 @@ module Saml module Kit + # {include:file:spec/saml/xml_spec.rb} class Xml # :nodoc: include ActiveModel::Validations NAMESPACES = { "NameFormat": Namespaces::ATTR_SPLAT, "ds": Namespaces::XMLDSIG, @@ -57,27 +58,23 @@ end end end def validate_certificates(now = Time.current) - return unless document.at_xpath('//ds:Signature', Xmldsig::NAMESPACES).present? + return if find_by('//ds:Signature').nil? x509_certificates.each do |certificate| - if now < certificate.not_before - errors.add(:certificate, "Not valid before #{certificate.not_before}") - end + inactive = now < certificate.not_before + errors.add(:certificate, "Not valid before #{certificate.not_before}") if inactive - if now > certificate.not_after - errors.add(:certificate, "Not valid after #{certificate.not_after}") - end + expired = now > certificate.not_after + errors.add(:certificate, "Not valid after #{certificate.not_after}") if expired end end def x509_certificates xpath = "//ds:KeyInfo/ds:X509Data/ds:X509Certificate" - document.search(xpath, Xmldsig::NAMESPACES).map do |item| - Certificate.to_x509(item.text) - end + find_all(xpath).map { |item| Certificate.to_x509(item.text) } end end end end