Commit 653f74d

mo <mo.khan@gmail.com>
2018-03-03 19:41:21
generate response for user without attributes.
1 parent c3f1484
Changed files (3)
lib
saml
kit
spec
lib/saml/kit/builders/assertion.rb
@@ -24,6 +24,7 @@ module Saml
         end
 
         def assertion_attributes
+          return {} unless user.respond_to?(:assertion_attributes_for)
           user.assertion_attributes_for(request)
         end
 
spec/saml/kit/response_spec.rb
@@ -567,5 +567,19 @@ XML
       expect(result).to be_instance_of(described_class)
       expect(result).to be_valid
     end
+
+    it 'can build a response without the need for the user to provide attributes' do
+      configuration = Saml::Kit::Configuration.new do |config|
+        config.entity_id = FFaker::Internet.uri('https')
+      end
+      sp = Saml::Kit::Metadata.build(&:build_service_provider)
+      allow(configuration.registry).to receive(:metadata_for).with(configuration.entity_id).and_return(sp)
+      user = UserWithoutAttributes.new
+
+      result = described_class.build(user, configuration: configuration)
+      expect(result).to be_instance_of(described_class)
+      expect(result).to be_valid
+      expect(result.attributes).to be_empty
+    end
   end
 end
spec/support/user_without_attributes.rb
@@ -0,0 +1,13 @@
+# frozen_string_literal: true
+
+class UserWithoutAttributes
+  attr_accessor :name_id
+
+  def initialize(name_id: SecureRandom.uuid)
+    @name_id = name_id
+  end
+
+  def name_id_for(_format)
+    name_id
+  end
+end