Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a mocked version of Socure docauth #11698

Closed
wants to merge 1 commit into from
Closed
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: 2 additions & 0 deletions app/controllers/concerns/idv/document_capture_concern.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ def redirect_to_correct_vendor(vendor, in_hybrid_mobile)
when Idp::Constants::Vendors::SOCURE
in_hybrid_mobile ? idv_hybrid_mobile_socure_document_capture_path
: idv_socure_document_capture_path
when Idp::Constants::Vendors::MOCK_SOCURE
test_mock_socure_url(hybrid: in_hybrid_mobile ? 1 : 0)
when Idp::Constants::Vendors::LEXIS_NEXIS, Idp::Constants::Vendors::MOCK
in_hybrid_mobile ? idv_hybrid_mobile_document_capture_path
: idv_document_capture_path
Expand Down
2 changes: 2 additions & 0 deletions app/controllers/idv/hybrid_mobile/entry_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ def show
case doc_auth_vendor
when Idp::Constants::Vendors::SOCURE
redirect_to idv_hybrid_mobile_socure_document_capture_url
when Idp::Constants::Vendors::MOCK_SOCURE
redirect_to test_mock_socure_url(hybrid: 1)
when Idp::Constants::Vendors::MOCK, Idp::Constants::Vendors::LEXIS_NEXIS
redirect_to idv_hybrid_mobile_document_capture_url
end
Expand Down
109 changes: 109 additions & 0 deletions app/controllers/test/mock_socure_document_capture_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
# frozen_string_literal: true

module Test
class MockSocureDocumentCaptureController < ApplicationController
before_action :check_not_in_prod

def show
if verify?
simulate_socure_docv
return
end

@url = test_mock_socure_url(verify: 1, hybrid: hybrid? ? 1 : 0)
end

private

def check_not_in_prod
render_not_found if Rails.env.production?
Copy link
Member

Choose a reason for hiding this comment

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

All deployed environments (including sandbox environments) are considered production. Is that the behavior we're expecting? I see we're also only registering this route if enable_test_routes is enabled.

I'd wonder if either (a) this isn't needed since we're only registering the route in environments with test routes enabled, or (b) we could rename this to clarify "deployed environments" instead of "production" to try to preempt any potential future misunderstandings.

end

def build_fake_docv_result_response
DocAuth::Socure::Responses::DocvResultResponse.new(
http_response: Struct.new(:body, keyword_init: true).new(
body: JSON.generate(
{
referenceId: SecureRandom.uuid,
documentVerification: {
customerProfile: {
customerUserId: '',
userId: SecureRandom.uuid,
},
decision: {
name: '',
value: 'accept',
},
documentData: {
dob: '1938-01-01',
documentNumber: 'ABCD-1234',
expirationDate: (Time.zone.now + 1.year).to_date,
firstName: 'Joey',
issueDate: 3.years.ago.to_date,
middleName: 'Joe-Joe',
surName: 'Junior Shabbadoo',
parsedAddress: {
physicalAddress: '1234 Fake St.',
physicalAddress2: 'Unit 99',
city: 'Fakeville',
state: 'CA',
zip: '90210',
},
},
documentType: {
state: 'WA',
country: 'US',
},
reasonCodes: [],
},

},
),
),
)
end

def document_capture_session
DocumentCaptureSession.find_by(
uuid: if idv_session.present?
idv_session.document_capture_session_uuid
else
session[:document_capture_session_uuid]
end,
)
end

def hybrid?
params[:hybrid].to_i == 1
end

def idv_session
return nil if user_session.nil?

@idv_session ||= Idv::Session.new(
user_session: user_session,
current_user: current_user,
service_provider: current_sp,
)
end

def simulate_socure_docv
# Fake what the Socure webhook processor would've done.
# TODO: It'd be cool to just call the webhook processing code here

document_capture_session.store_result_from_response(
build_fake_docv_result_response,
)

if hybrid?
redirect_to idv_hybrid_mobile_capture_complete_url
else
redirect_to idv_socure_document_capture_update_url
end
end

def verify?
params[:verify].to_i == 1
end
end
end
6 changes: 6 additions & 0 deletions app/views/idv/shared/_doc_capture_interstitial.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@
) %>
<% end %>

<% if local_assigns.fetch(:show_test_mode_warning, false) %>
<p>
<marquee class="bg-accent-warm" ><strong>FOR TESTING ONLY.</strong> This will only <strong>simulate</strong> verifying your documents.</marquee>
Copy link
Contributor

Choose a reason for hiding this comment

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

<marquee> LOL

</p>
<% end %>

<%= render PageHeadingComponent.new do %>
<%= t('doc_auth.headings.verify_with_phone') %>
<% end %>
Expand Down
1 change: 1 addition & 0 deletions app/views/test/mock_socure_document_capture/show.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<%= render 'idv/shared/doc_capture_interstitial', show_test_mode_warning: true %>
2 changes: 2 additions & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,8 @@
put '/s3/:key' => 'fake_s3#update'

get '/session_data' => 'session_data#index'

get '/mock_socure' => 'mock_socure_document_capture#show'
end
end

Expand Down
1 change: 1 addition & 0 deletions lib/idp/constants.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ module Vendors
LEXIS_NEXIS = 'lexis_nexis'
SOCURE = 'socure'
MOCK = 'mock'
MOCK_SOCURE = 'mock_socure'
USPS = 'usps'
AAMVA = 'aamva'
AAMVA_UNSUPPORTED_JURISDICTION = 'UnsupportedJurisdiction'
Expand Down