From 5832d1141aef869f1c7f79c1877dd38db77b3d89 Mon Sep 17 00:00:00 2001 From: Sonia Connolly Date: Tue, 28 Mar 2023 12:56:53 -0700 Subject: [PATCH 01/12] Redirect to new document capture controller from ssn controller If feature flag is set, redirect back to new controller instead of doc_auth_url. Note: not checking for desktop/mobile/hybrid flow Co-authored-by: Doug Price --- app/controllers/concerns/idv_step_concern.rb | 8 ++++++-- spec/controllers/idv/ssn_controller_spec.rb | 16 ++++++++++++++++ 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/app/controllers/concerns/idv_step_concern.rb b/app/controllers/concerns/idv_step_concern.rb index dc5f3742356..45b8808ce6d 100644 --- a/app/controllers/concerns/idv_step_concern.rb +++ b/app/controllers/concerns/idv_step_concern.rb @@ -12,8 +12,12 @@ def confirm_document_capture_complete @pii = flow_session&.[]('pii_from_doc') # hash with indifferent access return if @pii.present? - flow_session&.delete('Idv::Steps::DocumentCaptureStep') - redirect_to idv_doc_auth_url + if IdentityConfig.store.doc_auth_document_capture_controller_enabled + redirect_to idv_document_capture_url + else + flow_session&.delete('Idv::Steps::DocumentCaptureStep') + redirect_to idv_doc_auth_url + end end def confirm_verify_info_step_complete diff --git a/spec/controllers/idv/ssn_controller_spec.rb b/spec/controllers/idv/ssn_controller_spec.rb index af91a94147f..4287a8c972c 100644 --- a/spec/controllers/idv/ssn_controller_spec.rb +++ b/spec/controllers/idv/ssn_controller_spec.rb @@ -194,7 +194,23 @@ put :update expect(flow_session['Idv::Steps::DocumentCaptureStep']).to eq nil expect(response.status).to eq 302 + expect(response).to redirect_to idv_doc_auth_url end end end + + describe 'doc_auth_document_capture_controller_enabled flag is true' do + before do + allow(IdentityConfig.store).to receive(:doc_auth_document_capture_controller_enabled). + and_return(true) + end + + it 'redirects to document_capture_controller when pii_from_doc is not present' do + flow_session.delete('pii_from_doc') + flow_session['Idv::Steps::DocumentCaptureStep'] = true + put :update + expect(response.status).to eq 302 + expect(response).to redirect_to idv_document_capture_url + end + end end From 730cd8fd595f9af1d7fd999335432410cf757d24 Mon Sep 17 00:00:00 2001 From: Sonia Connolly Date: Tue, 28 Mar 2023 13:47:08 -0700 Subject: [PATCH 02/12] add missing _ to analytics step name Co-authored-by: Eric Gade --- app/controllers/idv/document_capture_controller.rb | 2 +- spec/controllers/idv/document_capture_controller_spec.rb | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/app/controllers/idv/document_capture_controller.rb b/app/controllers/idv/document_capture_controller.rb index 9505554cba6..3566babee26 100644 --- a/app/controllers/idv/document_capture_controller.rb +++ b/app/controllers/idv/document_capture_controller.rb @@ -70,7 +70,7 @@ def confirm_agreement_step_complete def analytics_arguments { flow_path: flow_path, - step: 'document capture', + step: 'document_capture', step_count: current_flow_step_counts['Idv::Steps::DocumentCaptureStep'], analytics_id: 'Doc Auth', irs_reproofing: irs_reproofing?, diff --git a/spec/controllers/idv/document_capture_controller_spec.rb b/spec/controllers/idv/document_capture_controller_spec.rb index 1539520f7d3..7e13c8218ed 100644 --- a/spec/controllers/idv/document_capture_controller_spec.rb +++ b/spec/controllers/idv/document_capture_controller_spec.rb @@ -67,7 +67,7 @@ analytics_id: 'Doc Auth', flow_path: 'standard', irs_reproofing: false, - step: 'document capture', + step: 'document_capture', step_count: 1, } end @@ -118,7 +118,7 @@ analytics_id: 'Doc Auth', flow_path: 'standard', irs_reproofing: false, - step: 'document capture', + step: 'document_capture', step_count: 1, } end From cbb4e3b340251ba8af140e45aa73783d7241b03f Mon Sep 17 00:00:00 2001 From: Sonia Connolly Date: Tue, 28 Mar 2023 13:48:31 -0700 Subject: [PATCH 03/12] redirect to new controller in desktop flow when feature flag is set --- app/services/idv/steps/upload_step.rb | 4 ++++ spec/features/idv/doc_auth/document_capture_spec.rb | 1 - 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/app/services/idv/steps/upload_step.rb b/app/services/idv/steps/upload_step.rb index b5edaec3bd9..441eb068ecb 100644 --- a/app/services/idv/steps/upload_step.rb +++ b/app/services/idv/steps/upload_step.rb @@ -100,6 +100,10 @@ def send_user_to_email_sent_step def bypass_send_link_steps mark_step_complete(:link_sent) mark_step_complete(:email_sent) + if IdentityConfig.store.doc_auth_document_capture_controller_enabled + flow_session[:flow_path] = @flow.flow_path + redirect_to idv_document_capture_url + end form_response(destination: :document_capture) end diff --git a/spec/features/idv/doc_auth/document_capture_spec.rb b/spec/features/idv/doc_auth/document_capture_spec.rb index fa354541058..7ad0a95284a 100644 --- a/spec/features/idv/doc_auth/document_capture_spec.rb +++ b/spec/features/idv/doc_auth/document_capture_spec.rb @@ -24,7 +24,6 @@ sign_in_and_2fa_user(user) complete_doc_auth_steps_before_document_capture_step - visit(idv_document_capture_url) end it 'shows the new DocumentCapture page for desktop standard flow' do From 25873a67322198b230dfdefdb1092ee9f4df1802 Mon Sep 17 00:00:00 2001 From: Sonia Connolly Date: Tue, 28 Mar 2023 14:01:13 -0700 Subject: [PATCH 04/12] Do not redirect to new document_capture_controller in hybrid flow from ssn step changelog: Internal, Flow State Machine replacement, redirect to and from DocumentCaptureController (feature flagged) --- app/controllers/concerns/idv_step_concern.rb | 3 ++- spec/controllers/idv/ssn_controller_spec.rb | 9 +++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/app/controllers/concerns/idv_step_concern.rb b/app/controllers/concerns/idv_step_concern.rb index 45b8808ce6d..fecdbe5e1cb 100644 --- a/app/controllers/concerns/idv_step_concern.rb +++ b/app/controllers/concerns/idv_step_concern.rb @@ -12,7 +12,8 @@ def confirm_document_capture_complete @pii = flow_session&.[]('pii_from_doc') # hash with indifferent access return if @pii.present? - if IdentityConfig.store.doc_auth_document_capture_controller_enabled + if (IdentityConfig.store.doc_auth_document_capture_controller_enabled && + flow_session&.[](:flow_path) == 'standard') redirect_to idv_document_capture_url else flow_session&.delete('Idv::Steps::DocumentCaptureStep') diff --git a/spec/controllers/idv/ssn_controller_spec.rb b/spec/controllers/idv/ssn_controller_spec.rb index 4287a8c972c..113330ea835 100644 --- a/spec/controllers/idv/ssn_controller_spec.rb +++ b/spec/controllers/idv/ssn_controller_spec.rb @@ -212,5 +212,14 @@ expect(response.status).to eq 302 expect(response).to redirect_to idv_document_capture_url end + + it 'in hybrid flow it does not redirect to document_capture_controller' do + flow_session.delete('pii_from_doc') + flow_session['Idv::Steps::DocumentCaptureStep'] = true + flow_session[:flow_path] = 'hybrid' + put :update + expect(response.status).to eq 302 + expect(response).to redirect_to idv_doc_auth_url + end end end From 0e34fc7f119b94d1e6e59f984f0af454c93f12e3 Mon Sep 17 00:00:00 2001 From: Sonia Connolly Date: Tue, 28 Mar 2023 16:21:30 -0700 Subject: [PATCH 05/12] Redirect from document_capture controller to ssn step if session already has pii --- app/controllers/idv/document_capture_controller.rb | 8 ++++++++ .../idv/document_capture_controller_spec.rb | 10 +++++++++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/app/controllers/idv/document_capture_controller.rb b/app/controllers/idv/document_capture_controller.rb index 3566babee26..f953355fc98 100644 --- a/app/controllers/idv/document_capture_controller.rb +++ b/app/controllers/idv/document_capture_controller.rb @@ -8,6 +8,7 @@ class DocumentCaptureController < ApplicationController before_action :render_404_if_document_capture_controller_disabled before_action :confirm_two_factor_authenticated before_action :confirm_agreement_step_complete + before_action :confirm_document_capture_needed before_action :override_document_capture_step_csp def show @@ -67,6 +68,13 @@ def confirm_agreement_step_complete redirect_to idv_doc_auth_url end + def confirm_document_capture_needed + pii = flow_session&.[]('pii_from_doc') # hash with indifferent access + return if pii.blank? + + redirect_to idv_ssn_url + end + def analytics_arguments { flow_path: flow_path, diff --git a/spec/controllers/idv/document_capture_controller_spec.rb b/spec/controllers/idv/document_capture_controller_spec.rb index 7e13c8218ed..86ec3ced25c 100644 --- a/spec/controllers/idv/document_capture_controller_spec.rb +++ b/spec/controllers/idv/document_capture_controller_spec.rb @@ -5,7 +5,6 @@ let(:flow_session) do { 'document_capture_session_uuid' => 'fd14e181-6fb1-4cdc-92e0-ef66dad0df4e', - 'pii_from_doc' => Idp::Constants::MOCK_IDV_APPLICANT.dup, :threatmetrix_session_id => 'c90ae7a5-6629-4e77-b97c-f1987c2df7d0', :flow_path => 'standard', 'Idv::Steps::AgreementStep' => true } @@ -109,6 +108,15 @@ expect(response).to redirect_to(idv_doc_auth_url) end end + + context 'With pii in session' do + it 'redirects to ssn step' do + flow_session['pii_from_doc'] = Idp::Constants::MOCK_IDV_APPLICANT + get :show + + expect(response).to redirect_to(idv_ssn_url) + end + end end describe '#update' do From 7a905265b286258affe98bb4ba502a598773fb82 Mon Sep 17 00:00:00 2001 From: Kimball Bighorse Date: Wed, 29 Mar 2023 10:00:11 -0700 Subject: [PATCH 06/12] Conditionally redirect to document capture url from address step --- app/controllers/idv/address_controller.rb | 7 ++++++- spec/features/idv/doc_auth/address_step_spec.rb | 14 ++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/app/controllers/idv/address_controller.rb b/app/controllers/idv/address_controller.rb index 9492de49ae9..bf6ea14e458 100644 --- a/app/controllers/idv/address_controller.rb +++ b/app/controllers/idv/address_controller.rb @@ -27,7 +27,12 @@ def update def confirm_document_capture_complete @pii = user_session.dig('idv/doc_auth', 'pii_from_doc') return if @pii.present? - redirect_to idv_doc_auth_url + + if IdentityConfig.store.doc_auth_document_capture_controller_enabled + redirect_to idv_document_capture_url + else + redirect_to idv_doc_auth_url + end end def idv_form diff --git a/spec/features/idv/doc_auth/address_step_spec.rb b/spec/features/idv/doc_auth/address_step_spec.rb index b55352e51b2..cb6c82af2c1 100644 --- a/spec/features/idv/doc_auth/address_step_spec.rb +++ b/spec/features/idv/doc_auth/address_step_spec.rb @@ -60,4 +60,18 @@ expect(page).to have_current_path(idv_verify_info_path) end end + + context 'with document capture controller flag set' do + before do + allow(IdentityConfig.store).to receive(:doc_auth_document_capture_controller_enabled). + and_return(true) + sign_in_and_2fa_user + complete_doc_auth_steps_before_document_capture_step + end + + it 'shows address guidance and hint text' do + visit(idv_address_url) + expect(page).to have_current_path(idv_document_capture_url) + end + end end From d57c0cb3a597281cdfc918e1667218b798b62405 Mon Sep 17 00:00:00 2001 From: Sonia Connolly Date: Wed, 29 Mar 2023 13:00:28 -0700 Subject: [PATCH 07/12] From address page, check for standard flow before redirecting to DocumentCaptureController --- app/controllers/idv/address_controller.rb | 5 ++++- spec/features/idv/doc_auth/address_step_spec.rb | 12 +++++++++--- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/app/controllers/idv/address_controller.rb b/app/controllers/idv/address_controller.rb index bf6ea14e458..9a66a7b3b84 100644 --- a/app/controllers/idv/address_controller.rb +++ b/app/controllers/idv/address_controller.rb @@ -28,7 +28,10 @@ def confirm_document_capture_complete @pii = user_session.dig('idv/doc_auth', 'pii_from_doc') return if @pii.present? - if IdentityConfig.store.doc_auth_document_capture_controller_enabled + flow_path = user_session.dig('idv/doc_auth', :flow_path) + + if (IdentityConfig.store.doc_auth_document_capture_controller_enabled && + flow_path == 'standard') redirect_to idv_document_capture_url else redirect_to idv_doc_auth_url diff --git a/spec/features/idv/doc_auth/address_step_spec.rb b/spec/features/idv/doc_auth/address_step_spec.rb index cb6c82af2c1..71a519bbaa7 100644 --- a/spec/features/idv/doc_auth/address_step_spec.rb +++ b/spec/features/idv/doc_auth/address_step_spec.rb @@ -61,17 +61,23 @@ end end - context 'with document capture controller flag set' do + context 'with document capture controller flag set, no PII in session' do before do allow(IdentityConfig.store).to receive(:doc_auth_document_capture_controller_enabled). and_return(true) sign_in_and_2fa_user - complete_doc_auth_steps_before_document_capture_step end - it 'shows address guidance and hint text' do + it 'goes to new document capture page on standard flow' do + complete_doc_auth_steps_before_document_capture_step visit(idv_address_url) expect(page).to have_current_path(idv_document_capture_url) end + + it 'stays in FSM on hybrid flow' do + complete_doc_auth_steps_before_link_sent_step + visit(idv_address_url) + expect(page).to have_current_path(idv_doc_auth_link_sent_step) + end end end From 0103dcec114ab6728aac542a94b6a73b862e0c81 Mon Sep 17 00:00:00 2001 From: Sonia Connolly Date: Wed, 29 Mar 2023 15:14:02 -0700 Subject: [PATCH 08/12] Add specs to check guards against redirecting to document_capture too early or late And check if the VerifyInfo step is complete in confirm_document_capture_needed before action Check in feature specs for ignoring redirects to completed steps --- app/controllers/idv/document_capture_controller.rb | 2 +- .../features/idv/doc_auth/document_capture_spec.rb | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/app/controllers/idv/document_capture_controller.rb b/app/controllers/idv/document_capture_controller.rb index f953355fc98..9c3931a3f29 100644 --- a/app/controllers/idv/document_capture_controller.rb +++ b/app/controllers/idv/document_capture_controller.rb @@ -70,7 +70,7 @@ def confirm_agreement_step_complete def confirm_document_capture_needed pii = flow_session&.[]('pii_from_doc') # hash with indifferent access - return if pii.blank? + return if pii.blank? && !idv_session.verify_info_step_complete? redirect_to idv_ssn_url end diff --git a/spec/features/idv/doc_auth/document_capture_spec.rb b/spec/features/idv/doc_auth/document_capture_spec.rb index 7ad0a95284a..4bc8bb19ba8 100644 --- a/spec/features/idv/doc_auth/document_capture_spec.rb +++ b/spec/features/idv/doc_auth/document_capture_spec.rb @@ -41,6 +41,11 @@ irs_reproofing: false, acuant_sdk_upgrade_ab_test_bucket: :default, ) + + visit(idv_ssn_url) + expect(page).to have_current_path(idv_document_capture_url) + visit(idv_address_url) + expect(page).to have_current_path(idv_document_capture_url) end it 'logs return to sp link click' do @@ -115,6 +120,15 @@ expect(page).to have_current_path(idv_ssn_url) expect_costing_for_document expect(DocAuthLog.find_by(user_id: user.id).state).to eq('MT') + + visit(idv_document_capture_url) + expect(page).to have_current_path(idv_ssn_url) + fill_out_ssn_form_ok + click_idv_continue + complete_verify_step + expect(page).to have_current_path(idv_phone_url) + visit(idv_document_capture_url) + expect(page).to have_current_path(idv_phone_url) end it 'catches network connection errors on post_front_image', allow_browser_log: true do From 49fafffd4741cf885f6744c192d885a814d4df49 Mon Sep 17 00:00:00 2001 From: Sonia Connolly Date: Thu, 30 Mar 2023 08:42:33 -0700 Subject: [PATCH 09/12] Check for UploadStep complete rather than AgreementStep --- app/controllers/idv/document_capture_controller.rb | 6 +++--- .../idv/document_capture_controller_spec.rb | 10 +++++----- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/app/controllers/idv/document_capture_controller.rb b/app/controllers/idv/document_capture_controller.rb index 9c3931a3f29..36aa13bfd55 100644 --- a/app/controllers/idv/document_capture_controller.rb +++ b/app/controllers/idv/document_capture_controller.rb @@ -7,7 +7,7 @@ class DocumentCaptureController < ApplicationController before_action :render_404_if_document_capture_controller_disabled before_action :confirm_two_factor_authenticated - before_action :confirm_agreement_step_complete + before_action :confirm_upload_step_complete before_action :confirm_document_capture_needed before_action :override_document_capture_step_csp @@ -62,8 +62,8 @@ def render_404_if_document_capture_controller_disabled render_not_found unless IdentityConfig.store.doc_auth_document_capture_controller_enabled end - def confirm_agreement_step_complete - return if flow_session['Idv::Steps::AgreementStep'] + def confirm_upload_step_complete + return if flow_session['Idv::Steps::UploadStep'] redirect_to idv_doc_auth_url end diff --git a/spec/controllers/idv/document_capture_controller_spec.rb b/spec/controllers/idv/document_capture_controller_spec.rb index 86ec3ced25c..a2a7f44ecf0 100644 --- a/spec/controllers/idv/document_capture_controller_spec.rb +++ b/spec/controllers/idv/document_capture_controller_spec.rb @@ -7,7 +7,7 @@ { 'document_capture_session_uuid' => 'fd14e181-6fb1-4cdc-92e0-ef66dad0df4e', :threatmetrix_session_id => 'c90ae7a5-6629-4e77-b97c-f1987c2df7d0', :flow_path => 'standard', - 'Idv::Steps::AgreementStep' => true } + 'Idv::Steps::UploadStep' => true } end let(:user) { create(:user) } @@ -42,10 +42,10 @@ ) end - it 'checks that agreement step is complete' do + it 'checks that upload step is complete' do expect(subject).to have_actions( :before, - :confirm_agreement_step_complete, + :confirm_upload_step_complete, ) end end @@ -99,9 +99,9 @@ ) end - context 'agreement step is not complete' do + context 'upload step is not complete' do it 'redirects to idv_doc_auth_url' do - flow_session['Idv::Steps::AgreementStep'] = nil + flow_session['Idv::Steps::UploadStep'] = nil get :show From 7c8581dfe4d2a0af13f984320310932b0544181f Mon Sep 17 00:00:00 2001 From: Sonia Connolly Date: Thu, 30 Mar 2023 10:56:06 -0700 Subject: [PATCH 10/12] Add spec to test required earlier steps and test mobile only flow Co-authored-by: Eric Gade --- .../idv/doc_auth/document_capture_spec.rb | 238 +++++++++++------- 1 file changed, 142 insertions(+), 96 deletions(-) diff --git a/spec/features/idv/doc_auth/document_capture_spec.rb b/spec/features/idv/doc_auth/document_capture_spec.rb index 4bc8bb19ba8..26d4b1281b7 100644 --- a/spec/features/idv/doc_auth/document_capture_spec.rb +++ b/spec/features/idv/doc_auth/document_capture_spec.rb @@ -23,134 +23,180 @@ visit_idp_from_oidc_sp_with_ial2 sign_in_and_2fa_user(user) - complete_doc_auth_steps_before_document_capture_step end - it 'shows the new DocumentCapture page for desktop standard flow' do - expect(page).to have_current_path(idv_document_capture_url) - - expect(page).to have_content(t('doc_auth.headings.document_capture')) - expect(page).to have_content(t('step_indicator.flows.idv.verify_id')) - - expect(fake_analytics).to have_logged_event( - 'IdV: doc auth document_capture visited', - flow_path: 'standard', - step: 'document_capture', - step_count: 1, - analytics_id: 'Doc Auth', - irs_reproofing: false, - acuant_sdk_upgrade_ab_test_bucket: :default, - ) - - visit(idv_ssn_url) - expect(page).to have_current_path(idv_document_capture_url) - visit(idv_address_url) - expect(page).to have_current_path(idv_document_capture_url) + context 'standard desktop flow does not skip ahead' do + before do + visit(idv_document_capture_url) + expect(page).to have_current_path(idv_doc_auth_welcome_step) + complete_welcome_step + visit(idv_document_capture_url) + expect(page).to have_current_path(idv_doc_auth_agreement_step) + complete_agreement_step + visit(idv_document_capture_url) + expect(page).to have_current_path(idv_doc_auth_upload_step) + end end - it 'logs return to sp link click' do - new_window = window_opened_by do - click_on t('idv.troubleshooting.options.get_help_at_sp', sp_name: sp_name) + context 'standard desktop flow' do + before do + complete_doc_auth_steps_before_document_capture_step end - within_window new_window do + it 'shows the new DocumentCapture page for desktop standard flow' do + expect(page).to have_current_path(idv_document_capture_url) + + expect(page).to have_content(t('doc_auth.headings.document_capture')) + expect(page).to have_content(t('step_indicator.flows.idv.verify_id')) + expect(fake_analytics).to have_logged_event( - 'Return to SP: Failed to proof', - flow: nil, - location: 'document_capture_troubleshooting_options', - redirect_url: instance_of(String), + 'IdV: doc auth document_capture visited', + flow_path: 'standard', step: 'document_capture', + step_count: 1, + analytics_id: 'Doc Auth', + irs_reproofing: false, + acuant_sdk_upgrade_ab_test_bucket: :default, ) + + visit(idv_ssn_url) + expect(page).to have_current_path(idv_document_capture_url) + visit(idv_address_url) + expect(page).to have_current_path(idv_document_capture_url) end - end - context 'throttles calls to acuant', allow_browser_log: true do - let(:fake_attempts_tracker) { IrsAttemptsApiTrackingHelper::FakeAttemptsTracker.new } - before do - allow_any_instance_of(ApplicationController).to receive( - :irs_attempts_api_tracker, - ).and_return(fake_attempts_tracker) - allow(fake_attempts_tracker).to receive(:idv_document_upload_rate_limited) - allow(IdentityConfig.store).to receive(:doc_auth_max_attempts).and_return(max_attempts) - DocAuth::Mock::DocAuthMockClient.mock_response!( - method: :post_front_image, - response: DocAuth::Response.new( - success: false, - errors: { network: I18n.t('doc_auth.errors.general.network_error') }, - ), - ) + it 'logs return to sp link click' do + new_window = window_opened_by do + click_on t('idv.troubleshooting.options.get_help_at_sp', sp_name: sp_name) + end - (max_attempts - 1).times do - attach_and_submit_images - click_on t('idv.failure.button.warning') + within_window new_window do + expect(fake_analytics).to have_logged_event( + 'Return to SP: Failed to proof', + flow: nil, + location: 'document_capture_troubleshooting_options', + redirect_url: instance_of(String), + step: 'document_capture', + ) end end - it 'redirects to the throttled error page' do - freeze_time do + context 'throttles calls to acuant', allow_browser_log: true do + let(:fake_attempts_tracker) { IrsAttemptsApiTrackingHelper::FakeAttemptsTracker.new } + before do + allow_any_instance_of(ApplicationController).to receive( + :irs_attempts_api_tracker, + ).and_return(fake_attempts_tracker) + allow(fake_attempts_tracker).to receive(:idv_document_upload_rate_limited) + allow(IdentityConfig.store).to receive(:doc_auth_max_attempts).and_return(max_attempts) + DocAuth::Mock::DocAuthMockClient.mock_response!( + method: :post_front_image, + response: DocAuth::Response.new( + success: false, + errors: { network: I18n.t('doc_auth.errors.general.network_error') }, + ), + ) + + (max_attempts - 1).times do + attach_and_submit_images + click_on t('idv.failure.button.warning') + end + end + + it 'redirects to the throttled error page' do + freeze_time do + attach_and_submit_images + timeout = distance_of_time_in_words( + Throttle.attempt_window_in_minutes(:idv_doc_auth).minutes, + ) + message = strip_tags(t('errors.doc_auth.throttled_text_html', timeout: timeout)) + expect(page).to have_content(message) + expect(page).to have_current_path(idv_session_errors_throttled_path) + end + end + + it 'logs the throttled analytics event for doc_auth' do attach_and_submit_images - timeout = distance_of_time_in_words( - Throttle.attempt_window_in_minutes(:idv_doc_auth).minutes, + expect(fake_analytics).to have_logged_event( + 'Throttler Rate Limit Triggered', + throttle_type: :idv_doc_auth, ) - message = strip_tags(t('errors.doc_auth.throttled_text_html', timeout: timeout)) - expect(page).to have_content(message) - expect(page).to have_current_path(idv_session_errors_throttled_path) end - end - it 'logs the throttled analytics event for doc_auth' do - attach_and_submit_images - expect(fake_analytics).to have_logged_event( - 'Throttler Rate Limit Triggered', - throttle_type: :idv_doc_auth, - ) + it 'logs irs attempts event for rate limiting' do + attach_and_submit_images + expect(fake_attempts_tracker).to have_received(:idv_document_upload_rate_limited) + end end - it 'logs irs attempts event for rate limiting' do + it 'proceeds to the next page with valid info' do + expect_step_indicator_current_step(t('step_indicator.flows.idv.verify_id')) + attach_and_submit_images - expect(fake_attempts_tracker).to have_received(:idv_document_upload_rate_limited) + + expect(page).to have_current_path(idv_ssn_url) + expect_costing_for_document + expect(DocAuthLog.find_by(user_id: user.id).state).to eq('MT') + + visit(idv_document_capture_url) + expect(page).to have_current_path(idv_ssn_url) + fill_out_ssn_form_ok + click_idv_continue + complete_verify_step + expect(page).to have_current_path(idv_phone_url) + visit(idv_document_capture_url) + expect(page).to have_current_path(idv_phone_url) end - end - it 'proceeds to the next page with valid info' do - expect_step_indicator_current_step(t('step_indicator.flows.idv.verify_id')) + it 'catches network connection errors on post_front_image', allow_browser_log: true do + DocAuth::Mock::DocAuthMockClient.mock_response!( + method: :post_front_image, + response: DocAuth::Response.new( + success: false, + errors: { network: I18n.t('doc_auth.errors.general.network_error') }, + ), + ) - attach_and_submit_images + attach_and_submit_images - expect(page).to have_current_path(idv_ssn_url) - expect_costing_for_document - expect(DocAuthLog.find_by(user_id: user.id).state).to eq('MT') + expect(page).to have_current_path(idv_document_capture_url) + expect(page).to have_content(I18n.t('doc_auth.errors.general.network_error')) + end - visit(idv_document_capture_url) - expect(page).to have_current_path(idv_ssn_url) - fill_out_ssn_form_ok - click_idv_continue - complete_verify_step - expect(page).to have_current_path(idv_phone_url) - visit(idv_document_capture_url) - expect(page).to have_current_path(idv_phone_url) - end + it 'does not track state if state tracking is disabled' do + allow(IdentityConfig.store).to receive(:state_tracking_enabled).and_return(false) + attach_and_submit_images - it 'catches network connection errors on post_front_image', allow_browser_log: true do - DocAuth::Mock::DocAuthMockClient.mock_response!( - method: :post_front_image, - response: DocAuth::Response.new( - success: false, - errors: { network: I18n.t('doc_auth.errors.general.network_error') }, - ), - ) + expect(DocAuthLog.find_by(user_id: user.id).state).to be_nil + end + end - attach_and_submit_images + context 'standard mobile flow' do + it 'proceeds to the next page with valid info' do + perform_in_browser(:mobile) do + visit_idp_from_oidc_sp_with_ial2 + sign_in_and_2fa_user(user) + complete_doc_auth_steps_before_document_capture_step - expect(page).to have_current_path(idv_document_capture_url) - expect(page).to have_content(I18n.t('doc_auth.errors.general.network_error')) - end + expect(page).to have_current_path(idv_document_capture_url) + expect_step_indicator_current_step(t('step_indicator.flows.idv.verify_id')) - it 'does not track state if state tracking is disabled' do - allow(IdentityConfig.store).to receive(:state_tracking_enabled).and_return(false) - attach_and_submit_images + attach_and_submit_images - expect(DocAuthLog.find_by(user_id: user.id).state).to be_nil + expect(page).to have_current_path(idv_ssn_url) + expect_costing_for_document + expect(DocAuthLog.find_by(user_id: user.id).state).to eq('MT') + + visit(idv_document_capture_url) + expect(page).to have_current_path(idv_ssn_url) + fill_out_ssn_form_ok + click_idv_continue + complete_verify_step + expect(page).to have_current_path(idv_phone_url) + visit(idv_document_capture_url) + expect(page).to have_current_path(idv_phone_url) + end + end end def expect_costing_for_document From 46c9cb49832685a5fc2474721d9f353bfde7fe64 Mon Sep 17 00:00:00 2001 From: Sonia Connolly Date: Fri, 31 Mar 2023 09:08:48 -0700 Subject: [PATCH 11/12] Update spec/controllers/idv/document_capture_controller_spec.rb Capitalization change in spec. Co-authored-by: Zach Margolis --- spec/controllers/idv/document_capture_controller_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/controllers/idv/document_capture_controller_spec.rb b/spec/controllers/idv/document_capture_controller_spec.rb index a2a7f44ecf0..b757586cfa1 100644 --- a/spec/controllers/idv/document_capture_controller_spec.rb +++ b/spec/controllers/idv/document_capture_controller_spec.rb @@ -109,7 +109,7 @@ end end - context 'With pii in session' do + context 'with pii in session' do it 'redirects to ssn step' do flow_session['pii_from_doc'] = Idp::Constants::MOCK_IDV_APPLICANT get :show From 03a02d4806d1cfccb920db484736d332bce6bafd Mon Sep 17 00:00:00 2001 From: Sonia Connolly Date: Fri, 31 Mar 2023 09:21:18 -0700 Subject: [PATCH 12/12] Readability changes --- app/controllers/concerns/idv_step_concern.rb | 6 ++++-- app/controllers/idv/address_controller.rb | 4 ++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/app/controllers/concerns/idv_step_concern.rb b/app/controllers/concerns/idv_step_concern.rb index fecdbe5e1cb..9f10dfdf291 100644 --- a/app/controllers/concerns/idv_step_concern.rb +++ b/app/controllers/concerns/idv_step_concern.rb @@ -12,8 +12,10 @@ def confirm_document_capture_complete @pii = flow_session&.[]('pii_from_doc') # hash with indifferent access return if @pii.present? - if (IdentityConfig.store.doc_auth_document_capture_controller_enabled && - flow_session&.[](:flow_path) == 'standard') + flow_path = flow_session&.[](:flow_path) + + if IdentityConfig.store.doc_auth_document_capture_controller_enabled && + flow_path == 'standard' redirect_to idv_document_capture_url else flow_session&.delete('Idv::Steps::DocumentCaptureStep') diff --git a/app/controllers/idv/address_controller.rb b/app/controllers/idv/address_controller.rb index 9a66a7b3b84..9c07d69ed6c 100644 --- a/app/controllers/idv/address_controller.rb +++ b/app/controllers/idv/address_controller.rb @@ -30,8 +30,8 @@ def confirm_document_capture_complete flow_path = user_session.dig('idv/doc_auth', :flow_path) - if (IdentityConfig.store.doc_auth_document_capture_controller_enabled && - flow_path == 'standard') + if IdentityConfig.store.doc_auth_document_capture_controller_enabled && + flow_path == 'standard' redirect_to idv_document_capture_url else redirect_to idv_doc_auth_url