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
2 changes: 1 addition & 1 deletion app/controllers/users/phone_setup_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions app/controllers/users/phones_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions app/views/users/phone_setup/spam_protection.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -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')) %>
Expand All @@ -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 %>
Expand Down
2 changes: 2 additions & 0 deletions spec/features/phone/add_phone_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 15 additions & 0 deletions spec/features/users/sign_up_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
10 changes: 5 additions & 5 deletions spec/views/phone_setup/spam_protection.html.erb_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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(
Expand Down