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
13 changes: 2 additions & 11 deletions app/services/doc_auth/error_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,12 @@ def initialize(config)
ID = :id
FRONT = :front
BACK = :back
SELFIE = :selfie
GENERAL = :general

ERROR_KEYS = [
ID,
FRONT,
BACK,
SELFIE,
GENERAL,
].to_set.freeze

Expand Down Expand Up @@ -50,7 +48,6 @@ def initialize(config)
}.freeze

def generate_doc_auth_errors(response_info)
liveness_enabled = response_info[:liveness_enabled]
alert_error_count = response_info[:doc_auth_result] == 'Passed' ?
0 : response_info[:alert_failure_count]

Expand All @@ -60,8 +57,7 @@ def generate_doc_auth_errors(response_info)
image_metric_errors = get_image_metric_errors(response_info[:image_metrics])
return image_metric_errors.to_h unless image_metric_errors.empty?

alert_errors = get_error_messages(liveness_enabled, response_info)
alert_error_count += 1 if alert_errors.include?(SELFIE)
alert_errors = get_error_messages(response_info)

error = ''
side = nil
Expand Down Expand Up @@ -145,7 +141,7 @@ def get_image_metric_errors(processed_image_metrics)
error_result
end

def get_error_messages(liveness_enabled, response_info)
def get_error_messages(response_info)
errors = Hash.new { |hash, key| hash[key] = Set.new }

if response_info[:doc_auth_result] != 'Passed'
Expand All @@ -159,11 +155,6 @@ def get_error_messages(liveness_enabled, response_info)
end
end

portrait_match_results = response_info[:portrait_match_results] || {}
if liveness_enabled && portrait_match_results.dig(:FaceMatchResult) != 'Pass'
errors[SELFIE] << Errors::SELFIE_FAILURE
end

errors
end

Expand Down
4 changes: 0 additions & 4 deletions app/services/doc_auth/errors.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ module Errors
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'
Expand Down Expand Up @@ -58,7 +57,6 @@ module Errors
MULTIPLE_BACK_ID_FAILURES,
MULTIPLE_FRONT_ID_FAILURES,
REF_CONTROL_NUMBER_CHECK,
SELFIE_FAILURE,
SEX_CHECK,
VISIBLE_COLOR_CHECK,
VISIBLE_PHOTO_CHECK,
Expand Down Expand Up @@ -108,8 +106,6 @@ module Errors
MULTIPLE_FRONT_ID_FAILURES => { long_msg: MULTIPLE_FRONT_ID_FAILURES, field_msg: FALLBACK_FIELD_LEVEL, hints: true },
MULTIPLE_BACK_ID_FAILURES => { long_msg: MULTIPLE_BACK_ID_FAILURES, field_msg: FALLBACK_FIELD_LEVEL, hints: true },
GENERAL_ERROR => { long_msg: GENERAL_ERROR, field_msg: FALLBACK_FIELD_LEVEL, hints: true },
# Liveness
SELFIE_FAILURE => { long_msg: SELFIE_FAILURE, field_msg: FALLBACK_FIELD_LEVEL, hints: false },
}
# rubocop:enable Layout/LineLength
end
Expand Down
10 changes: 0 additions & 10 deletions app/services/doc_auth_router.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,6 @@ module DocAuthRouter
# i18n-tasks-use t('doc_auth.errors.alerts.ref_control_number_check')
DocAuth::Errors::REF_CONTROL_NUMBER_CHECK =>
'doc_auth.errors.alerts.ref_control_number_check',
# i18n-tasks-use t('doc_auth.errors.alerts.selfie_failure')
DocAuth::Errors::SELFIE_FAILURE => 'doc_auth.errors.alerts.selfie_failure',
# i18n-tasks-use t('doc_auth.errors.alerts.sex_check')
DocAuth::Errors::SEX_CHECK => 'doc_auth.errors.alerts.sex_check',
# i18n-tasks-use t('doc_auth.errors.alerts.visible_color_check')
Expand Down Expand Up @@ -116,9 +114,7 @@ def translate_form_response!(response)
end

def translate_doc_auth_errors!(response)
# acuant selfie errors are handled in translate_generic_errors!
error_keys = DocAuth::ErrorGenerator::ERROR_KEYS.dup
error_keys.delete(:selfie) if @client.is_a?(DocAuth::Acuant::AcuantClient)

error_keys.each do |category|
response.errors[category]&.map! do |plain_error|
Expand All @@ -127,7 +123,6 @@ def translate_doc_auth_errors!(response)
I18n.t(error_key)
else
Rails.logger.warn("unknown DocAuth error=#{plain_error}")
# This isn't right, this should depend on the liveness setting
I18n.t('doc_auth.errors.general.no_liveness')
end
end
Expand All @@ -138,11 +133,6 @@ def translate_generic_errors!(response)
if response.errors[:network] == true
response.errors[:network] = I18n.t('doc_auth.errors.general.network_error')
end

