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
6 changes: 3 additions & 3 deletions app/presenters/image_upload_response_presenter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def as_json(*)
end
json[:hints] = true if show_hints?
json[:ocr_pii] = ocr_pii
json[:result_failed] = doc_auth_failed?
json[:result_failed] = doc_auth_result_failed?
json[:result_code_invalid] = result_code_invalid?
json[:doc_type_supported] = doc_type_supported?
json[:selfie_status] = selfie_status if show_selfie_failures?
Expand All @@ -73,8 +73,8 @@ def result_code_invalid?
!attention_with_barcode?
end

def doc_auth_failed?
@form_response.to_h[:transaction_status] == 'failed'
def doc_auth_result_failed?
@form_response.to_h[:doc_auth_result] == DocAuth::LexisNexis::ResultCodes::FAILED.name
end

def show_hints?
Expand Down
26 changes: 22 additions & 4 deletions app/services/doc_auth/error_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ def get_doc_auth_errors(response_info, known_error_count)
def get_doc_auth_error_messages(response_info)
errors = Hash.new { |hash, key| hash[key] = Set.new }

if response_info[:transaction_status] != 'passed'
if response_info[:doc_auth_result] != LexisNexis::ResultCodes::PASSED.name
response_info[:processed_alerts][:failed]&.each do |alert|
alert_msg_hash = ErrorGenerator::ALERT_MESSAGES[alert[:name].to_sym]

Expand Down Expand Up @@ -370,10 +370,28 @@ def scan_for_unknown_alerts(response_info)
unknown_fail_count
end

def doc_auth_error_count(response_info)
return 0 if response_info[:transaction_status] == 'passed'
# This method replicates TrueIdResponse::attention_with_barcode? and
# should be removed/updated when that is.
def attention_with_barcode_result(doc_auth_result, processed_alerts)
attention_result_name = LexisNexis::ResultCodes::ATTENTION.name
barcode_alerts = processed_alerts[:failed]&.count.to_i == 1 &&
processed_alerts.dig(:failed, 0, :name) == '2D Barcode Read' &&
processed_alerts.dig(:failed, 0, :result) == 'Attention'

doc_auth_result == attention_result_name && barcode_alerts
end

def doc_auth_passed_or_attn_with_barcode(response_info)
doc_auth_result = response_info[:doc_auth_result]
processed_alerts = response_info[:processed_alerts]

response_info[:alert_failure_count]
doc_auth_result_passed = doc_auth_result == LexisNexis::ResultCodes::PASSED.name
doc_auth_result_passed || attention_with_barcode_result(doc_auth_result, processed_alerts)
end

