diff --git a/app/controllers/users/phone_setup_controller.rb b/app/controllers/users/phone_setup_controller.rb index 6344fd8e60b..579e68457fd 100644 --- a/app/controllers/users/phone_setup_controller.rb +++ b/app/controllers/users/phone_setup_controller.rb @@ -35,7 +35,7 @@ def create if result.success? handle_create_success(@new_phone_form.phone) elsif recoverable_recaptcha_error?(result) - render :spam_protection, locals: { authentication_methods_setup_path: } + render :spam_protection else render :index end diff --git a/app/controllers/users/phones_controller.rb b/app/controllers/users/phones_controller.rb index d2813f92eec..b5bd2834ef8 100644 --- a/app/controllers/users/phones_controller.rb +++ b/app/controllers/users/phones_controller.rb @@ -11,6 +11,8 @@ class PhonesController < ApplicationController before_action :allow_csp_recaptcha_src, if: :recaptcha_enabled? before_action :confirm_recently_authenticated_2fa + helper_method :in_multi_mfa_selection_flow? + def add user_session[:phone_id] = nil @new_phone_form = NewPhoneForm.new(user: current_user, analytics: analytics) diff --git a/app/views/users/phone_setup/spam_protection.html.erb b/app/views/users/phone_setup/spam_protection.html.erb index 620c13936a1..85cd48d5d7c 100644 --- a/app/views/users/phone_setup/spam_protection.html.erb +++ b/app/views/users/phone_setup/spam_protection.html.erb @@ -43,7 +43,7 @@ <%= render TroubleshootingOptionsComponent.new do |c| %> <% c.with_header { t('components.troubleshooting_options.default_heading') } %> - <% if local_assigns[:authentication_methods_setup_path].present? %> + <% if in_multi_mfa_selection_flow? %> <% c.with_option( url: authentication_methods_setup_path, ).with_content(t('two_factor_authentication.login_options_link_text')) %> @@ -59,7 +59,7 @@ ).with_content(t('two_factor_authentication.learn_more')) %> <% end %> -<% unless local_assigns[:authentication_methods_setup_path].present? %> +<% unless in_multi_mfa_selection_flow? %> <%= render PageFooterComponent.new do %> <%= link_to t('links.cancel'), account_path %> <% end %> diff --git a/spec/features/phone/add_phone_spec.rb b/spec/features/phone/add_phone_spec.rb index c018e2ba008..b65c8017357 100644 --- a/spec/features/phone/add_phone_spec.rb +++ b/spec/features/phone/add_phone_spec.rb @@ -220,6 +220,8 @@ fill_in t('components.captcha_submit_button.mock_score_label'), with: '0.5' click_send_one_time_code expect(page).to have_content(t('titles.spam_protection'), wait: 5) + expect(page).not_to have_link(t('two_factor_authentication.login_options_link_text')) + expect(page).to have_link(t('links.cancel')) click_continue expect(page).to have_content(t('two_factor_authentication.header_text')) visit account_path diff --git a/spec/features/users/sign_up_spec.rb b/spec/features/users/sign_up_spec.rb index 7cc68677adf..30a1381da8f 100644 --- a/spec/features/users/sign_up_spec.rb +++ b/spec/features/users/sign_up_spec.rb @@ -132,6 +132,21 @@ expect(page).to have_content(/#{rate_limited_message}/) end + scenario 'signing up using phone with a reCAPTCHA challenge', :js do + allow(IdentityConfig.store).to receive(:phone_recaptcha_mock_validator).and_return(true) + allow(IdentityConfig.store).to receive(:phone_recaptcha_score_threshold).and_return(0.6) + + sign_up_and_set_password + select_2fa_option('phone') + + fill_in t('two_factor_authentication.phone_label'), with: '+61 0491 570 006' + fill_in t('components.captcha_submit_button.mock_score_label'), with: '0.5' + click_send_one_time_code + expect(page).to have_content(t('titles.spam_protection'), wait: 5) + expect(page).to have_link(t('two_factor_authentication.login_options_link_text')) + expect(page).not_to have_link(t('links.cancel')) + end + context 'with js', js: true do before do page.driver.browser.execute_cdp( diff --git a/spec/views/phone_setup/spam_protection.html.erb_spec.rb b/spec/views/phone_setup/spam_protection.html.erb_spec.rb index 657b02255fb..24beaf790b8 100644 --- a/spec/views/phone_setup/spam_protection.html.erb_spec.rb +++ b/spec/views/phone_setup/spam_protection.html.erb_spec.rb @@ -3,12 +3,13 @@ RSpec.describe 'users/phone_setup/spam_protection.html.erb' do let(:user) { build_stubbed(:user) } let(:form) { NewPhoneForm.new(user:) } - let(:locals) { {} } + let(:in_multi_mfa_selection_flow) { false } - subject(:rendered) { render(template: 'users/phone_setup/spam_protection', locals:) } + subject(:rendered) { render(template: 'users/phone_setup/spam_protection') } before do @new_phone_form = form + allow(view).to receive(:in_multi_mfa_selection_flow?).and_return(in_multi_mfa_selection_flow) end it 'renders hidden form inputs' do @@ -33,9 +34,8 @@ expect(rendered).not_to have_link(t('two_factor_authentication.login_options_link_text')) end - context 'with two factor options path' do - let(:authentication_methods_setup_path) { root_path } - let(:locals) { { authentication_methods_setup_path: } } + context 'in multi mfa selectino flow' do + let(:in_multi_mfa_selection_flow) { true } it 'renders additional troubleshooting option to two factor options' do expect(rendered).to have_link(