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
8 changes: 6 additions & 2 deletions app/controllers/idv/usps_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -136,12 +136,16 @@ def form_response(result, success)
FormResponse.new(success: success, errors: result[:errors])
end

def idv_throttle_params
[idv_session.current_user.id, :idv_resolution]
end

def idv_attempter_increment
Throttler::Increment.call(idv_session.current_user.id, :idv_resolution, analytics: analytics)
Throttler::Increment.call(*idv_throttle_params)
end

def idv_attempter_throttled?
Throttler::IsThrottled.call(idv_session.current_user.id, :idv_resolution)
Throttler::IsThrottled.call(*idv_throttle_params)
end

def throttle_failure
Expand Down
1 change: 0 additions & 1 deletion app/controllers/users/verify_account_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ def create
throttled = Throttler::IsThrottledElseIncrement.call(
current_user.id,
:verify_gpo_key,
analytics: analytics,
)

if throttled
Expand Down
1 change: 0 additions & 1 deletion app/controllers/users/verify_personal_key_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ def create
throttled = Throttler::IsThrottledElseIncrement.call(
current_user.id,
:verify_personal_key,
analytics: analytics,
)

if throttled
Expand Down
4 changes: 1 addition & 3 deletions app/forms/idv/api_document_verification_form.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,9 @@ class ApiDocumentVerificationForm

validate :throttle_if_rate_limited

def initialize(params, liveness_checking_enabled:, analytics:)
def initialize(params, liveness_checking_enabled:)
@params = params
@liveness_checking_enabled = liveness_checking_enabled
@analytics = analytics
end

def submit
Expand Down Expand Up @@ -87,7 +86,6 @@ def throttled_else_increment
@throttled = Throttler::IsThrottledElseIncrement.call(
document_capture_session.user_id,
:idv_acuant,
analytics: @analytics,
)
end

Expand Down
1 change: 0 additions & 1 deletion app/forms/idv/api_image_upload_form.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ def throttled_else_increment
@throttled = Throttler::IsThrottledElseIncrement.call(
document_capture_session.user_id,
:idv_acuant,
analytics: @analytics,
)
end

Expand Down
1 change: 0 additions & 1 deletion app/services/analytics.rb
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,6 @@ def browser_attributes
SIGN_IN_PAGE_VISIT = 'Sign in page visited'.freeze
SP_REDIRECT_INITIATED = 'SP redirect initiated'.freeze
TELEPHONY_OTP_SENT = 'Telephony: OTP sent'.freeze
THROTTLER_RATE_LIMIT_TRIGGERED = 'Throttler Rate Limit Triggered'.freeze
TOTP_SETUP_VISIT = 'TOTP Setup Visited'.freeze
TOTP_USER_DISABLED = 'TOTP: User Disabled TOTP'.freeze
OTP_PHONE_VALIDATION_FAILED = 'Twilio Phone Validation Failed'.freeze
Expand Down
1 change: 0 additions & 1 deletion app/services/idv/actions/verify_document_action.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ def form
@form ||= Idv::ApiDocumentVerificationForm.new(
params,
liveness_checking_enabled: liveness_checking_enabled?,
analytics: @flow.analytics,
)
end

Expand Down
10 changes: 7 additions & 3 deletions app/services/idv/steps/doc_auth_base_step.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,16 @@ def initialize(flow)

private

def idv_throttle_params
[current_user.id, :idv_resolution]
end

def attempter_increment
Throttler::Increment.call(current_user.id, :idv_resolution, analytics: @flow.analytics)
Throttler::Increment.call(*idv_throttle_params)
end

def attempter_throttled?
Throttler::IsThrottled.call(current_user.id, :idv_resolution)
Throttler::IsThrottled.call(*idv_throttle_params)
end

def idv_failure(result)
Expand Down Expand Up @@ -64,7 +68,7 @@ def throttled_url
end

def throttled_else_increment
Throttler::IsThrottledElseIncrement.call(user_id, :idv_acuant, analytics: @flow.analytics)
Throttler::IsThrottledElseIncrement.call(user_id, :idv_acuant)
end

def user_id
Expand Down
6 changes: 1 addition & 5 deletions app/services/idv/steps/send_link_step.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,7 @@ def link(session_uuid)
end

def throttled_else_increment
Throttler::IsThrottledElseIncrement.call(
user_id,
:idv_send_link,
analytics: @flow.analytics,
)
Throttler::IsThrottledElseIncrement.call(user_id, :idv_send_link)
end
end
end
Expand Down
8 changes: 2 additions & 6 deletions app/services/throttler/increment.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
module Throttler
class Increment
def self.call(user_id, throttle_type, analytics: nil)
def self.call(user_id, throttle_type)
throttle = Throttler::FindOrCreate.call(user_id, throttle_type)
return throttle if throttle.maxed?
Update.call(
throttle: throttle,
attributes: { attempts: throttle.attempts + 1, attempted_at: Time.zone.now },
analytics: analytics,
)
throttle.update(attempts: throttle.attempts + 1, attempted_at: Time.zone.now)
throttle
end
end
Expand Down
8 changes: 2 additions & 6 deletions app/services/throttler/is_throttled_else_increment.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
module Throttler
class IsThrottledElseIncrement
def self.call(user_id, throttle_type, analytics: nil)
def self.call(user_id, throttle_type)
throttle = FindOrCreate.call(user_id, throttle_type)
return throttle if throttle.throttled?
Update.call(
throttle: throttle,
attributes: { attempts: throttle.attempts + 1, attempted_at: Time.zone.now },
analytics: analytics,
)
throttle.update(attempts: throttle.attempts + 1, attempted_at: Time.zone.now)
false
end
end
Expand Down
2 changes: 1 addition & 1 deletion app/services/throttler/reset.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module Throttler
class Reset
def self.call(user_id, throttle_type)
throttle = Throttle.find_or_create_by(user_id: user_id, throttle_type: throttle_type)
Update.call(throttle: throttle, attributes: { attempts: 0 })
throttle.update(attempts: 0)
throttle
end
end
Expand Down
13 changes: 0 additions & 13 deletions app/services/throttler/update.rb