def doc_auth_error_count(response_info)
doc_auth_passed_or_attn_with_barcode(response_info) ?
0 : response_info[:alert_failure_count]
end
end
end
16 changes: 13 additions & 3 deletions app/services/doc_auth/lexis_nexis/responses/true_id_response.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ def initialize(http_response, config, liveness_checking_enabled = false,

## returns full check success status, considering all checks:
# vendor (document and selfie if requested)
# document type
# bar code attention
def successful_result?
doc_auth_success? &&
(@liveness_checking_enabled ? selfie_passed? : true)
Expand All @@ -47,9 +49,16 @@ def successful_result?
# all checks from document perspectives, without considering selfie:
# vendor (document only)
# document_type
# bar code attention
def doc_auth_success?
# really it's everything else excluding selfie
transaction_status_passed? && id_type_supported?
((transaction_status_passed? &&
true_id_product.present? &&
product_status_passed? &&
doc_auth_result_passed?
) ||
attention_with_barcode?
) && id_type_supported?
end

def error_messages
Expand Down Expand Up @@ -84,8 +93,9 @@ def extra_attributes
def attention_with_barcode?
return false unless doc_auth_result_attention?

!!parsed_alerts[:failed]&.
any? { |alert| alert[:name] == '2D Barcode Read' && alert[:result] == 'Attention' }
parsed_alerts[:failed]&.count.to_i == 1 &&
parsed_alerts.dig(:failed, 0, :name) == '2D Barcode Read' &&
parsed_alerts.dig(:failed, 0, :result) == 'Attention'
end

def billed?
Expand Down
44 changes: 9 additions & 35 deletions app/services/doc_auth/mock/result_response.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ def initialize(uploaded_file, config, selfie_required = false)
selfie_quality_good: selfie_quality_good?,
selfie_status: selfie_status,
extra: {
transaction_status: transaction_status,
doc_auth_result: doc_auth_result,
portrait_match_results: portrait_match_results,
billed: true,
Expand All @@ -40,7 +39,6 @@ def errors
if file_data.blank?
{}
else
transaction_status = file_data.dig('transaction_status')
doc_auth_result = file_data.dig('doc_auth_result')
image_metrics = file_data.dig('image_metrics')
failed = file_data.dig('failed_alerts')&.dup
Expand All @@ -49,7 +47,6 @@ def errors
classification_info = file_data.dig('classification_info')
# Pass and doc type is ok
has_fields = [
transaction_status,
doc_auth_result,
image_metrics,
failed,
Expand All @@ -62,11 +59,10 @@ def errors
# Error generator is not to be called when it's not failure
# allows us to test successful results
return {} if all_doc_capture_values_passing?(
transaction_status, id_type_supported?
doc_auth_result, id_type_supported?
)

mock_args = {}
mock_args[:transaction_status] = transaction_status if transaction_status.present?
mock_args[:doc_auth_result] = doc_auth_result if doc_auth_result.present?
mock_args[:image_metrics] = image_metrics.symbolize_keys if image_metrics.present?
mock_args[:failed] = failed.map!(&:symbolize_keys) unless failed.nil?
Expand Down Expand Up @@ -95,8 +91,7 @@ def success?
end

def attention_with_barcode?
!!parsed_alerts&.
any? { |alert| alert['name'] == '2D Barcode Read' && alert['result'] == 'Attention' }
parsed_alerts == [ATTENTION_WITH_BARCODE_ALERT]
end

def self.create_network_error_response
Expand All @@ -110,14 +105,10 @@ def self.create_network_error_response
end

def doc_auth_success?
return false unless id_type_supported?
return false if transaction_status_from_uploaded_file == 'failed'
return true if transaction_status_from_uploaded_file == 'passed'
return false if doc_auth_result_from_uploaded_file == 'Failed'

doc_auth_result_from_uploaded_file == 'Passed' ||
(doc_auth_result_from_uploaded_file == 'Passed' ||
errors.blank? ||
(attention_with_barcode? && parsed_alerts.length == 1)
attention_with_barcode?
) && id_type_supported?
end

def selfie_status
Expand Down Expand Up @@ -163,14 +154,6 @@ def doc_auth_result_from_uploaded_file
parsed_data_from_uploaded_file&.[]('doc_auth_result')
end

def transaction_status
transaction_status_from_uploaded_file || transaction_status_from_success
end

def transaction_status_from_uploaded_file
parsed_data_from_uploaded_file&.[]('transaction_status')
end

def portrait_match_results
parsed_data_from_uploaded_file.dig('portrait_match_results')&.
transform_keys! { |key| key.to_s.camelize }&.
Expand All @@ -183,23 +166,15 @@ def classification_info
end

def doc_auth_result_from_success
if doc_auth_success?
if success?
DocAuth::LexisNexis::ResultCodes::PASSED.name
else
DocAuth::LexisNexis::ResultCodes::CAUTION.name
end
end

def transaction_status_from_success
if doc_auth_success?
'passed'
else
'failed'
end
end

def all_doc_capture_values_passing?(transaction_status, id_type_supported)
transaction_status == 'passed' &&
def all_doc_capture_values_passing?(doc_auth_result, id_type_supported)
doc_auth_result == 'Passed' &&
id_type_supported &&
(selfie_check_performed? ? selfie_passed? : true)
end
Expand All @@ -219,6 +194,7 @@ def parse_uri
# no-op, allows falling through to YAML parsing
end

ATTENTION_WITH_BARCODE_ALERT = { 'name' => '2D Barcode Read', 'result' => 'Attention' }.freeze
DEFAULT_FAILED_ALERTS = [{ name: '2D Barcode Read', result: 'Failed' }].freeze
DEFAULT_IMAGE_METRICS = {
front: {
Expand All @@ -236,7 +212,6 @@ def parse_uri
}.freeze

def create_response_info(
transaction_status: 'failed',
doc_auth_result: 'Failed',
passed: [],
failed: DEFAULT_FAILED_ALERTS,
Expand All @@ -247,7 +222,6 @@ def create_response_info(
merged_image_metrics = DEFAULT_IMAGE_METRICS.deep_merge(image_metrics)
{
vendor: 'Mock',
transaction_status: transaction_status,
doc_auth_result: doc_auth_result,
processed_alerts: {
passed: passed,
Expand Down
4 changes: 2 additions & 2 deletions spec/controllers/idv/image_uploads_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -458,7 +458,7 @@
product_status: nil,
reference: nil,
transaction_reason_code: nil,
transaction_status: 'passed',
transaction_status: nil,
vendor: nil,
workflow: an_instance_of(String),
birth_year: 1938,
Expand Down Expand Up @@ -1190,7 +1190,7 @@
product_status: nil,
reference: nil,
transaction_reason_code: nil,
transaction_status: 'failed',
transaction_status: nil,
vendor: nil,
workflow: an_instance_of(String),
birth_year: nil,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
transaction_status: failed
portrait_match_results:
FaceMatchResult: Fail
FaceErrorMessage: 'Successful. Liveness: Live'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
transaction_status: failed
portrait_match_results:
FaceMatchResult: Fail
FaceErrorMessage: 'Liveness: NotLive'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
transaction_status: passed
portrait_match_results:
# returns the portrait match result
FaceMatchResult: Fail
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
transaction_status: passed
document:
address1: 1800 F Street
address2: Apt 3
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
transaction_status: failed
failed_alerts:
- name: unexpected attention alert
result: Attention
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
transaction_status: failed
portrait_match_results:
# returns the portrait match result
FaceMatchResult: Fail
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
transaction_status: failed
failed_alerts: []
portrait_match_results:
FaceMatchResult: Fail
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
transaction_status: failed
failed_alerts: []
portrait_match_results:
FaceMatchResult: Pass
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
transaction_status: passed
document:
first_name: Jane
last_name: Doe
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
transaction_status: passed
document:
first_name: Jane
last_name: Doe
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
transaction_status: passed
document:
first_name: 'John'
last_name: 'Doe'
Expand Down
1 change: 0 additions & 1 deletion spec/fixtures/ial2_test_credential_no_liveness.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
transaction_status: passed
portrait_match_results:
# returns the portrait match result
FaceMatchResult: Fail
Expand Down
1 change: 0 additions & 1 deletion spec/fixtures/ial2_test_credential_poor_quality.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
transaction_status: passed
portrait_match_results:
# returns the portrait match result
FaceMatchResult: Fail
Expand Down
1 change: 0 additions & 1 deletion spec/fixtures/ial2_test_portrait_match_success.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
transaction_status: passed
document:
address1: '1 FAKE RD'
city: 'GREAT FALLS'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@
"Name": "Alert_1_AuthenticationResult",
"Values": [
{
"Value": "Failed",
"Value": "Passed",
"Detail": "Verified the presence of a pattern on the visible image."
}
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"ProductType": "TrueID",
"ExecutedStepName": "True_ID_Step",
"ProductConfigurationName": "AndreV3_TrueID_Flow",
"ProductStatus": "fail",
"ProductStatus": "pass",
"ParameterDetails": [
{
"Group": "AUTHENTICATION_RESULT",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"ProductType": "TrueID",
"ExecutedStepName": "True_ID_Step",
"ProductConfigurationName": "AndreV3_TrueID_Flow",
"ProductStatus": "fail",
"ProductStatus": "pass",
"ParameterDetails": [
{
"Group": "AUTHENTICATION_RESULT",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"ProductType": "TrueID",
"ExecutedStepName": "True_ID_Step",
"ProductConfigurationName": "AndreV3_TrueID_Flow",
"ProductStatus": "fail",
"ProductStatus": "pass",
"ParameterDetails": [
{
"Group": "AUTHENTICATION_RESULT",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"ProductType": "TrueID",
"ExecutedStepName": "True_ID_Step",
"ProductConfigurationName": "AndreV3_TrueID_Flow",
"ProductStatus": "fail",
"ProductStatus": "pass",
"ParameterDetails": [
{
"Group": "AUTHENTICATION_RESULT",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"ProductType": "TrueID",
"ExecutedStepName": "True_ID_Step",
"ProductConfigurationName": "AndreV3_TrueID_Flow",
"ProductStatus": "fail",
"ProductStatus": "pass",
"ParameterDetails": [
{
"Group": "AUTHENTICATION_RESULT",
Expand Down
4 changes: 2 additions & 2 deletions spec/forms/idv/api_image_upload_form_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@
doc_auth_success: boolean,
selfie_status: anything,
vendor: nil,
transaction_status: 'passed',
transaction_status: nil,
transaction_reason_code: nil,
workflow: 'test_non_liveness_workflow',
birth_year: 1938,
Expand Down Expand Up @@ -373,7 +373,7 @@
doc_auth_success: boolean,
selfie_status: :success,
vendor: nil,
transaction_status: 'passed',
transaction_status: nil,
transaction_reason_code: nil,
workflow: 'test_liveness_workflow',
birth_year: 1938,
Expand Down
2 changes: 1 addition & 1 deletion spec/presenters/image_upload_response_presenter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@
front: t('doc_auth.errors.not_a_file'),
hints: true,
},
extra: { transaction_status: 'failed', remaining_submit_attempts: 3 },
extra: { doc_auth_result: 'Failed', remaining_submit_attempts: 3 },
)
end

Expand Down
Loading