Skip to content

Commit

Permalink
Initial crack at mock socure doc auth
Browse files Browse the repository at this point in the history
Add a development-only mock socure doc auth implementation.

[skip changelog]
  • Loading branch information
matthinz committed Dec 31, 2024
1 parent a9e50e4 commit 6a63ca6
Show file tree
Hide file tree
Showing 7 changed files with 123 additions and 0 deletions.
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?
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>
</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

0 comments on commit 6a63ca6

Please sign in to comment.