# this is only relevant to acuant code path
if response.errors[:selfie] == true
response.errors[:selfie] = I18n.t('doc_auth.errors.general.liveness')
end
end
end

Expand Down
4 changes: 0 additions & 4 deletions config/locales/doc_auth/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@ en:
the picture. Try taking new pictures.
issue_date_checks: We couldn’t read the issue date on your ID. Try taking new pictures.
ref_control_number_check: We couldn’t read the control number barcode. Try taking new pictures.
selfie_failure: We couldn’t match the photo of you to your ID. Try taking a new
picture of yourself or the front of your ID.
sex_check: We couldn’t read the sex on your ID. Try taking new pictures.
visible_color_check: We couldn’t verify your ID. It might have moved when you
took the picture, or the picture is too dark. Try taking new pictures
Expand Down Expand Up @@ -67,8 +65,6 @@ en:
invalid: This file type is not accepted, please choose a JPG or PNG file.
general:
fallback_field_level: Please add a new image
liveness: We couldn’t verify your ID and photo of yourself. Try taking new
pictures.
multiple_back_id_failures: We couldn’t verify the back of your ID. Try taking a new picture.
multiple_front_id_failures: We couldn’t verify the front of your ID. Try taking a new picture.
network_error: We are having technical difficulties on our end. Please try to
Expand Down
5 changes: 0 additions & 5 deletions config/locales/doc_auth/es.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,6 @@ es:
identidad. Intente tomar nuevas fotos.
ref_control_number_check: No pudimos leer el código de barras del número de
control. Intente tomar nuevas fotografías.
selfie_failure: No pudimos hacer coincidir su foto con su documento de
identidad. Intente tomarse una nueva foto de usted o de la parte
delantera de su documento de identidad.
sex_check: No pudimos leer el sexo en su documento de identidad. Intente tomar
nuevas fotos.
visible_color_check: No pudimos verificar su documento de identidad. Puede que
Expand Down Expand Up @@ -83,8 +80,6 @@ es:
invalid: Ese formato no es admitido, por favor elija un archivo JPG o PNG.
general:
fallback_field_level: Agregue una imagen nueva
liveness: No pudimos verificar su documento de identidad y su foto. Intente
tomar nuevas fotografías.
multiple_back_id_failures: No pudimos verificar la parte trasera de su documento
de identidad. Intente tomar una nueva foto.
multiple_front_id_failures: No pudimos verificar la parte delantera de su
Expand Down
5 changes: 0 additions & 5 deletions config/locales/doc_auth/fr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,6 @@ fr:
d’identité. Essayez de prendre de nouvelles photos.
ref_control_number_check: Nous n’avons pas pu lire le code-barres du numéro de
contrôle. Essayez de prendre de nouvelles photos.
selfie_failure: Nous n’avons pas pu associer votre photo à votre pièce
d’identité. Essayez de prendre une nouvelle photo de vous-même ou du
recto de votre carte d’identité.
sex_check: Nous n’avons pas pu lire le sexe sur votre pièce d’identité. Essayez
de prendre de nouvelles photos.
visible_color_check: Nous n’avons pas pu vérifier votre pièce d’identité. Elle a
Expand Down Expand Up @@ -88,8 +85,6 @@ fr:
ou PNG.
general:
fallback_field_level: Veuillez ajouter une nouvelle image
liveness: Nous n’avons pas pu vérifier votre pièce d’identité et votre photo.
Essayez de prendre de nouvelles photos.
multiple_back_id_failures: Nous n’avons pas pu vérifier le verso de votre pièce
d’identité. Essayez de prendre une nouvelle photo.
multiple_front_id_failures: Nous n’avons pas pu vérifier le recto de votre pièce
Expand Down
65 changes: 3 additions & 62 deletions spec/services/doc_auth/error_generator_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,12 @@ def build_error_info(
doc_result: nil,
passed: [],
failed: [],
liveness_result: nil,
image_metrics: {}
)
{
conversation_id: 31000406181234,
reference: 'Reference1',
liveness_enabled: liveness_result.present? ? true : false,
liveness_enabled: false,
vendor: 'Test',
transaction_reason_code: 'testing',
doc_auth_result: doc_result,
Expand All @@ -28,12 +27,12 @@ def build_error_info(
failed: failed,
},
alert_failure_count: failed&.count.to_i,
portrait_match_results: { FaceMatchResult: liveness_result },
portrait_match_results: { FaceMatchResult: 'Pass' },
image_metrics: image_metrics,
}
end

