From b83e589b629c42afe0c122690e5d67d25572f798 Mon Sep 17 00:00:00 2001 From: Vraj Mohan Date: Fri, 20 Dec 2024 10:26:51 -0800 Subject: [PATCH] Share email only when the identity is "active" --- app/models/service_provider_identity.rb | 2 +- spec/models/service_provider_identity_spec.rb | 20 +++++++++++++++++-- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/app/models/service_provider_identity.rb b/app/models/service_provider_identity.rb index 5ad3eaf6ede..255b96e6198 100644 --- a/app/models/service_provider_identity.rb +++ b/app/models/service_provider_identity.rb @@ -66,7 +66,7 @@ def happened_at end def email_address_for_sharing - if IdentityConfig.store.feature_select_email_to_share_enabled && email_address + if IdentityConfig.store.feature_select_email_to_share_enabled && session_uuid && email_address return email_address end user.last_sign_in_email_address diff --git a/spec/models/service_provider_identity_spec.rb b/spec/models/service_provider_identity_spec.rb index 54015505d9d..6bbb204d148 100644 --- a/spec/models/service_provider_identity_spec.rb +++ b/spec/models/service_provider_identity_spec.rb @@ -216,8 +216,24 @@ identity.email_address = shared_email_address end - it 'returns the shared email' do - expect(identity.email_address_for_sharing).to eq(shared_email_address) + context 'when the identity is active' do + before do + identity.session_uuid = SecureRandom.uuid + end + + it 'returns the shared email' do + expect(identity.email_address_for_sharing).to eq(shared_email_address) + end + end + + context 'when the identity is not active' do + before do + identity.session_uuid = nil + end + + it 'returns the last login email' do + expect(identity.email_address_for_sharing).to eq(last_login_email_address) + end end end