Commit 5c1d8df

mo <mo.khan@gmail.com>
2017-11-26 17:54:52
cache decrypted assertion.
1 parent 7a6e1d6
Changed files (2)
saml-kit
lib
saml
spec
saml-kit/lib/saml/kit/response.rb
@@ -48,13 +48,16 @@ module Saml
       end
 
       def assertion
-        if encrypted?
-          decrypted = Cryptography.new.decrypt(to_h.fetch(name, {}).fetch('EncryptedAssertion', {}))
-          Saml::Kit.logger.debug(decrypted)
-          Hash.from_xml(decrypted)['Assertion']
-        else
-          to_h.fetch(name, {}).fetch('Assertion', {})
-        end
+        @assertion =
+          begin
+            if encrypted?
+              decrypted = Cryptography.new.decrypt(to_h.fetch(name, {}).fetch('EncryptedAssertion', {}))
+              Saml::Kit.logger.debug(decrypted)
+              Hash.from_xml(decrypted)['Assertion']
+            else
+              to_h.fetch(name, {}).fetch('Assertion', {})
+            end
+          end
       end
 
       def signed?
saml-kit/spec/saml/response_spec.rb
@@ -412,6 +412,10 @@ RSpec.describe Saml::Kit::Response do
       Saml::Kit.configuration.stripped_encryption_certificate
     end
 
+    before :each do
+      allow(Saml::Kit.configuration).to receive(:issuer).and_return(FFaker::Internet.uri("https"))
+    end
+
     describe "#build" do
       it 'builds a response with the request_id' do
         expect(subject.build.request_id).to eql(request.id)
@@ -431,11 +435,11 @@ RSpec.describe Saml::Kit::Response do
         expect(decrypted_hash['Assertion']['Subject']).to be_present
         expect(decrypted_hash['Assertion']['Subject']['NameID']).to be_present
         expect(decrypted_hash['Assertion']['Subject']['SubjectConfirmation']).to be_present
-        expect(decrypted_hash['Assertion']['Subject']['Conditions']).to be_present
-        expect(decrypted_hash['Assertion']['Subject']['Conditions']['AudienceRestriction']).to be_present
-        expect(decrypted_hash['Assertion']['Subject']['AuthnStatement']).to be_present
-        expect(decrypted_hash['Assertion']['Subject']['AuthnStatement']['AuthnContext']).to be_present
-        expect(decrypted_hash['Assertion']['Subject']['AuthnStatement']['AuthnContext']['AuthnContextClassRef']).to be_present
+        expect(decrypted_hash['Assertion']['Conditions']).to be_present
+        expect(decrypted_hash['Assertion']['Conditions']['AudienceRestriction']).to be_present
+        expect(decrypted_hash['Assertion']['AuthnStatement']).to be_present
+        expect(decrypted_hash['Assertion']['AuthnStatement']['AuthnContext']).to be_present
+        expect(decrypted_hash['Assertion']['AuthnStatement']['AuthnContext']['AuthnContextClassRef']).to be_present
       end
     end
   end