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/idv/gpo_verify_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def create
@gpo_verify_form = build_gpo_verify_form

if throttle.throttled_else_increment?
irs_attempts_api_tracker.idv_gpo_verification_throttled
irs_attempts_api_tracker.idv_gpo_verification_rate_limited
render_throttled
else
result = @gpo_verify_form.submit
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/users/verify_personal_key_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def new

def create
if throttle.throttled_else_increment?
irs_attempts_api_tracker.personal_key_reactivation_throttled(success: false)
irs_attempts_api_tracker.personal_key_reactivation_rate_limited(success: false)
render_throttled
else
result = personal_key_form.submit
Expand Down
12 changes: 6 additions & 6 deletions app/services/irs_attempts_api/tracker_events.rb
Original file line number Diff line number Diff line change
Expand Up @@ -148,10 +148,10 @@ def idv_gpo_verification_submitted(success:, failure_reason: nil)
)
end

# GPO verification submission throttled, user entered in too many invalid gpo letter codes
def idv_gpo_verification_throttled
# GPO verification submission rate limited, user entered in too many invalid gpo letter codes
def idv_gpo_verification_rate_limited
track_event(
:idv_gpo_verification_throttled,
:idv_gpo_verification_rate_limited,
)
end

Expand Down Expand Up @@ -615,11 +615,11 @@ def personal_key_reactivation_submitted(success:, failure_reason: nil)
)
end

# Tracks when User personal key has been throttled by too many attempts
# Tracks when User personal key has been rate limited by too many attempts
# @param [Boolean] success
def personal_key_reactivation_throttled(success:)
def personal_key_reactivation_rate_limited(success:)
track_event(
:personal_key_reactivation_throttled,
:personal_key_reactivation_rate_limited,
success: success,
)
end
Expand Down
7 changes: 4 additions & 3 deletions spec/controllers/idv/gpo_verify_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@
end

describe '#create' do
let(:otp_code_error_message) { { otp: [t('errors.messages.confirmation_code_incorrect')] } }
let(:otp_code_incorrect) { { otp: [:confirmation_code_incorrect] } }
let(:success_properties) { { success: true, failure_reason: nil } }

Expand Down Expand Up @@ -171,7 +172,7 @@
expect(@analytics).to receive(:track_event).with(
'IdV: GPO verification submitted',
success: false,
errors: { otp: [t('errors.messages.confirmation_code_incorrect')] },
errors: otp_code_error_message,
pending_in_person_enrollment: false,
enqueued_at: nil,
error_details: otp_code_incorrect,
Expand Down Expand Up @@ -201,7 +202,7 @@
expect(@analytics).to receive(:track_event).with(
'IdV: GPO verification submitted',
success: false,
errors: { otp: [t('errors.messages.confirmation_code_incorrect')] },
errors: otp_code_error_message,
pending_in_person_enrollment: false,
enqueued_at: nil,
error_details: otp_code_incorrect,
Expand All @@ -213,7 +214,7 @@
throttle_type: :verify_gpo_key,
).once

expect(@irs_attempts_api_tracker).to receive(:idv_gpo_verification_throttled).once
expect(@irs_attempts_api_tracker).to receive(:idv_gpo_verification_rate_limited).once

(max_attempts + 1).times do |i|
post(
Expand Down
28 changes: 16 additions & 12 deletions spec/controllers/users/verify_personal_key_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@

it 'renders throttled page' do
stub_analytics
stub_attempts_tracker
expect(@analytics).to receive(:track_event).with(
'Personal key reactivation: Personal key form visited',
).once
Expand All @@ -62,6 +63,8 @@
throttle_type: :verify_personal_key,
).once

expect(@irs_attempts_api_tracker).not_to receive(:personal_key_reactivation_rate_limited)

get :new

expect(response).to render_template(:throttled)
Expand All @@ -81,8 +84,10 @@
]
end
let(:error_text) { 'Incorrect personal key' }
let(:personal_key_bad_params) { { personal_key: 'baaad' } }
let(:personal_key_error) { { personal_key: [error_text] } }
let(:failure_properties) { { success: false, failure_reason: personal_key_error } }
let(:pii_like_keypaths_errors) { [[:errors, :personal_key], [:error_details, :personal_key]] }
let(:response_ok) { FormResponse.new(success: true, errors: {}) }
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like the simplification that is done here. Great work 👍

let(:response_bad) { FormResponse.new(success: false, errors: personal_key_error, extra: {}) }

Expand All @@ -99,7 +104,7 @@
'Personal key reactivation: Personal key form submitted',
errors: {},
success: true,
pii_like_keypaths: [[:errors, :personal_key], [:error_details, :personal_key]],
pii_like_keypaths: pii_like_keypaths_errors,
).once

expect(@analytics).to receive(:track_event).with(
Expand All @@ -126,16 +131,14 @@
end

context 'with an invalid form' do
let(:bad_key) { 'baaad' }
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😆


it 'sets an error in the flash' do
post :create, params: { personal_key: bad_key }
post :create, params: personal_key_bad_params

expect(flash[:error]).to eq(error_text)
end

it 'redirects to form' do
post :create, params: { personal_key: bad_key }
post :create, params: personal_key_bad_params
expect(response).to redirect_to(verify_personal_key_url)
end

Expand All @@ -148,29 +151,30 @@

allow_any_instance_of(VerifyPersonalKeyForm).to receive(:submit).and_return(response_bad)

post :create, params: { personal_key: bad_key }
post :create, params: personal_key_bad_params
end
end

context 'with throttle reached' do
let(:bad_key) { 'baaad' }

it 'renders throttled page' do
stub_analytics
stub_attempts_tracker
expect(@analytics).to receive(:track_event).with(
'Personal key reactivation: Personal key form submitted',
errors: { personal_key: ['Please fill in this field.', 'Incorrect personal key'] },
errors: { personal_key: ['Please fill in this field.', error_text] },
error_details: { personal_key: [:blank, :personal_key_incorrect] },
success: false,
pii_like_keypaths: [[:errors, :personal_key], [:error_details, :personal_key]],
pii_like_keypaths: pii_like_keypaths_errors,
).once
expect(@analytics).to receive(:track_event).with(
'Throttler Rate Limit Triggered',
throttle_type: :verify_personal_key,
).once

expect(@irs_attempts_api_tracker).to receive(:personal_key_reactivation_rate_limited).once

max_attempts = Throttle.max_attempts(:verify_personal_key)
(max_attempts + 1).times { post :create, params: { personal_key: bad_key } }
(max_attempts + 1).times { post :create, params: personal_key_bad_params }

expect(response).to render_template(:throttled)
end
Expand All @@ -184,7 +188,7 @@

allow_any_instance_of(VerifyPersonalKeyForm).to receive(:submit).and_return(response_bad)

post :create, params: { personal_key: bad_key }
post :create, params: personal_key_bad_params
end
end
end
Expand Down