Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 11 additions & 11 deletions app/controllers/concerns/verify_sp_attributes_concern.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down Expand Up @@ -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 }
Expand Down