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
9 changes: 7 additions & 2 deletions app/forms/idv/doc_pii_form.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,12 @@ class DocPiiForm
I18n.t('doc_auth.errors.general.no_liveness')
} }

validates_presence_of :state_id_number, { message: proc {
Comment thread
charleyf marked this conversation as resolved.
I18n.t('doc_auth.errors.general.no_liveness')
} }

attr_reader :first_name, :last_name, :dob, :address1, :state, :zipcode, :attention_with_barcode,
:jurisdiction
:jurisdiction, :state_id_number
alias_method :attention_with_barcode?, :attention_with_barcode
Comment thread
charleyf marked this conversation as resolved.

def initialize(pii:, attention_with_barcode: false)
Expand All @@ -36,6 +40,7 @@ def initialize(pii:, attention_with_barcode: false)
@state = pii[:state]
@zipcode = pii[:zipcode]
@jurisdiction = pii[:state_id_jurisdiction]
@state_id_number = pii[:state_id_number]
@attention_with_barcode = attention_with_barcode
end

Expand All @@ -54,7 +59,7 @@ def submit

def self.pii_like_keypaths
keypaths = [[:pii]]
attrs = %i[name dob dob_min_age address1 state zipcode jurisdiction]
attrs = %i[name dob dob_min_age address1 state zipcode jurisdiction state_id_number]
attrs.each do |k|
keypaths << [:errors, k]
keypaths << [:error_details, k]
Expand Down
97 changes: 93 additions & 4 deletions spec/controllers/idv/image_uploads_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
let(:document_filename_regex) { /^[a-f0-9]{8}-([a-f0-9]{4}-){3}[a-f0-9]{12}\.[a-z]+$/ }
let(:base64_regex) { /^[a-z0-9+\/]+=*$/i }
let(:selfie_img) { nil }
let(:state_id_number) { 'S59397998' }

describe '#create' do
subject(:action) do
post :create, params: params
Expand Down Expand Up @@ -491,6 +493,7 @@
state_id_type: state_id_type,
dob: dob,
state_id_jurisdiction: jurisdiction,
state_id_number: state_id_number,
zipcode: zipcode,
},
),
Expand All @@ -508,7 +511,7 @@
:idv_document_upload_submitted,
success: false,
document_state: 'ND',
document_number: nil,
Comment thread
charleyf marked this conversation as resolved.
document_number: state_id_number,
document_issued: nil,
document_expiration: nil,
first_name: nil,
Expand Down Expand Up @@ -597,7 +600,7 @@
:idv_document_upload_submitted,
success: false,
document_state: 'ND',
document_number: nil,
document_number: state_id_number,
document_issued: nil,
document_expiration: nil,
first_name: nil,
Expand Down Expand Up @@ -686,7 +689,7 @@
:idv_document_upload_submitted,
success: false,
document_state: 'Maryland',
document_number: nil,
document_number: state_id_number,
document_issued: nil,
document_expiration: nil,
first_name: 'FAKEY',
Expand All @@ -702,6 +705,92 @@
end
end

context 'but doc_pii validation fails due to missing state_id_number' do
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@amirbey Adding a test is a good idea. Did it here.

let(:state_id_number) { nil }

it 'tracks state_id_number validation errors in analytics' do
stub_analytics
stub_attempts_tracker

expect(@analytics).to receive(:track_event).with(
'IdV: doc auth image upload form submitted',
success: true,
errors: {},
user_id: user.uuid,
attempts: 1,
remaining_attempts: IdentityConfig.store.doc_auth_max_attempts - 1,
pii_like_keypaths: pii_like_keypaths,
flow_path: 'standard',
front_image_fingerprint: an_instance_of(String),
back_image_fingerprint: an_instance_of(String),
)

expect(@analytics).to receive(:track_event).with(
'IdV: doc auth image upload vendor submitted',
success: true,
errors: {},
attention_with_barcode: false,
async: false,
billed: true,
exception: nil,
doc_auth_result: 'Passed',
state: 'ND',
state_id_type: 'drivers_license',
user_id: user.uuid,
attempts: 1,
remaining_attempts: IdentityConfig.store.doc_auth_max_attempts - 1,
client_image_metrics: {
front: { glare: 99.99 },
back: { glare: 99.99 },
},
pii_like_keypaths: pii_like_keypaths,
flow_path: 'standard',
vendor_request_time_in_ms: a_kind_of(Float),
front_image_fingerprint: an_instance_of(String),
back_image_fingerprint: an_instance_of(String),
doc_type_supported: boolean,
)

expect(@analytics).to receive(:track_event).with(
'IdV: doc auth image upload vendor pii validation',
success: false,
errors: {
state_id_number: [I18n.t('doc_auth.errors.general.no_liveness')],
},
error_details: {
state_id_number: { blank: true },
},
attention_with_barcode: false,
user_id: user.uuid,
attempts: 1,
remaining_attempts: IdentityConfig.store.doc_auth_max_attempts - 1,
pii_like_keypaths: pii_like_keypaths,
flow_path: 'standard',
front_image_fingerprint: an_instance_of(String),
back_image_fingerprint: an_instance_of(String),
classification_info: hash_including(:Front, :Back),
)

