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/controllers/api/verify/document_capture_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ def create
verify_params,
liveness_checking_enabled: liveness_checking_enabled?,
analytics: analytics,
irs_attempts_api_tracker: irs_attempts_api_tracker,
).submit

if result.success?
Expand Down
10 changes: 9 additions & 1 deletion app/forms/idv/api_document_verification_form.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,17 @@ class ApiDocumentVerificationForm

validate :throttle_if_rate_limited

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

Expand Down Expand Up @@ -88,6 +95,7 @@ def valid_url?(key)
def throttle_if_rate_limited
return unless @throttled
@analytics.throttler_rate_limit_triggered(throttle_type: :idv_doc_auth)
@irs_attempts_api_tracker.idv_document_upload_rate_limited
errors.add(:limit, t('errors.doc_auth.throttled_heading'), type: :throttled)
end

Expand Down
1 change: 1 addition & 0 deletions app/forms/idv/api_image_upload_form.rb
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ def validate_images
def throttle_if_rate_limited
return unless @throttled
analytics.throttler_rate_limit_triggered(throttle_type: :idv_doc_auth)
irs_attempts_api_tracker.idv_document_upload_rate_limited
errors.add(:limit, t('errors.doc_auth.throttled_heading'), type: :throttled)
end

Expand Down
1 change: 1 addition & 0 deletions app/services/idv/steps/doc_auth_base_step.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ def throttled_response
@flow.analytics.throttler_rate_limit_triggered(
throttle_type: :idv_doc_auth,
)
@flow.irs_attempts_api_tracker.idv_document_upload_rate_limited
redirect_to throttled_url
DocAuth::Response.new(
success: false,
Expand Down
7 changes: 7 additions & 0 deletions app/services/irs_attempts_api/tracker_events.rb
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,13 @@ def idv_document_upload_submitted(
)
end

# The user has exceeded the rate limit during idv document upload
def idv_document_upload_rate_limited
track_event(
:idv_document_upload_rate_limited,
)
end

# @param [Boolean] success
# @param [String] phone_number
# The phone upload link was sent during the IDV process
Expand Down
2 changes: 2 additions & 0 deletions spec/features/idv/doc_auth/document_capture_step_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
let(:liveness_enabled) { false }
let(:doc_auth_enable_presigned_s3_urls) { false }
let(:fake_analytics) { FakeAnalytics.new }
let(:fake_attempts_tracker) { IrsAttemptsApiTrackingHelper::FakeAttemptsTracker.new }
let(:sp_name) { 'Test SP' }
before do
allow(IdentityConfig.store).to receive(:liveness_checking_enabled).
Expand Down Expand Up @@ -74,6 +75,7 @@
# 'Throttler Rate Limit Triggered',
# throttle_type: :idv_doc_auth,
# )
# expect(fake_attempts_tracker).to receive(:idv_document_upload_rate_limited)
end

it 'catches network connection errors on post_front_image', allow_browser_log: true do
Expand Down
3 changes: 3 additions & 0 deletions spec/forms/idv/api_document_verification_form_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
},
liveness_checking_enabled: liveness_checking_enabled?,
analytics: analytics,
irs_attempts_api_tracker: irs_attempts_api_tracker,
)
end

Expand All @@ -28,6 +29,7 @@
let!(:document_capture_session) { DocumentCaptureSession.create!(user: create(:user)) }
let(:document_capture_session_uuid) { document_capture_session.uuid }
let(:analytics) { FakeAnalytics.new }
let(:irs_attempts_api_tracker) { IrsAttemptsApiTrackingHelper::FakeAttemptsTracker.new }
let(:liveness_checking_enabled?) { true }

describe '#valid?' do
Expand Down Expand Up @@ -121,6 +123,7 @@
end

it 'is not valid' do
expect(irs_attempts_api_tracker).to receive(:idv_document_upload_rate_limited)
expect(form.valid?).to eq(false)
expect(form.errors.attribute_names).to eq([:limit])
expect(form.errors[:limit]).to eq([I18n.t('errors.doc_auth.throttled_heading')])
Expand Down
1 change: 1 addition & 0 deletions spec/forms/idv/api_image_upload_form_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@
end

it 'is not valid' do
expect(irs_attempts_api_tracker).to receive(:idv_document_upload_rate_limited)
expect(form.valid?).to eq(false)
expect(form.errors[:limit]).to eq([I18n.t('errors.doc_auth.throttled_heading')])
end
Expand Down