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
11 changes: 3 additions & 8 deletions app/controllers/concerns/rate_limit_concern.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ module RateLimitConcern

ALL_IDV_RATE_LIMITERS = [:idv_resolution, :idv_doc_auth, :proof_ssn].freeze

def confirm_not_rate_limited(rate_limiters = ALL_IDV_RATE_LIMITERS)
def confirm_not_rate_limited(rate_limiters = ALL_IDV_RATE_LIMITERS, check_last_submission: false)
exceeded_rate_limits = check_for_exceeded_rate_limits(rate_limiters)
if exceeded_rate_limits.any? && !final_hybrid_submission_passed?
if exceeded_rate_limits.any? && !(check_last_submission && final_submission_passed?)
rate_limit_redirect!(exceeded_rate_limits.first)
return true
end
Expand All @@ -28,18 +28,13 @@ def confirm_not_rate_limited_for_phone_address_verification

private

def final_hybrid_submission_passed?
def final_submission_passed?
doc_session_idv = user_session.to_h['idv']
return false if doc_session_idv.blank?

doc_session_uuid = doc_session_idv['document_capture_session_uuid']
return false if doc_session_uuid.blank?

flow_path = doc_session_idv['flow_path']
return false if flow_path.blank?

return false if flow_path != 'hybrid'

Comment on lines -38 to -42
Copy link
Contributor

Choose a reason for hiding this comment

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

👍🏿

document_capture_session = DocumentCaptureSession.find_by(uuid: doc_session_uuid)
return false if document_capture_session.nil?

Expand Down
5 changes: 4 additions & 1 deletion app/controllers/idv/link_sent_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ class LinkSentController < ApplicationController
include IdvStepConcern
include StepIndicatorConcern

before_action :confirm_not_rate_limited
before_action -> do
confirm_not_rate_limited(check_last_submission: true)
end

before_action :confirm_step_allowed

def show
Expand Down
15 changes: 6 additions & 9 deletions app/controllers/idv/socure/document_capture_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,18 @@ class DocumentCaptureController < ApplicationController
include RenderConditionConcern

check_or_render_not_found -> { IdentityConfig.store.socure_docv_enabled }
before_action :confirm_not_rate_limited

before_action :confirm_not_rate_limited, except: :update
before_action -> do
confirm_not_rate_limited(check_last_submission: true)
end, only: :update

before_action :confirm_step_allowed
before_action -> do
redirect_to_correct_vendor(Idp::Constants::Vendors::SOCURE, in_hybrid_mobile: false)
end, only: :show
before_action :fetch_test_verification_data, only: [:update]

# reconsider and maybe remove these when implementing the real
# update handler
skip_before_action :redirect_unless_idv_session_user, only: [:update]
skip_before_action :confirm_two_factor_authenticated, only: [:update]
skip_before_action :confirm_idv_needed, only: [:update]
skip_before_action :confirm_not_rate_limited, only: [:update]
skip_before_action :confirm_step_allowed, only: [:update]

def show
idv_session.socure_docv_wait_polling_started_at = nil

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,8 @@

describe '#update' do
before do
stub_sign_in(user)
subject.idv_session.flow_path = 'standard'
get :update
end

Expand Down
45 changes: 26 additions & 19 deletions spec/features/idv/doc_auth/socure_document_capture_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -114,25 +114,29 @@
end
end

it 'redirects to the rate limited error page' do
# recovers when fails to repeat webhook to an endpoint
allow_any_instance_of(DocAuth::Socure::WebhookRepeater)
.to receive(:send_http_post_request).and_raise('doh')
expect(page).to have_current_path(fake_socure_document_capture_app_url)
visit idv_socure_document_capture_path
expect(page).to have_current_path(idv_socure_document_capture_path)
socure_docv_upload_documents(
docv_transaction_token: @docv_transaction_token,
)
visit idv_socure_document_capture_path
expect(page).to have_current_path(idv_session_errors_rate_limited_path)
expect(fake_analytics).to have_logged_event(
'Rate Limit Reached',
limiter_type: :idv_doc_auth,
)
expect(fake_analytics).to have_logged_event(
:idv_socure_document_request_submitted,
)
context 'when we fail on the last attempt' do
before do
allow_any_instance_of(DocAuth::Socure::WebhookRepeater)
.to receive(:send_http_post_request).and_raise('doh')
end

it 'redirects to the rate limited error page' do
expect(page).to have_current_path(fake_socure_document_capture_app_url)
visit idv_socure_document_capture_path
expect(page).to have_current_path(idv_socure_document_capture_path)
socure_docv_upload_documents(
docv_transaction_token: @docv_transaction_token,
)
visit idv_socure_document_capture_path
expect(page).to have_current_path(idv_session_errors_rate_limited_path)
expect(fake_analytics).to have_logged_event(
'Rate Limit Reached',
limiter_type: :idv_doc_auth,
)
expect(fake_analytics).to have_logged_event(
:idv_socure_document_request_submitted,
)
end
end

context 'successfully processes image on last attempt' do
Expand All @@ -147,6 +151,9 @@
socure_docv_upload_documents(
docv_transaction_token: @docv_transaction_token,
)
DocumentCaptureSession.find_by(user_id: @user.id).update(
last_doc_auth_result: 'Passed',
)
Comment on lines +154 to +156
Copy link
Contributor

@amirbey amirbey Feb 10, 2025

Choose a reason for hiding this comment

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

looking at the code this does not appear to happen in the Socure flow 🤔 ... which Is why this workaround is happening manually here
will address this in a follow up issue


visit idv_socure_document_capture_update_path
expect(page).to have_current_path(idv_ssn_url)
Expand Down