diff --git a/app/controllers/concerns/verify_sp_attributes_concern.rb b/app/controllers/concerns/verify_sp_attributes_concern.rb index a474059904e..65db253fbd0 100644 --- a/app/controllers/concerns/verify_sp_attributes_concern.rb +++ b/app/controllers/concerns/verify_sp_attributes_concern.rb @@ -3,13 +3,14 @@ def needs_completion_screen_reason return nil if sp_session[:issuer].blank? return nil if sp_session[:request_url].blank? + sp_session_identity = find_sp_session_identity if sp_session_identity.nil? :new_sp - elsif !requested_attributes_verified? + elsif !requested_attributes_verified?(sp_session_identity) :new_attributes - elsif consent_has_expired? + elsif consent_has_expired?(sp_session_identity) :consent_expired - elsif consent_was_revoked? + elsif consent_was_revoked?(sp_session_identity) :consent_revoked end end @@ -26,7 +27,7 @@ def update_verified_attributes ) end - def consent_has_expired? + def consent_has_expired?(sp_session_identity) return false unless sp_session_identity return false if sp_session_identity.deleted_at.present? last_estimated_consent = sp_session_identity.last_consented_at || sp_session_identity.created_at @@ -35,7 +36,7 @@ def consent_has_expired? verified_after_consent?(last_estimated_consent) end - def consent_was_revoked? + def consent_was_revoked?(sp_session_identity) return false unless sp_session_identity sp_session_identity.deleted_at.present? end @@ -48,14 +49,13 @@ def verified_after_consent?(last_estimated_consent) verification_timestamp.present? && last_estimated_consent < verification_timestamp end - def sp_session_identity - @sp_session_identity = - current_user&.identities&.find_by(service_provider: sp_session[:issuer]) + def find_sp_session_identity + current_user&.identities&.find_by(service_provider: sp_session[:issuer]) end - def requested_attributes_verified? - @sp_session_identity && ( - Array(sp_session[:requested_attributes]) - @sp_session_identity.verified_attributes.to_a + def requested_attributes_verified?(sp_session_identity) + sp_session_identity && ( + Array(sp_session[:requested_attributes]) - sp_session_identity.verified_attributes.to_a ).empty? end end diff --git a/spec/controllers/concerns/verify_sp_attributes_concern_spec.rb b/spec/controllers/concerns/verify_sp_attributes_concern_spec.rb index 85db9e38c4a..d6be336fdfa 100644 --- a/spec/controllers/concerns/verify_sp_attributes_concern_spec.rb +++ b/spec/controllers/concerns/verify_sp_attributes_concern_spec.rb @@ -14,7 +14,7 @@ allow(controller).to receive(:sp_session_identity).and_return(sp_session_identity) end - subject(:consent_has_expired?) { controller.consent_has_expired? } + subject(:consent_has_expired?) { controller.consent_has_expired?(sp_session_identity) } context 'when there is no sp_session_identity' do let(:sp_session_identity) { nil } @@ -113,7 +113,7 @@ allow(controller).to receive(:sp_session_identity).and_return(sp_session_identity) end - subject(:consent_was_revoked?) { controller.consent_was_revoked? } + subject(:consent_was_revoked?) { controller.consent_was_revoked?(sp_session_identity) } context 'when there is no sp_session_identity' do let(:sp_session_identity) { nil }