Skip to content
This repository was archived by the owner on Nov 30, 2022. It is now read-only.
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: 6 additions & 0 deletions lib/identity_doc_auth/acuant/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ module Acuant
:facial_match_url,
:passlive_url,
:timeout,
:dpi_threshold,
:sharpness_threshold,
:glare_threshold,
:exception_notifier,
keyword_init: true,
allowed_members: [
Expand All @@ -22,6 +25,9 @@ module Acuant
:facial_match_url,
:passlive_url,
:timeout,
:dpi_threshold,
:sharpness_threshold,
:glare_threshold,
]
)
end
Expand Down
61 changes: 53 additions & 8 deletions lib/identity_doc_auth/acuant/responses/get_results_response.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ def initialize(http_response, config)
@config = config
super(
success: successful_result?,
errors: error_messages_from_alerts,
errors: generate_errors,
extra: {
result: result_code.name,
billed: result_code.billed,
processed_alerts: processed_alerts,
alert_failure_count: processed_alerts[:failed]&.count.to_i,
image_metrics: process_images_data,
image_metrics: processed_image_metrics,
raw_alerts: raw_alerts,
raw_regions: raw_regions,
}
Expand All @@ -31,7 +31,7 @@ def initialize(http_response, config)
# Explicitly override #to_h here because this method response object contains PII.
# This method is used to determine what from this response gets written to events.log.
# #to_h is defined on the super class and should not include any parts of the response that
# contain PII. This method is here as a safegaurd in case that changes.
# contain PII. This method is here as a safeguard in case that changes.
def to_h
{
success: success?,
Expand All @@ -41,7 +41,7 @@ def to_h
billed: result_code.billed,
processed_alerts: processed_alerts,
alert_failure_count: processed_alerts[:failed]&.count.to_i,
image_metrics: process_images_data,
image_metrics: processed_image_metrics,
raw_alerts: raw_alerts,
raw_regions: raw_regions,
}
Expand All @@ -62,6 +62,51 @@ def pii_from_doc

attr_reader :http_response

def generate_errors
return {} if successful_result?

dpi_threshold = config.dpi_threshold&.to_i || 290
sharpness_threshold = config&.sharpness_threshold&.to_i || 40
glare_threshold = config&.glare_threshold&.to_i || 40

front_dpi_fail, back_dpi_fail = false
front_sharp_fail, back_sharp_fail = false
front_glare_fail, back_glare_fail = false

processed_image_metrics.each do |side, img_metrics|
hdpi = img_metrics['HorizontalResolution'] || 0
vdpi = img_metrics['VerticalResolution'] || 0
if hdpi < dpi_threshold || vdpi < dpi_threshold
front_dpi_fail = true if side == :front
back_dpi_fail = true if side == :back
end

sharpness = img_metrics['SharpnessMetric']
if sharpness.present? && sharpness < sharpness_threshold
front_sharp_fail = true if side == :front
back_sharp_fail = true if side == :back
end

glare = img_metrics['GlareMetric']
if glare.present? && glare < glare_threshold
front_glare_fail = true if side == :front
back_glare_fail = true if side == :back
end
end

return { results: [Errors::DPI_LOW_BOTH_SIDES] } if front_dpi_fail && back_dpi_fail
return { results: [Errors::DPI_LOW_ONE_SIDE] } if front_dpi_fail || back_dpi_fail

return { results: [Errors::SHARP_LOW_BOTH_SIDES] } if front_sharp_fail && back_sharp_fail
return { results: [Errors::SHARP_LOW_ONE_SIDE] } if front_sharp_fail || back_sharp_fail

return { results: [Errors::GLARE_LOW_BOTH_SIDES] } if front_glare_fail && back_glare_fail
return { results: [Errors::GLARE_LOW_ONE_SIDE] } if front_glare_fail || back_glare_fail

#if no image metric errors default to raw error output
error_messages_from_alerts
end

def error_messages_from_alerts
return {} if successful_result?

Expand Down Expand Up @@ -99,10 +144,10 @@ def processed_alerts
@processed_alerts ||= process_raw_alerts(raw_alerts)
end

def process_images_data
raw_images_data.index_by do |image|
def processed_image_metrics
@image_metrics ||= raw_images_data.index_by do |image|
image.delete('Uri')
get_image_side_name(image['Side']).to_sym
get_image_side_name(image['Side'])
end
end

Expand All @@ -127,7 +172,7 @@ def attention_with_barcode?
end

def get_image_side_name(side_number)
side_number == 0 ? 'front' : 'back'
side_number == 0 ? :front : :back
end

def get_image_info(image_id)
Expand Down
62 changes: 62 additions & 0 deletions lib/identity_doc_auth/errors.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
module IdentityDocAuth
module Errors
# Alerts
BARCODE_CONTENT_CHECK = 'barcode_content_check'
BARCODE_READ_CHECK = 'barcode_read_check'
BIRTH_DATE_CHECKS = 'birth_date_checks'
CONTROL_NUMBER_CHECK = 'control_number_check'
DOC_CROSSCHECK = 'doc_crosscheck'
DOC_NUMBER_CHECKS = 'doc_number_checks'
EXPIRATION_CHECKS = 'expiration_checks'
FULL_NAME_CHECK = 'full_name_check'
GENERAL_ERROR_LIVENESS = 'general_error_liveness'
GENERAL_ERROR_NO_LIVENESS = 'general_error_no_liveness'
ID_NOT_RECOGNIZED = 'id_not_recognized'
ID_NOT_VERIFIED = 'id_not_verified'
ISSUE_DATE_CHECKS = 'issue_date_checks'
MULTIPLE_BACK_ID_FAILURES = 'multiple_back_id_failures'
MULTIPLE_FRONT_ID_FAILURES = 'multiple_front_id_failures'
REF_CONTROL_NUMBER_CHECK = 'ref_control_number_check'
SELFIE_FAILURE = 'selfie_failure'
SEX_CHECK = 'sex_check'
VISIBLE_COLOR_CHECK = 'visible_color_check'
VISIBLE_PHOTO_CHECK = 'visible_photo_check'
# Image metrics
DPI_LOW_ONE_SIDE = 'dpi_low_one_side'
DPI_LOW_BOTH_SIDES = 'dpi_low_both_sides'
SHARP_LOW_ONE_SIDE = 'sharp_low_one_side'
SHARP_LOW_BOTH_SIDES = 'sharp_low_both_sides'
GLARE_LOW_ONE_SIDE = 'glare_low_one_side'
GLARE_LOW_BOTH_SIDES = 'glare_low_both_sides'

ALL = [
BARCODE_CONTENT_CHECK,
BARCODE_READ_CHECK,
BIRTH_DATE_CHECKS,
BIRTH_DATE_CHECKS,
CONTROL_NUMBER_CHECK,
DOC_CROSSCHECK,
DOC_NUMBER_CHECKS,
EXPIRATION_CHECKS,
FULL_NAME_CHECK,
GENERAL_ERROR_LIVENESS,
GENERAL_ERROR_NO_LIVENESS,
ID_NOT_RECOGNIZED,
ID_NOT_VERIFIED,
ISSUE_DATE_CHECKS,
MULTIPLE_BACK_ID_FAILURES,
MULTIPLE_FRONT_ID_FAILURES,
REF_CONTROL_NUMBER_CHECK,
SELFIE_FAILURE,
SEX_CHECK,
VISIBLE_COLOR_CHECK,
VISIBLE_PHOTO_CHECK,
DPI_LOW_ONE_SIDE,
DPI_LOW_BOTH_SIDES,
SHARP_LOW_ONE_SIDE,
SHARP_LOW_BOTH_SIDES,
GLARE_LOW_ONE_SIDE,
GLARE_LOW_BOTH_SIDES,
].freeze
end
end
2 changes: 1 addition & 1 deletion lib/identity_doc_auth/lexis_nexis/error_generator.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true
require 'identity_doc_auth/lexis_nexis/errors'
require 'identity_doc_auth/errors'

module IdentityDocAuth
module LexisNexis
Expand Down
50 changes: 0 additions & 50 deletions lib/identity_doc_auth/lexis_nexis/errors.rb

This file was deleted.

2 changes: 1 addition & 1 deletion lib/identity_doc_auth/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true

module IdentityDocAuth
VERSION = "0.5.0"
VERSION = "0.5.1"
end
16 changes: 8 additions & 8 deletions spec/fixtures/acuant_responses/get_results_response_failure.json
Original file line number Diff line number Diff line change
Expand Up @@ -175,30 +175,30 @@
"Fields": [],
"Images": [
{
"GlareMetric": null,
"HorizontalResolution": 96,
"GlareMetric": 50,
"HorizontalResolution": 300,
"Id": "fe7c612a-66bb-46ab-8b06-b28f657b6482",
"IsCropped": false,
"IsTampered": false,
"Light": 0,
"MimeType": "image/jpeg",
"SharpnessMetric": null,
"SharpnessMetric": 50,
"Side": 0,
"Uri": "https://services.assureid.net/AssureIDService/Document/97b0215a-7858-4104-b1f3-17dbaf609140/Image?side=Front&light=White",
"VerticalResolution": 96
"VerticalResolution": 300
},
{
"GlareMetric": null,
"HorizontalResolution": 96,
"GlareMetric": 50,
"HorizontalResolution": 300,
"Id": "60359af3-d87e-46da-ab5b-883ebfec923f",
"IsCropped": false,
"IsTampered": false,
"Light": 0,
"MimeType": "image/jpeg",
"SharpnessMetric": null,
"SharpnessMetric": 50,
"Side": 1,
"Uri": "https://services.assureid.net/AssureIDService/Document/97b0215a-7858-4104-b1f3-17dbaf609140/Image?side=Back&light=White",
"VerticalResolution": 96
"VerticalResolution": 300
}
],
"InstanceId": "97b0215a-7858-4104-b1f3-17dbaf609140",
Expand Down
Loading