-
Notifications
You must be signed in to change notification settings - Fork 166
Document capture #6457
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
Merged
Merged
Document capture #6457
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
8922b17
LG-6397 - create api request to handle document capture
peggles2 d32ef26
changelog: Improvements, Document Capture, Add API for document capture
peggles2 a98df0c
remove document_status_token
peggles2 edda8d0
pass flow_path as a parameter
peggles2 f0226ac
update test
peggles2 201390e
code review feedbacks
peggles2 9c70209
add track event
peggles2 9c1bc33
code review feedback
peggles2 7da6478
update analytics
peggles2 57fa152
updates from code review feedbacks
peggles2 ae88bcd
fix rspec test
peggles2 e5f2d63
pass the uuid parameters
peggles2 e974ad9
update error checking
peggles2 e15f48f
fix linter error
peggles2 6dfa5ea
code review feedbacks
peggles2 7d1d171
fix linter errors
peggles2 f1c5339
fix linter errors
peggles2 549e5b1
code review feedback
peggles2 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,80 @@ | ||
| module Api | ||
| module Verify | ||
| class DocumentCaptureController < BaseController | ||
| self.required_step = 'document_capture' | ||
| include ApplicationHelper | ||
| include EffectiveUser | ||
|
peggles2 marked this conversation as resolved.
|
||
|
|
||
| def create | ||
| result = Idv::ApiDocumentVerificationForm.new( | ||
| verify_params, | ||
| liveness_checking_enabled: liveness_checking_enabled?, | ||
| analytics: analytics, | ||
| ).submit | ||
|
|
||
| if result.success? | ||
| enqueue_job | ||
|
|
||
| render json: { | ||
| status: 'in_progress', | ||
| }, status: :ok | ||
| else | ||
| render_errors(result.errors) | ||
| end | ||
| end | ||
|
|
||
| private | ||
|
|
||
| def enqueue_job | ||
| verify_document_capture_session = DocumentCaptureSession. | ||
| find_by(uuid: params[:document_capture_session_uuid]) | ||
| verify_document_capture_session.requested_at = Time.zone.now | ||
| verify_document_capture_session.create_doc_auth_session | ||
|
|
||
| document_attributes = verify_params.to_h | ||
| applicant = { | ||
| user_uuid: effective_user.uuid, | ||
| uuid_prefix: current_sp&.app_id, | ||
| document_arguments: document_attributes, | ||
| } | ||
| Idv::Agent.new(applicant).proof_document( | ||
| verify_document_capture_session, | ||
| liveness_checking_enabled: liveness_checking_enabled?, | ||
| trace_id: amzn_trace_id, | ||
| image_metadata: image_metadata, | ||
| analytics_data: { | ||
| browser_attributes: analytics.browser_attributes, | ||
| }, | ||
| flow_path: params[:flow_path], | ||
| ) | ||
| nil | ||
| end | ||
|
|
||
| def verify_params | ||
| params.permit( | ||
| :encryption_key, | ||
| :front_image_iv, | ||
| :back_image_iv, | ||
| :selfie_image_iv, | ||
| :front_image_url, | ||
| :back_image_url, | ||
| :selfie_image_url, | ||
| :document_capture_session_uuid, | ||
| :flow_path, | ||
| ) | ||
| end | ||
|
|
||
| def image_metadata | ||
| params.permit(:front_image_metadata, :back_image_metadata). | ||
| to_h. | ||
| transform_values do |str| | ||
| JSON.parse(str, symbolize_names: true) | ||
| rescue JSON::ParserError | ||
| nil | ||
| end. | ||
| compact. | ||
| transform_keys { |key| key.gsub(/_image_metadata$/, '') } | ||
|
peggles2 marked this conversation as resolved.
|
||
| end | ||
| end | ||
| end | ||
| end | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
101 changes: 101 additions & 0 deletions
101
spec/controllers/api/verify/document_capture_controller_spec.rb
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,101 @@ | ||
| require 'rails_helper' | ||
|
|
||
| describe Api::Verify::DocumentCaptureController do | ||
| include PersonalKeyValidator | ||
| include SamlAuthHelper | ||
|
|
||
| let(:encryption_key) { 'encryption-key' } | ||
| let(:front_image_url) { 'http://example.com/front' } | ||
| let(:front_image_iv) { 'front-iv' } | ||
| let(:back_image_url) { 'http://example.com/back' } | ||
| let(:back_image_iv) { 'back-iv' } | ||
| let(:selfie_image_url) { 'http://example.com/selfie' } | ||
| let(:selfie_image_iv) { 'selfie-iv' } | ||
| let(:front_image_metadata) do | ||
| { width: 40, height: 40, mimeType: 'image/png', source: 'upload' } | ||
| end | ||
| let(:back_image_metadata) do | ||
| { width: 20, height: 20, mimeType: 'image/png', source: 'upload' } | ||
| end | ||
| let(:image_metadata) { { front: front_image_metadata, back: back_image_metadata } } | ||
| let!(:document_capture_session) { DocumentCaptureSession.create!(user: create(:user)) } | ||
| let(:document_capture_session_uuid) { document_capture_session.uuid } | ||
| let(:password) { 'iambatman' } | ||
| let(:user) { create(:user, :signed_up) } | ||
| let(:flow_path) { 'standard' } | ||
| let(:liveness_checking_enabled) { false } | ||
| let(:analytics_data) { | ||
| { browser_attributes: | ||
| { browser_bot: false, | ||
| browser_device_name: 'Unknown', | ||
| browser_mobile: false, | ||
| browser_name: 'Unknown Browser', | ||
| browser_platform_name: 'Unknown', | ||
| browser_platform_version: '0', | ||
| browser_version: '0.0', | ||
| user_agent: 'Rails Testing' } } | ||
| } | ||
|
|
||
| before do | ||
| allow(IdentityConfig.store).to receive(:idv_api_enabled_steps).and_return(['document_capture']) | ||
| stub_sign_in(user) | ||
| end | ||
|
|
||
| describe '#create' do | ||
| context 'When user document is submitted to be verified ' do | ||
| it 'returns inprogress status when create is called' do | ||
| agent = instance_double(Idv::Agent) | ||
| allow(Idv::Agent).to receive(:new).and_return(agent) | ||
|
|
||
| expect(agent).to receive(:proof_document).with( | ||
| document_capture_session, | ||
| liveness_checking_enabled: liveness_checking_enabled, | ||
| trace_id: nil, | ||
| image_metadata: image_metadata, | ||
| analytics_data: analytics_data, | ||
| flow_path: flow_path, | ||
| ) | ||
|
|
||
| post :create, params: { | ||
| encryption_key: encryption_key, | ||
| front_image_iv: front_image_iv, | ||
| back_image_iv: back_image_iv, | ||
| selfie_image_iv: selfie_image_iv, | ||
| front_image_url: front_image_url, | ||
| back_image_url: back_image_url, | ||
| selfie_image_url: selfie_image_url, | ||
| front_image_metadata: front_image_metadata.to_json, | ||
| back_image_metadata: back_image_metadata.to_json, | ||
| document_capture_session_uuid: document_capture_session_uuid, | ||
| flow_path: flow_path, | ||
| } | ||
| expect(JSON.parse(response.body)['status']).to eq('in_progress') | ||
| expect(response.status).to eq 200 | ||
| end | ||
|
|
||
| context 'When the request does not have all the parameters' do | ||
| it 'returns 400 and gives error message' do | ||
| agent = instance_double(Idv::Agent) | ||
| allow(Idv::Agent).to receive(:new).and_return(agent) | ||
| expect(agent).to_not receive(:proof_document) | ||
|
|
||
| post :create, params: { | ||
| encryption_key: encryption_key, | ||
| front_image_iv: nil, | ||
| back_image_iv: back_image_iv, | ||
| selfie_image_iv: selfie_image_iv, | ||
| front_image_url: front_image_url, | ||
| back_image_url: back_image_url, | ||
| selfie_image_url: selfie_image_url, | ||
| document_capture_session_uuid: document_capture_session_uuid, | ||
| } | ||
|
|
||
| expect(JSON.parse(response.body)['errors'].keys.first).to eq('front_image_iv') | ||
| expect(JSON.parse(response.body)['errors']['front_image_iv'][0]). | ||
| to eq('Please fill in this field.') | ||
| expect(response.status).to eq 400 | ||
| end | ||
| end | ||
| end | ||
| end | ||
| end |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.