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
1 change: 1 addition & 0 deletions app/forms/recaptcha_form.rb
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ def log_analytics(result: nil, error: nil)
evaluated_as_valid: recaptcha_result_valid?(result),
exception_class: error&.class&.name,
form_class: self.class.name,
recaptcha_action:,
**extra_analytics_properties,
)
end
Expand Down
5 changes: 4 additions & 1 deletion app/services/analytics_events.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6138,13 +6138,15 @@ def reactivate_account_visit
# @param [Boolean] evaluated_as_valid Whether result was considered valid
# @param [String] form_class Class name of form
# @param [String, nil] exception_class Class name of exception, if error occurred
# @param [String, nil] phone_country_code Country code associated with reCAPTCHA phone result
# @param [String] recaptcha_action reCAPTCHA action name, for distinct user flow
# @param [String, nil] phone_country_code Country code associated with reCAPTCHA phone results
def recaptcha_verify_result_received(
recaptcha_result:,
score_threshold:,
evaluated_as_valid:,
form_class:,
exception_class:,
recaptcha_action:,
phone_country_code: nil,
**extra
)
Expand All @@ -6155,6 +6157,7 @@ def recaptcha_verify_result_received(
evaluated_as_valid:,
form_class:,
exception_class:,
recaptcha_action:,
phone_country_code:,
**extra,
)
Expand Down
1 change: 1 addition & 0 deletions spec/features/phone/add_phone_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,7 @@
evaluated_as_valid: false,
score_threshold: 0.6,
phone_country_code: 'AU',
recaptcha_action: 'phone_setup',
form_class: 'RecaptchaMockForm',
)

Expand Down
31 changes: 19 additions & 12 deletions spec/forms/recaptcha_enterprise_form_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
let(:score_threshold) { 0.2 }
let(:analytics) { FakeAnalytics.new }
let(:extra_analytics_properties) { {} }
let(:action) { 'example_action' }
let(:recaptcha_action) { 'example_action' }
let(:recaptcha_enterprise_api_key) { 'recaptcha_enterprise_api_key' }
let(:recaptcha_enterprise_project_id) { 'project_id' }
let(:recaptcha_site_key) { 'recaptcha_site_key' }
Expand All @@ -19,7 +19,7 @@

subject(:form) do
described_class.new(
recaptcha_action: action,
recaptcha_action:,
score_threshold:,
analytics:,
extra_analytics_properties:,
Expand Down Expand Up @@ -121,11 +121,11 @@
before do
stub_recaptcha_response(
body: {
tokenProperties: { valid: false, action:, invalidReason: 'EXPIRED' },
tokenProperties: { valid: false, action: recaptcha_action, invalidReason: 'EXPIRED' },
event: {},
name:,
},
action:,
action: recaptcha_action,
token:,
)
end
Expand Down Expand Up @@ -155,6 +155,7 @@
evaluated_as_valid: false,
score_threshold: score_threshold,
form_class: 'RecaptchaEnterpriseForm',
recaptcha_action:,
)
end
end
Expand All @@ -167,7 +168,7 @@
body: {
error: { code: 400, status: 'INVALID_ARGUMENT' },
},
action:,
action: recaptcha_action,
token:,
)
end
Expand All @@ -194,6 +195,7 @@
evaluated_as_valid: true,
score_threshold: score_threshold,
form_class: 'RecaptchaEnterpriseForm',
recaptcha_action:,
)
end
end
Expand Down Expand Up @@ -221,6 +223,7 @@
score_threshold: score_threshold,
form_class: 'RecaptchaEnterpriseForm',
exception_class: 'Faraday::ConnectionFailed',
recaptcha_action:,
)
end
end
Expand All @@ -233,12 +236,12 @@
before do
stub_recaptcha_response(
body: {
tokenProperties: { valid: true, action: },
tokenProperties: { valid: true, action: recaptcha_action },
riskAnalysis: { score:, reasons: ['AUTOMATION'] },
event: {},
name:,
},
action:,
action: recaptcha_action,
token:,
)
end
Expand Down Expand Up @@ -268,19 +271,20 @@
evaluated_as_valid: false,
score_threshold: score_threshold,
form_class: 'RecaptchaEnterpriseForm',
recaptcha_action:,
)
end

