Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
3 changes: 3 additions & 0 deletions app/forms/idv/state_id_form.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ def submit(params)
cleaned_errors = errors.deep_dup

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@svalexander I realized I made a mistake when originally working on this, and that's why FakeAnalytics didn't catch the issue here. This change will fix the issue.

Suggested change
cleaned_errors = errors.deep_dup
cleaned_errors = errors.dup

I'd appreciate if you make the same change to address_form.rb as well.

@aduth FYI I think this is part of the issue here, i.e. ActiveModel::Error supports dup for cloning, but not deep_dup. There may also be issues when trying to print out the contents of these error objects directly.

cleaned_errors.delete(:first_name, :nontransliterable_field)
cleaned_errors.delete(:last_name, :nontransliterable_field)
cleaned_errors.delete(:state_id_city, :nontransliterable_field)
cleaned_errors.delete(:state_id_address1, :nontransliterable_field)
cleaned_errors.delete(:state_id_address2, :nontransliterable_field)

FormResponse.new(
success: valid?,
Expand Down
12 changes: 11 additions & 1 deletion app/validators/idv/form_state_id_validator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,24 @@ module FormStateIdValidator
presence: true

validates_with UspsInPersonProofing::TransliterableValidator,
fields: [:first_name, :last_name],
fields: [:first_name, :last_name, :state_id_city],
reject_chars: /[^A-Za-z\-' ]/,
message: ->(invalid_chars) do
I18n.t(
'in_person_proofing.form.state_id.errors.unsupported_chars',
char_list: invalid_chars.join(', '),
)
end

validates_with UspsInPersonProofing::TransliterableValidator,
fields: [:state_id_address1, :state_id_address2],
reject_chars: /[^A-Za-z0-9\-' .\/#]/,
message: ->(invalid_chars) do
I18n.t(
'in_person_proofing.form.state_id.errors.unsupported_chars',
char_list: invalid_chars.join(', '),
)
end
end
end
end
198 changes: 143 additions & 55 deletions spec/features/idv/in_person_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -424,70 +424,158 @@
allow(IdentityConfig.store).to receive(:usps_ipp_transliteration_enabled).
and_return(true)
end
it 'shows validation errors', allow_browser_log: true do
sign_in_and_2fa_user
begin_in_person_proofing
complete_location_step
complete_prepare_step
expect(page).to have_current_path(idv_in_person_step_path(step: :state_id), wait: 10)

fill_out_state_id_form_ok
fill_in t('in_person_proofing.form.state_id.first_name'), with: 'T0mmy "Lee"'
fill_in t('in_person_proofing.form.state_id.last_name'), with: 'Джейкоб'
click_idv_continue
expect(page).to have_content(
I18n.t(
'in_person_proofing.form.state_id.errors.unsupported_chars',
char_list: '", 0',
),
)
context 'with double address validation' do
let(:capture_secondary_id_enabled) { true }
let(:double_address_verification) { true }
let(:user) { user_with_2fa }
let(:enrollment) { InPersonEnrollment.new(capture_secondary_id_enabled:) }

expect(page).to have_content(
I18n.t(
'in_person_proofing.form.state_id.errors.unsupported_chars',
char_list: 'Д, б, е, ж, й, к, о',
),
)
before do
allow(IdentityConfig.store).to receive(:in_person_capture_secondary_id_enabled).
and_return(true)
allow(user).to receive(:establishing_in_person_enrollment).
and_return(enrollment)
end

fill_in t('in_person_proofing.form.state_id.first_name'),
with: InPersonHelper::GOOD_FIRST_NAME
fill_in t('in_person_proofing.form.state_id.last_name'), with: InPersonHelper::GOOD_LAST_NAME
click_idv_continue
it 'shows validation errors when double address validation is true',
allow_browser_log: true do
sign_in_and_2fa_user
begin_in_person_proofing
complete_location_step
complete_prepare_step
expect(page).to have_current_path(idv_in_person_step_path(step: :state_id), wait: 10)

expect(page).to have_current_path(idv_in_person_step_path(step: :address), wait: 10)
fill_out_address_form_ok
fill_out_state_id_form_ok(double_address_verification: double_address_verification)
fill_in t('in_person_proofing.form.state_id.first_name'), with: 'T0mmy "Lee"'
fill_in t('in_person_proofing.form.state_id.last_name'), with: 'Джейкоб'
fill_in t('in_person_proofing.form.state_id.address1'), with: '#1 $treet'
fill_in t('in_person_proofing.form.state_id.address2'), with: 'Gr@nd Lañe^'
fill_in t('in_person_proofing.form.state_id.city'), with: 'B3st C!ty'
click_idv_continue

fill_in t('idv.form.address1'), with: 'Джордж'
fill_in t('idv.form.address2_optional'), with: '(Nope) = %'
fill_in t('idv.form.city'), with: 'Елена'
click_idv_continue
expect(page).to have_content(
I18n.t(
'in_person_proofing.form.state_id.errors.unsupported_chars',
char_list: '", 0',
),
)

expect(page).to have_content(
I18n.t(
'in_person_proofing.form.state_id.errors.unsupported_chars',
char_list: 'Д, б, е, ж, й, к, о',
),
)

expect(page).to have_content(
I18n.t(
'in_person_proofing.form.state_id.errors.unsupported_chars',
char_list: '$',
),
)

expect(page).to have_content(
I18n.t(
'in_person_proofing.form.state_id.errors.unsupported_chars',
char_list: '@, ^',
),
)

expect(page).to have_content(
I18n.t(
'in_person_proofing.form.state_id.errors.unsupported_chars',
char_list: '!, 3',
),
)

# re-fill state id form with good inputs
fill_in t('in_person_proofing.form.state_id.first_name'),
with: InPersonHelper::GOOD_FIRST_NAME
fill_in t('in_person_proofing.form.state_id.last_name'),
with: InPersonHelper::GOOD_LAST_NAME
fill_in t('in_person_proofing.form.state_id.address1'),
with: InPersonHelper::GOOD_STATE_ID_ADDRESS1
fill_in t('in_person_proofing.form.state_id.address2'),
with: InPersonHelper::GOOD_STATE_ID_ADDRESS2
fill_in t('in_person_proofing.form.state_id.city'), with: InPersonHelper::GOOD_STATE_ID_CITY
click_idv_continue

expect(page).to have_content(
I18n.t(
'in_person_proofing.form.address.errors.unsupported_chars',
char_list: 'Д, д, ж, о, р',
),
)
expect(page).to have_current_path(idv_in_person_step_path(step: :address), wait: 10)
end
end

expect(page).to have_content(
I18n.t(
'in_person_proofing.form.address.errors.unsupported_chars',
char_list: '%, (, ), =',
),
)
context 'without double address validation' do
it 'shows validation errors when double address validation is false',
allow_browser_log: true do
sign_in_and_2fa_user
begin_in_person_proofing
complete_location_step
complete_prepare_step
expect(page).to have_current_path(idv_in_person_step_path(step: :state_id), wait: 10)

expect(page).to have_content(
I18n.t(
'in_person_proofing.form.address.errors.unsupported_chars',
char_list: 'Е, а, е, л, н',
),
)
fill_out_state_id_form_ok
fill_in t('in_person_proofing.form.state_id.first_name'), with: 'T0mmy "Lee"'
fill_in t('in_person_proofing.form.state_id.last_name'), with: 'Джейкоб'
click_idv_continue
# binding.pry

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Remove this debugging code.

Suggested change
# binding.pry

expect(page).to have_content(
I18n.t(
'in_person_proofing.form.state_id.errors.unsupported_chars',
char_list: '", 0',
),
)

expect(page).to have_content(
I18n.t(
'in_person_proofing.form.state_id.errors.unsupported_chars',
char_list: 'Д, б, е, ж, й, к, о',
),
)

# re-fill form with good inputs
fill_in t('in_person_proofing.form.state_id.first_name'),
with: InPersonHelper::GOOD_FIRST_NAME
fill_in t('in_person_proofing.form.state_id.last_name'),
with: InPersonHelper::GOOD_LAST_NAME
click_idv_continue

fill_in t('idv.form.address1'), with: InPersonHelper::GOOD_ADDRESS1
fill_in t('idv.form.address2_optional'), with: InPersonHelper::GOOD_ADDRESS2
fill_in t('idv.form.city'), with: InPersonHelper::GOOD_CITY
click_idv_continue
expect(page).to have_current_path(idv_in_person_step_path(step: :ssn), wait: 10)
expect(page).to have_current_path(idv_in_person_step_path(step: :address), wait: 10)
fill_out_address_form_ok

fill_in t('idv.form.address1'), with: 'Джордж'
fill_in t('idv.form.address2_optional'), with: '(Nope) = %'
fill_in t('idv.form.city'), with: 'Елена'
click_idv_continue

expect(page).to have_content(
I18n.t(
'in_person_proofing.form.address.errors.unsupported_chars',
char_list: 'Д, д, ж, о, р',
),
)

expect(page).to have_content(
I18n.t(
'in_person_proofing.form.address.errors.unsupported_chars',
char_list: '%, (, ), =',
),
)

expect(page).to have_content(
I18n.t(
'in_person_proofing.form.address.errors.unsupported_chars',
char_list: 'Е, а, е, л, н',
),
)

# re-fill form with good inputs
fill_in t('idv.form.address1'), with: InPersonHelper::GOOD_ADDRESS1
fill_in t('idv.form.address2_optional'), with: InPersonHelper::GOOD_ADDRESS2
fill_in t('idv.form.city'), with: InPersonHelper::GOOD_CITY
click_idv_continue
expect(page).to have_current_path(idv_in_person_step_path(step: :ssn), wait: 10)
end
end
end

Expand Down