expect(@irs_attempts_api_tracker).to receive(:track_event).with(
:idv_document_upload_submitted,
success: false,
document_back_image_filename: nil,
document_front_image_filename: nil,
document_image_encryption_key: nil,
document_state: 'ND',
document_number: state_id_number,
document_issued: nil,
document_expiration: nil,
first_name: 'FAKEY',
last_name: 'MCFAKERSON',
date_of_birth: '10/06/1938',
address: address1,
)

action
end
end

context 'but doc_pii validation fails due to invalid DOB' do
let(:dob) { nil }

Expand Down Expand Up @@ -775,7 +864,7 @@
document_front_image_filename: nil,
document_image_encryption_key: nil,
document_state: 'ND',
document_number: nil,
document_number: state_id_number,
document_issued: nil,
document_expiration: nil,
first_name: 'FAKEY',
Expand Down
1 change: 1 addition & 0 deletions spec/fixtures/ial2_test_credential.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ document:
dob: 10/06/1938
phone: +1 314-555-1212
state_id_jurisdiction: 'ND'
state_id_number: 'S59397998'
1 change: 1 addition & 0 deletions spec/fixtures/ial2_test_credential_no_dob.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ document:
zipcode: '11364'
phone: +1 314-555-1212
state_id_jurisdiction: 'NY'
state_id_number: 'S59397998'
1 change: 1 addition & 0 deletions spec/fixtures/puerto_rico_resident.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ document:
dob: 01/06/1998
phone: +1 787-555-1212
state_id_jurisdiction: 'PR'
state_id_number: 'S59397998'
46 changes: 42 additions & 4 deletions spec/forms/idv/doc_pii_form_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,28 @@
zipcode: Faker::Address.zip_code,
state: Faker::Address.state_abbr,
state_id_jurisdiction: 'AL',
state_id_number: 'S59397998',
Comment thread
charleyf marked this conversation as resolved.
}
end
let(:name_errors_pii) do
{ first_name: nil,
{
first_name: nil,
last_name: nil,
dob: valid_dob,
address1: Faker::Address.street_address,
state: Faker::Address.state_abbr }
state: Faker::Address.state_abbr,
state_id_number: 'S59397998',
}
end
let(:name_and_dob_errors_pii) do
{ first_name: nil,
{
first_name: nil,
last_name: nil,
dob: nil,
address1: Faker::Address.street_address,
state: Faker::Address.state_abbr }
state: Faker::Address.state_abbr,
state_id_number: 'S59397998',
}
end
let(:dob_min_age_error_pii) do
{
Expand All @@ -41,6 +48,7 @@
dob: too_young_dob,
address1: Faker::Address.street_address,
state: Faker::Address.state_abbr,
state_id_number: 'S59397998',
}
end
let(:invalid_zipcode_pii) do
Expand All @@ -52,6 +60,7 @@
state: Faker::Address.state_abbr,
zipcode: 123456,
state_id_jurisdiction: 'AL',
state_id_number: 'S59397998',
}
end
let(:nil_zipcode_pii) do
Expand All @@ -63,6 +72,7 @@
state: Faker::Address.state_abbr,
zipcode: nil,
state_id_jurisdiction: 'AL',
state_id_number: 'S59397998',
}
end
let(:state_error_pii) do
Expand All @@ -74,6 +84,7 @@
zipcode: Faker::Address.zip_code,
state: 'YORK',
state_id_jurisdiction: 'AL',
state_id_number: 'S59397998',
}
end
let(:jurisdiction_error_pii) do
Expand All @@ -85,6 +96,7 @@
zipcode: Faker::Address.zip_code,
state: Faker::Address.state_abbr,
state_id_jurisdiction: 'XX',
state_id_number: 'S59397998',
}
end
let(:address1_error_pii) do
Expand All @@ -96,6 +108,19 @@
zipcode: Faker::Address.zip_code,
state: Faker::Address.state_abbr,
state_id_jurisdiction: 'AL',
state_id_number: 'S59397998',
}
end
let(:nil_state_id_number_pii) do
{
first_name: Faker::Name.first_name,
last_name: Faker::Name.last_name,
dob: valid_dob,
address1: nil,
zipcode: Faker::Address.zip_code,
state: Faker::Address.state_abbr,
state_id_jurisdiction: 'AL',
state_id_number: nil,
}
end
let(:pii) { nil }
Expand Down Expand Up @@ -257,4 +282,17 @@
expect(result.errors[:state]).to eq([I18n.t('doc_auth.errors.general.no_liveness')])
end
end

context 'when the state_id_number is missing' do
let(:subject) { Idv::DocPiiForm.new(pii: nil_state_id_number_pii) }

it 'responds with an unsuccessful result' do
result = subject.submit

expect(result.success?).to eq(false)
expect(result.errors[:state_id_number]).to eq(
[I18n.t('doc_auth.errors.general.no_liveness')],
)
end
end
end
3 changes: 3 additions & 0 deletions spec/support/doc_pii_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ def pii_like_keypaths
[:errors, :jurisdiction],
[:error_details, :jurisdiction],
[:error_details, :jurisdiction, :jurisdiction],
[:errors, :state_id_number],
[:error_details, :state_id_number],
[:error_details, :state_id_number, :state_id_number],
]
end
end