lib/spid/ruby-saml/utils.rb in spid-es-0.0.19 vs lib/spid/ruby-saml/utils.rb in spid-es-0.0.20
- old
+ new
@@ -181,8 +181,45 @@
end
def self.uuid
RUBY_VERSION < '1.9' ? "_#{@@uuid_generator.generate}" : "_#{SecureRandom.uuid}"
end
+
+
+ # Given two strings, attempt to match them as URIs using Rails' parse method. If they can be parsed,
+ # then the fully-qualified domain name and the host should performa a case-insensitive match, per the
+ # RFC for URIs. If Rails can not parse the string in to URL pieces, return a boolean match of the
+ # two strings. This maintains the previous functionality.
+ # @return [Boolean]
+ def self.uri_match?(destination_url, settings_url)
+ dest_uri = URI.parse(destination_url)
+ acs_uri = URI.parse(settings_url)
+
+ if dest_uri.scheme.nil? || acs_uri.scheme.nil? || dest_uri.host.nil? || acs_uri.host.nil?
+ raise URI::InvalidURIError
+ else
+ dest_uri.scheme.downcase == acs_uri.scheme.downcase &&
+ dest_uri.host.downcase == acs_uri.host.downcase &&
+ dest_uri.path == acs_uri.path &&
+ dest_uri.query == acs_uri.query
+ end
+ rescue URI::InvalidURIError
+ original_uri_match?(destination_url, settings_url)
+ end
+
+ # If Rails' URI.parse can't match to valid URL, default back to the original matching service.
+ # @return [Boolean]
+ def self.original_uri_match?(destination_url, settings_url)
+ destination_url == settings_url
+ end
+
+ # Given a REXML::Element instance, return the concatenation of all child text nodes. Assumes
+ # that there all children other than text nodes can be ignored (e.g. comments). If nil is
+ # passed, nil will be returned.
+ def self.element_text(element)
+ element.texts.map(&:value).join if element
+ end
+
+
end
end
end