diff --git a/app/services/service_provider_request_handler.rb b/app/services/service_provider_request_handler.rb index 78b3b340d4a..c46bfcbca41 100644 --- a/app/services/service_provider_request_handler.rb +++ b/app/services/service_provider_request_handler.rb @@ -10,9 +10,12 @@ def call pull_request_id_from_current_sp_session_id delete_sp_request_if_session_has_matching_request_id - ServiceProviderRequestProxy.create!(attributes) - StoreSpMetadataInSession.new(session: session, request_id: request_id).call + service_provider_request = ServiceProviderRequestProxy.create!(attributes) + + StoreSpMetadataInSession.new(session: session, request_id: request_id).call( + service_provider_request: service_provider_request, + ) end private diff --git a/app/services/store_sp_metadata_in_session.rb b/app/services/store_sp_metadata_in_session.rb index d2fb274eb93..80ef897cb29 100644 --- a/app/services/store_sp_metadata_in_session.rb +++ b/app/services/store_sp_metadata_in_session.rb @@ -4,8 +4,8 @@ def initialize(session:, request_id:) @request_id = request_id end - def call - Rails.logger.info(event_attributes) + def call(service_provider_request: nil) + @sp_request = service_provider_request if service_provider_request return if sp_request.is_a?(NullServiceProviderRequest) diff --git a/spec/services/store_sp_metadata_in_session_spec.rb b/spec/services/store_sp_metadata_in_session_spec.rb index cf1e63626f6..94a35ca8ccf 100644 --- a/spec/services/store_sp_metadata_in_session_spec.rb +++ b/spec/services/store_sp_metadata_in_session_spec.rb @@ -4,24 +4,15 @@ describe '#call' do context 'when a ServiceProviderRequestProxy is not found' do it 'does not set the session[:sp] hash' do - allow(Rails.logger).to receive(:info) app_session = {} instance = StoreSpMetadataInSession.new(session: app_session, request_id: 'foo') - info_hash = { - event: 'StoreSpMetadataInSession', - request_id_present: true, - sp_request_class: 'NullServiceProviderRequest', - }.to_json expect { instance.call }.to_not change(app_session, :keys) - expect(Rails.logger).to have_received(:info).with(info_hash) end end context 'when a ServiceProviderRequestProxy is found' do it 'sets the session[:sp] hash' do - allow(Rails.logger).to receive(:info) - app_session = {} request_id = SecureRandom.uuid ServiceProviderRequestProxy.find_or_create_by(uuid: request_id) do |sp_request| @@ -32,12 +23,6 @@ end instance = StoreSpMetadataInSession.new(session: app_session, request_id: request_id) - info_hash = { - event: 'StoreSpMetadataInSession', - request_id_present: true, - sp_request_class: 'ServiceProviderRequest', - }.to_json - app_session_hash = { issuer: 'issuer', aal_level_requested: nil, @@ -52,15 +37,12 @@ } instance.call - expect(Rails.logger).to have_received(:info).with(info_hash) expect(app_session[:sp]).to eq app_session_hash end end context 'when IAL2 and AAL3 are requested' do it 'sets the session[:sp] hash' do - allow(Rails.logger).to receive(:info) - app_session = {} request_id = SecureRandom.uuid ServiceProviderRequestProxy.find_or_create_by(uuid: request_id) do |sp_request| @@ -72,12 +54,6 @@ end instance = StoreSpMetadataInSession.new(session: app_session, request_id: request_id) - info_hash = { - event: 'StoreSpMetadataInSession', - request_id_present: true, - sp_request_class: 'ServiceProviderRequest', - }.to_json - app_session_hash = { issuer: 'issuer', aal_level_requested: 3, @@ -92,15 +68,12 @@ } instance.call - expect(Rails.logger).to have_received(:info).with(info_hash) expect(app_session[:sp]).to eq app_session_hash end end context 'when IAL2 and phishing-resistant are requested' do it 'sets the session[:sp] hash' do - allow(Rails.logger).to receive(:info) - app_session = {} request_id = SecureRandom.uuid ServiceProviderRequestProxy.find_or_create_by(uuid: request_id) do |sp_request| @@ -112,12 +85,6 @@ end instance = StoreSpMetadataInSession.new(session: app_session, request_id: request_id) - info_hash = { - event: 'StoreSpMetadataInSession', - request_id_present: true, - sp_request_class: 'ServiceProviderRequest', - }.to_json - app_session_hash = { issuer: 'issuer', aal_level_requested: 2, @@ -132,7 +99,6 @@ } instance.call - expect(Rails.logger).to have_received(:info).with(info_hash) expect(app_session[:sp]).to eq app_session_hash end end