context 'The correct errors are delivered with liveness off when' do
context 'The correct errors are delivered when' do
it 'DocAuthResult is Attention' do
error_info = build_error_info(
doc_result: 'Attention',
Expand Down Expand Up @@ -206,64 +205,6 @@ def build_error_info(
end
end

context 'The correct errors are delivered with liveness on when' do
it 'DocAuthResult is Attention and selfie has passed' do
error_info = build_error_info(
doc_result: 'Attention',
liveness_result: 'Pass',
failed: [{ name: '2D Barcode Read', result: 'Attention' }],
)

output = described_class.new(config).generate_doc_auth_errors(error_info)

expect(output.keys).to contain_exactly(:general, :back, :hints)
expect(output[:general]).to contain_exactly(DocAuth::Errors::BARCODE_READ_CHECK)
expect(output[:back]).to contain_exactly(DocAuth::Errors::FALLBACK_FIELD_LEVEL)
expect(output[:hints]).to eq(true)
end

it 'DocAuthResult is Attention and selfie has failed' do
error_info = build_error_info(
doc_result: 'Attention',
liveness_result: 'Fail',
failed: [{ name: '2D Barcode Read', result: 'Attention' }],
)

output = described_class.new(config).generate_doc_auth_errors(error_info)

expect(output.keys).to contain_exactly(:general, :front, :back, :hints)
expect(output[:general]).to contain_exactly(DocAuth::Errors::GENERAL_ERROR)
expect(output[:back]).to contain_exactly(DocAuth::Errors::FALLBACK_FIELD_LEVEL)
expect(output[:hints]).to eq(true)
end

it 'DocAuthResult is Attention and selfie has succeeded' do
error_info = build_error_info(
doc_result: 'Attention',
liveness_result: 'Pass',
failed: [{ name: '2D Barcode Read', result: 'Attention' }],
)

output = described_class.new(config).generate_doc_auth_errors(error_info)

expect(output.keys).to contain_exactly(:general, :back, :hints)
expect(output[:general]).to contain_exactly(DocAuth::Errors::BARCODE_READ_CHECK)
expect(output[:back]).to contain_exactly(DocAuth::Errors::FALLBACK_FIELD_LEVEL)
expect(output[:hints]).to eq(true)
end

it 'DocAuthResult has passed but liveness failed' do
error_info = build_error_info(doc_result: 'Passed', liveness_result: 'Fail')

output = described_class.new(config).generate_doc_auth_errors(error_info)

expect(output.keys).to contain_exactly(:general, :selfie, :hints)
expect(output[:general]).to contain_exactly(DocAuth::Errors::SELFIE_FAILURE)
expect(output[:selfie]).to contain_exactly(DocAuth::Errors::FALLBACK_FIELD_LEVEL)
expect(output[:hints]).to eq(false)
end
end

context 'The correct errors are delivered for image metrics when' do
let(:metrics) do
{
Expand Down
10 changes: 4 additions & 6 deletions spec/services/doc_auth_router_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ def reload_ab_test_initializer!
),
)

response = proxy.post_images(front_image: 'a', back_image: 'b', selfie_image: 'c')
response = proxy.post_images(front_image: 'a', back_image: 'b')

expect(response.errors[:network]).to eq(I18n.t('doc_auth.errors.general.network_error'))
end
Expand All @@ -193,20 +193,18 @@ def reload_ab_test_initializer!
id: [DocAuth::Errors::EXPIRATION_CHECKS],
front: [DocAuth::Errors::VISIBLE_PHOTO_CHECK],
back: [DocAuth::Errors::REF_CONTROL_NUMBER_CHECK],
selfie: [DocAuth::Errors::SELFIE_FAILURE],
general: [DocAuth::Errors::GENERAL_ERROR],
not_translated: true,
},
),
)

response = proxy.post_images(front_image: 'a', back_image: 'b', selfie_image: 'c')
response = proxy.post_images(front_image: 'a', back_image: 'b')

expect(response.errors).to eq(
id: [I18n.t('doc_auth.errors.alerts.expiration_checks')],
front: [I18n.t('doc_auth.errors.alerts.visible_photo_check')],
back: [I18n.t('doc_auth.errors.alerts.ref_control_number_check')],
selfie: [I18n.t('doc_auth.errors.alerts.selfie_failure')],
general: [I18n.t('doc_auth.errors.general.no_liveness')],
not_translated: true,
)
Expand All @@ -225,7 +223,7 @@ def reload_ab_test_initializer!

expect(Rails.logger).to receive(:warn).with('unknown DocAuth error=some_obscure_error')

response = proxy.post_images(front_image: 'a', back_image: 'b', selfie_image: 'c')
response = proxy.post_images(front_image: 'a', back_image: 'b')

expect(response.errors).to eq(
id: [I18n.t('doc_auth.errors.general.no_liveness')],
Expand All @@ -244,7 +242,7 @@ def reload_ab_test_initializer!
),
)

response = proxy.post_images(front_image: 'a', back_image: 'b', selfie_image: 'c')
response = proxy.post_images(front_image: 'a', back_image: 'b')

expect(response.errors).to eq(general: [I18n.t('doc_auth.errors.http.image_load')])
expect(response.exception.message).to eq('Test 438 HTTP failure')
Expand Down