Commit e393cc8

mo <mo@mokhan.ca>
2018-10-22 16:09:34
forward accessors to memoized assertion
1 parent 0ced388
Changed files (3)
lib
saml
spec
saml
kit
lib/saml/kit/builders/response.rb
@@ -7,11 +7,8 @@ module Saml
       # {include:file:spec/saml/kit/builders/response_spec.rb}
       class Response
         include XmlTemplatable
-        attr_reader :user, :request
-        attr_accessor :id, :now
-        attr_accessor :version, :status_code, :status_message
-        attr_accessor :issuer, :destination
-        attr_reader :configuration
+        attr_reader :user, :request, :issuer, :destination, :now, :configuration
+        attr_accessor :id, :version, :status_code, :status_message
 
         def initialize(
           user, request = nil, configuration: Saml::Kit.configuration
@@ -60,6 +57,21 @@ module Saml
           assertion.destination = value
         end
 
+        def issuer=(value)
+          @issuer = value
+          assertion.issuer = value
+        end
+
+        def now=(value)
+          @now = value
+          assertion.now = value
+        end
+
+        def embed_signature=(value)
+          @embed_signature = value
+          assertion.embed_signature = value
+        end
+
         private
 
         def response_options
lib/saml/kit/version.rb
@@ -2,6 +2,6 @@
 
 module Saml
   module Kit
-    VERSION = '1.0.25'.freeze
+    VERSION = '1.0.26'.freeze
   end
 end
spec/saml/kit/builders/response_spec.rb
@@ -226,5 +226,28 @@ RSpec.describe Saml::Kit::Builders::Response do
       result = subject.build
       expect(result.assertion.at_xpath('/samlp:Response/saml:Assertion/saml:Subject/saml:SubjectConfirmation/saml:SubjectConfirmationData').attribute('Recipient').value).to eql(acs_url)
     end
+
+    it 'uses the updated issuer on the assertion' do
+      issuer = FFaker::Internet.uri('https')
+      subject.assertion # force memoization the assertion
+      subject.issuer = issuer
+      result = subject.build
+      expect(result.assertion.issuer).to eql(issuer)
+    end
+
+    it 'uses the `now` on the assertion' do
+      now = 5.minutes.from_now
+      subject.assertion # force memoization the assertion
+      subject.now = now
+      result = subject.build
+      expect(result.assertion.started_at.to_i).to eql(now.to_i)
+    end
+
+    it 'does not embed the signature' do
+      subject.assertion # force memoization the assertion
+      subject.embed_signature = false
+      result = subject.build
+      expect(result.assertion).not_to be_signed
+    end
   end
 end