Skip to content

Commit

Permalink
Add test for email shown in OIDC authorization confirmation
Browse files Browse the repository at this point in the history
  • Loading branch information
vrajmohan committed Dec 19, 2024
1 parent 28b0797 commit b5c849e
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 11 deletions.
2 changes: 1 addition & 1 deletion app/controllers/openid_connect/authorization_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def email_address_id
if user_session[:selected_email_id_for_linked_identity].present?
return user_session[:selected_email_id_for_linked_identity]
end
identity = current_user.identities.find_by(service_provider: sp_session['issuer'])
identity = current_user.identities.find_by(service_provider: sp_session[:issuer])
identity&.email_address_id
end

Expand Down
67 changes: 57 additions & 10 deletions spec/features/openid_connect/authorization_confirmation_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,36 +31,83 @@ def create_user_and_remember_device
user1
end

shared_examples 'signin email after signing in again' do
shared_examples 'signing in with a different email prompts with the shared email' do
it 'confirms the user wants to continue to SP' do
shared_email = user1.identities.first.email_address.email
second_email = create(:email_address, user: user1)
sign_in_user(user1, second_email.email)
visit_idp_from_ial1_oidc_sp
expect(current_url).to match(user_authorization_confirmation_path)
expect(page).to have_content second_email.email
expect(page).to have_content shared_email

continue_as(second_email.email)
expect(oidc_redirect_url).to match('http://localhost:7654/auth/result')
end
end

it_behaves_like 'signin email after signing in again'
shared_examples 'signing in with a different email prompts with the signed in email' do
it 'confirms the user wants to continue to SP' do
second_email = create(:email_address, user: user1)
sign_in_user(user1, second_email.email)
visit_idp_from_ial1_oidc_sp
expect(current_url).to match(user_authorization_confirmation_path)
expect(page).to have_content second_email.email

continue_as(second_email.email)
expect(oidc_redirect_url).to match('http://localhost:7654/auth/result')
end
end

context 'with client-side redirect' do
context 'when email sharing feature is enabled' do
before do
allow(IdentityConfig.store).to receive(:openid_connect_redirect).and_return('client_side')
allow(IdentityConfig.store)
.to receive(:feature_select_email_to_share_enabled).and_return(true)
end

it_behaves_like 'signin email after signing in again'
it_behaves_like 'signing in with a different email prompts with the shared email'

context 'with client-side redirect' do
before do
allow(IdentityConfig.store).to receive(:openid_connect_redirect).and_return('client_side')
end

it_behaves_like 'signing in with a different email prompts with the shared email'
end

context 'with client-side javascript redirect' do
before do
allow(IdentityConfig.store).to receive(:openid_connect_redirect)
.and_return('client_side_js')
end

it_behaves_like 'signing in with a different email prompts with the shared email'
end
end

context 'with client-side javascript redirect' do
context 'when email sharing feature is disabled' do
before do
allow(IdentityConfig.store).to receive(:openid_connect_redirect)
.and_return('client_side_js')
allow(IdentityConfig.store)
.to receive(:feature_select_email_to_share_enabled).and_return(false)
end

it_behaves_like 'signin email after signing in again'
it_behaves_like 'signing in with a different email prompts with the signed in email'

context 'with client-side redirect' do
before do
allow(IdentityConfig.store).to receive(:openid_connect_redirect).and_return('client_side')
end

it_behaves_like 'signing in with a different email prompts with the signed in email'
end

context 'with client-side javascript redirect' do
before do
allow(IdentityConfig.store).to receive(:openid_connect_redirect)
.and_return('client_side_js')
end

it_behaves_like 'signing in with a different email prompts with the signed in email'
end
end

it 'it allows the user to switch accounts prior to continuing to the SP' do
Expand Down

0 comments on commit b5c849e

Please sign in to comment.