Commit 1422d48

mo <mo.khan@gmail.com>
2017-11-01 21:27:02
parse name id formats from SP metadata.
1 parent 04c9b1e
lib/saml/kit/service_provider_metadata.rb
@@ -5,9 +5,14 @@ module Saml
         super("SPSSODescriptor", xml)
       end
 
+      def name_id_formats
+        find_all("/md:EntityDescriptor/md:SPSSODescriptor/md:NameIDFormat").map do |item|
+          item.text
+        end
+      end
+
       def assertion_consumer_services
-        xpath = "/md:EntityDescriptor/md:SPSSODescriptor/md:AssertionConsumerService"
-        find_all(xpath).map do |item|
+        find_all("/md:EntityDescriptor/md:SPSSODescriptor/md:AssertionConsumerService").map do |item|
           {
             binding: item.attribute("Binding").value,
             location: item.attribute("Location").value,
spec/saml/service_provider_metadata_spec.rb
@@ -81,5 +81,11 @@ RSpec.describe Saml::Kit::ServiceProviderMetadata do
         { location: logout_redirect_url, binding: Saml::Kit::Namespaces::Bindings::HTTP_REDIRECT },
       ])
     end
+
+    it 'returns each of the nameid formats' do
+      expect(subject.name_id_formats).to match_array([
+        Saml::Kit::Namespaces::Formats::NameId::PERSISTENT
+      ])
+    end
   end
 end