context 'with low confidence score as one of the reasons for failure' do
before do
stub_recaptcha_response(
body: {
tokenProperties: { valid: true, action: },
tokenProperties: { valid: true, action: recaptcha_action },
riskAnalysis: { score:, reasons: ['LOW_CONFIDENCE_SCORE'] },
event: {},
name:,
},
action:,
action: recaptcha_action,
token:,
)
end
Expand All @@ -307,6 +311,7 @@
evaluated_as_valid: true,
score_threshold: score_threshold,
form_class: 'RecaptchaEnterpriseForm',
recaptcha_action:,
)
end
end
Expand All @@ -320,12 +325,12 @@
around do |example|
stubbed_request = stub_recaptcha_response(
body: {
tokenProperties: { valid: true, action: },
tokenProperties: { valid: true, action: recaptcha_action },
riskAnalysis: { score:, reasons: ['LOW_CONFIDENCE'] },
event: {},
name:,
},
action:,
action: recaptcha_action,
token:,
)
example.run
Expand Down Expand Up @@ -354,6 +359,7 @@
evaluated_as_valid: true,
score_threshold: score_threshold,
form_class: 'RecaptchaEnterpriseForm',
recaptcha_action:,
)
end

Expand All @@ -368,7 +374,7 @@
event: {},
name:,
},
action:,
action: recaptcha_action,
token:,
)
end
Expand Down Expand Up @@ -402,6 +408,7 @@
evaluated_as_valid: true,
score_threshold: score_threshold,
form_class: 'RecaptchaEnterpriseForm',
recaptcha_action:,
extra: true,
)
end
Expand Down
10 changes: 9 additions & 1 deletion spec/forms/recaptcha_form_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@
let(:analytics) { FakeAnalytics.new }
let(:extra_analytics_properties) { {} }
let(:recaptcha_secret_key) { 'recaptcha_secret_key' }
let(:recaptcha_action) { 'example_action' }

subject(:form) do
RecaptchaForm.new(score_threshold:, analytics:, extra_analytics_properties:)
RecaptchaForm.new(score_threshold:, recaptcha_action:, analytics:, extra_analytics_properties:)
end

before do
Expand Down Expand Up @@ -129,6 +130,7 @@
evaluated_as_valid: false,
score_threshold: score_threshold,
form_class: 'RecaptchaForm',
recaptcha_action:,
)
end

Expand Down Expand Up @@ -163,6 +165,7 @@
evaluated_as_valid: true,
score_threshold: score_threshold,
form_class: 'RecaptchaForm',
recaptcha_action:,
)
end
end
Expand Down Expand Up @@ -197,6 +200,7 @@
evaluated_as_valid: true,
score_threshold: score_threshold,
form_class: 'RecaptchaForm',
recaptcha_action:,
)
end
end
Expand Down Expand Up @@ -226,6 +230,7 @@
score_threshold: score_threshold,
form_class: 'RecaptchaForm',
exception_class: 'Faraday::ConnectionFailed',
recaptcha_action:,
)
end
end
Expand Down Expand Up @@ -263,6 +268,7 @@
evaluated_as_valid: false,
score_threshold: score_threshold,
form_class: 'RecaptchaForm',
recaptcha_action:,
)
end
end
Expand Down Expand Up @@ -299,6 +305,7 @@
evaluated_as_valid: true,
score_threshold: score_threshold,
form_class: 'RecaptchaForm',
recaptcha_action:,
)
end

Expand All @@ -320,6 +327,7 @@
evaluated_as_valid: true,
score_threshold: score_threshold,
form_class: 'RecaptchaForm',
recaptcha_action:,
extra: true,
)
end
Expand Down
5 changes: 4 additions & 1 deletion spec/forms/recaptcha_mock_form_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@
let(:score_threshold) { 0.2 }
let(:analytics) { FakeAnalytics.new }
let(:score) { nil }
let(:recaptcha_action) { 'example_action' }
subject(:form) do
RecaptchaMockForm.new(score_threshold:, analytics:, score:)
RecaptchaMockForm.new(score_threshold:, analytics:, recaptcha_action:, score:)
end

around do |example|
Expand Down Expand Up @@ -44,6 +45,7 @@
evaluated_as_valid: false,
score_threshold: score_threshold,
form_class: 'RecaptchaMockForm',
recaptcha_action:,
)
end
end
Expand Down Expand Up @@ -74,6 +76,7 @@
evaluated_as_valid: true,
score_threshold: score_threshold,
form_class: 'RecaptchaMockForm',
recaptcha_action:,
)
end

Expand Down
1 change: 1 addition & 0 deletions spec/support/shared_examples/sign_in.rb
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,7 @@ def user_with_broken_personal_key(scenario)
},
evaluated_as_valid: false,
score_threshold: 0.2,
recaptcha_action: 'sign_in',
form_class: 'RecaptchaMockForm',
)
expect(fake_analytics).to have_logged_event(
Expand Down