Commit 3496a83

mo <mo@mokhan.ca>
2018-12-04 19:19:55
return array of values if more then one value for an attribute.
1 parent 283dd55
Changed files (3)
lib/saml/kit/attribute_statement.rb
@@ -15,8 +15,12 @@ module Saml
       def attributes
         @attributes ||= search('./saml:Attribute').inject({}) do |memo, item|
           namespace = Saml::Kit::Document::NAMESPACES
-          attribute = item.at_xpath('./saml:AttributeValue', namespace)
-          memo[item.attribute('Name').value] = attribute.try(:text)
+          values = item.search('./saml:AttributeValue', namespace)
+          if values.length == 1
+            memo[item.attribute('Name').value] = values[0].try(:text)
+          else
+            memo[item.attribute('Name').value] = values.map { |x| x.try(:text) }
+          end
           memo
         end.with_indifferent_access
       end
spec/saml/kit/builders/metadata_spec.rb
@@ -74,4 +74,21 @@ RSpec.describe Saml::Kit::Builders::Metadata do
       expect(metadata).to be_valid
     end
   end
+
+  specify do
+    configuration = Saml::Kit::Configuration.new do |config|
+      config.entity_id = "https://www.example.org/metadata"
+      config.generate_key_pair_for(use: :signing)
+      config.generate_key_pair_for(use: :encryption)
+    end
+    metadata = Saml::Kit::Metadata.build(configuration: configuration) do |x|
+      x.organization_name = "Acme"
+      x.contact_email = "acme@example.org"
+      x.organization_url = "https://www.example.org"
+      x.build_service_provider do |_|
+        _.add_assertion_consumer_service('https://www.example.org/assertions', binding: :http_post)
+      end
+    end
+    puts metadata.to_xml(pretty: true)
+  end
 end
spec/saml/kit/response_spec.rb
@@ -567,6 +567,12 @@ RSpec.describe Saml::Kit::Response do
       expect(subject.status_code).to eql(Saml::Kit::Namespaces::REQUESTER_ERROR)
       expect(subject.status_message).to eql(message)
     end
+
+    it 'parses an array of attributes' do
+      attributes[:roles] = [:admin, :user]
+      subject = described_class.build(user, request)
+      expect(subject.attributes[:roles]).to match_array(['admin', 'user'])
+    end
   end
 
   describe '#build' do