This file was deleted.

5 changes: 0 additions & 5 deletions spec/controllers/users/verify_account_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -108,11 +108,6 @@
success: false, errors: { otp: [t('errors.messages.confirmation_code_incorrect')]},
).exactly(max_attempts).times

expect(@analytics).to receive(:track_event).with(
Analytics::THROTTLER_RATE_LIMIT_TRIGGERED,
throttle_type: 'verify_gpo_key',
).once

(max_attempts + 1).times do |i|
post(
:create,
Expand Down
4 changes: 0 additions & 4 deletions spec/controllers/users/verify_personal_key_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -109,10 +109,6 @@
Analytics::PERSONAL_KEY_REACTIVATION_SUBMITTED,
{ errors: { personal_key: ['bad_key'] }, success: false },
).once
expect(@analytics).to receive(:track_event).with(
Analytics::THROTTLER_RATE_LIMIT_TRIGGERED,
throttle_type: 'verify_personal_key',
).once

post :create, params: { personal_key: bad_key }
post :create, params: { personal_key: bad_key }
Expand Down
10 changes: 0 additions & 10 deletions spec/features/idv/doc_auth/document_capture_step_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,6 @@
end

it 'throttles calls to acuant and allows retry after the attempt window' do
allow_any_instance_of(ApplicationController).to receive(:analytics).and_return(fake_analytics)
allow(AppConfig.env).to receive(:acuant_max_attempts).and_return(max_attempts)
max_attempts.times do
attach_and_submit_images
Expand All @@ -128,10 +127,6 @@
attach_and_submit_images

expect(page).to have_current_path(idv_session_errors_throttled_path)
expect(fake_analytics).to have_logged_event(
Analytics::THROTTLER_RATE_LIMIT_TRIGGERED,
throttle_type: 'idv_acuant',
)

Timecop.travel(AppConfig.env.acuant_attempt_window_in_minutes.to_i.minutes.from_now) do
sign_in_and_2fa_user(user)
Expand Down Expand Up @@ -194,7 +189,6 @@
end

it 'throttles calls to acuant and allows retry after the attempt window' do
allow_any_instance_of(ApplicationController).to receive(:analytics).and_return(fake_analytics)
allow(AppConfig.env).to receive(:acuant_max_attempts).and_return(max_attempts)
max_attempts.times do
attach_and_submit_images
Expand All @@ -207,10 +201,6 @@
attach_and_submit_images

expect(page).to have_current_path(idv_session_errors_throttled_path)
expect(fake_analytics).to have_logged_event(
Analytics::THROTTLER_RATE_LIMIT_TRIGGERED,
throttle_type: 'idv_acuant',
)

Timecop.travel(AppConfig.env.acuant_attempt_window_in_minutes.to_i.minutes.from_now) do
sign_in_and_2fa_user(user)
Expand Down
10 changes: 0 additions & 10 deletions spec/features/idv/doc_capture/document_capture_step_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,6 @@
end

it 'throttles calls to acuant and allows retry after the attempt window' do
allow_any_instance_of(ApplicationController).to receive(:analytics).and_return(fake_analytics)
IdentityDocAuth::Mock::DocAuthMockClient.mock_response!(
method: :post_front_image,
response: IdentityDocAuth::Response.new(
Expand All @@ -169,10 +168,6 @@
attach_and_submit_images

expect(page).to have_current_path(idv_session_errors_throttled_path)
expect(fake_analytics).to have_logged_event(
Analytics::THROTTLER_RATE_LIMIT_TRIGGERED,
throttle_type: 'idv_acuant',
)

IdentityDocAuth::Mock::DocAuthMockClient.reset!

Expand Down Expand Up @@ -239,7 +234,6 @@
end

it 'throttles calls to acuant and allows retry after the attempt window' do
allow_any_instance_of(ApplicationController).to receive(:analytics).and_return(fake_analytics)
IdentityDocAuth::Mock::DocAuthMockClient.mock_response!(
method: :post_front_image,
response: IdentityDocAuth::Response.new(
Expand All @@ -256,10 +250,6 @@
attach_and_submit_images

expect(page).to have_current_path(idv_session_errors_throttled_path)
expect(fake_analytics).to have_logged_event(
Analytics::THROTTLER_RATE_LIMIT_TRIGGERED,
throttle_type: 'idv_acuant',
)

IdentityDocAuth::Mock::DocAuthMockClient.reset!

Expand Down
1 change: 0 additions & 1 deletion spec/forms/idv/api_document_verification_form_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
document_capture_session_uuid: document_capture_session_uuid,
},
liveness_checking_enabled: liveness_checking_enabled?,
analytics: FakeAnalytics.new,
)
end

Expand Down
36 changes: 0 additions & 36 deletions spec/services/throttler/update_spec.rb

This file was deleted.