Skip to content

LG-7832: Validate State ID and Address are transliterable to a valid USPS submission#7938

Merged
NavaTim merged 42 commits intomainfrom
tbradley/lg-7832-transliterate-usps-api-frontend
Mar 10, 2023
Merged

LG-7832: Validate State ID and Address are transliterable to a valid USPS submission#7938
NavaTim merged 42 commits intomainfrom
tbradley/lg-7832-transliterate-usps-api-frontend

Conversation

@NavaTim
Copy link
Contributor

@NavaTim NavaTim commented Mar 6, 2023

🎫 Ticket

🛠 Summary of changes

📜 Testing Plan

Provide a checklist of steps to confirm the changes.

  • Complete IPP flow up to state ID / address
  • Check that state ID and address forms reject non-transliterable characters
  • Check that state ID and address forms reject transliterable characters that don't meet the USPS API requirements
  • Check that state ID and address forms accept transliterable characters that have diacritical marks but otherwise meet the USPS API requirements

👀 Screenshots

Desktop (State ID):

localhost_3000_verify_in_person_state_id

Desktop (Address):

localhost_3000_verify_in_person_address

Desktop (Verify):

localhost_3000_verify_in_person_verify

Mobile (State ID):

localhost_3000_verify_in_person_state_id(iPhone SE)

Mobile (Address):

localhost_3000_verify_in_person_address(iPhone SE)

Mobile (Verify):

localhost_3000_verify_in_person_verify(iPhone SE)

NavaTim added 4 commits March 6, 2023 15:53
changelog: Improvements, In-Person Proofing, USPS API Transliteration
changelog: Bug Fixes, In-Person Proofing, Retain State ID and Address on form re-render after invalid submissions
… tbradley/lg-7832-transliterate-usps-api-frontend
…USPS submission

changelog: Improvements, In-Person Proofing, Validate State ID and Address are transliterable to a valid USPS submission
@NavaTim NavaTim requested a review from zachmargolis March 6, 2023 23:50
NavaTim and others added 22 commits March 6, 2023 17:15
…to tbradley/lg-7832-transliterate-usps-api-frontend
… tbradley/lg-7832-transliterate-usps-api-frontend
Co-authored-by: Zach Margolis <zachmargolis@users.noreply.github.com>
…to tbradley/lg-7832-transliterate-usps-api-frontend
Co-authored-by: Zach Margolis <zachmargolis@users.noreply.github.com>
Co-authored-by: Zach Margolis <zachmargolis@users.noreply.github.com>
Co-authored-by: Zach Margolis <zachmargolis@users.noreply.github.com>
Co-authored-by: Zach Margolis <zachmargolis@users.noreply.github.com>
Co-authored-by: Zach Margolis <zachmargolis@users.noreply.github.com>
Co-authored-by: Zach Margolis <zachmargolis@users.noreply.github.com>
@NavaTim NavaTim marked this pull request as ready for review March 7, 2023 22:07
Comment on lines +19 to +24
if (@fields & SUPPORTED_FIELDS).size < @fields.size
# Catch incorrect usage of the validator
raise StandardError.new(
"Unsupported transliteration fields: #{(@fields - SUPPORTED_FIELDS).to_json}",
)
end
Copy link
Contributor

Choose a reason for hiding this comment

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

do we need this check ahead of time? If we added .fetch when we look up validations per field, we'd get errors early on that would make it clear which keys are unknown

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is to help catch unsupported usage, so it's better that this error occur as early as possible in the development cycle. If you can point me to a mechanism for disabling this check specifically for prod, then I'd be open to adding that.

Comment on lines +23 to +27
pii_keys.each do |key|
hash[:pii_like_keypaths] ||= []
hash[:pii_like_keypaths].append([:error_details, key]) if error_details.has_key?(key)
hash[:errors] = hash[:errors].except(key) if hash[:errors].has_key?(key)
end
Copy link
Contributor

Choose a reason for hiding this comment

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

The goal for pii_like_keypaths was that it's passed in at the analytics.track_event callsite, is the reason we're doing this here because for these 2 forms, the analytics happens "automatically" inside of the FSM?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, the FSM decouples the form from the analytics so we don't directly control how the errors are logged.

Copy link
Contributor

@zachmargolis zachmargolis Mar 7, 2023

Choose a reason for hiding this comment

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

Ah I just found how we work around this in other places, we add it to the extra part of the FormResponse:

pii_like_keypaths: [[:errors, :zipcode], [:error_details, :zipcode]],

Can we try that approach instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is a case where we should avoid logging the error message, which could in some cases expose a person's name. The same approach doesn't seem acceptable here.

Copy link
Contributor

Choose a reason for hiding this comment

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

If the goal is to not log them, can we remove them in the form before instantiating the FormResponse? FormResponse is to capture and transport data specifically to our logs

Copy link
Contributor

Choose a reason for hiding this comment

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

Like in this spot:

we could still submit the form, but then post-process that FormResponse to omit errors we don't want to log

Copy link
Contributor Author

Choose a reason for hiding this comment

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

e.g. create a version of the Errors object with the transliteration errors filtered out when creating FormResponse in these classes?

Copy link
Contributor

Choose a reason for hiding this comment

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

yup exactly that

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok, that seems doable. Thanks!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated to remove the errors potentially containing PII from the returned FormResponse. It looks like the errors are still displaying as expected, and they are not being logged.

@NavaTim NavaTim requested a review from zachmargolis March 8, 2023 01:57
Comment on lines +16 to +21
message: (proc do |invalid_chars|
I18n.t(
'in_person_proofing.form.state_id.errors.unsupported_chars',
char_list: invalid_chars.join(', '),
)
end)
Copy link
Contributor

Choose a reason for hiding this comment

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

I think if we switch this to "stabby lambda" syntax we may not need the extra wrapping parens anymore, so I just went and pushed that in 5b20738

- Real ActiveModel::Errors instance
- Model fields all defined in one spot
- spy on real validator.transliterator instead of stubbing
Copy link
Contributor

@zachmargolis zachmargolis left a comment

Choose a reason for hiding this comment

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

LGTM

a few notes:

  • I went ahead and pushed some syntactic/stubbing cleanups myself.
  • I wish we had unit tests for the FormAddressValidator/FormStateIdValidator (or at least the forms they're included in) so we don't have to go all the way to feature specs, but that's a bigger change than this PR

Comment on lines +93 to +95
unsupported_chars: 'Our system cannot read the following characters:
%{char_list}. Please try again using substitutes for those
characters.'
Copy link
Contributor

Choose a reason for hiding this comment

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

I feel like the copy is a little misleading, clearly the system can read the characters if we can render them back... but I'm guessing this copy already went through UX, and this is not the hill I die on

@NavaTim NavaTim requested review from a team and erogray and removed request for a team March 10, 2023 16:53
@rutvigupta-design
Copy link

This looks good to me!

@NavaTim NavaTim merged commit 59c383d into main Mar 10, 2023
@NavaTim NavaTim deleted the tbradley/lg-7832-transliterate-usps-api-frontend branch March 10, 2023 17:11
zachmargolis added a commit that referenced this pull request Mar 14, 2023
…USPS submission (#7938)

* LG-7832: Validate State ID and Address are transliterable to a valid USPS submission

changelog: Improvements, In-Person Proofing, Validate State ID and Address are transliterable to a valid USPS submission

Co-authored-by: Zach Margolis <zachmargolis@users.noreply.github.com>

* LG-7832: Make test updates based on PR feedback

* Update spec/services/usps_in_person_proofing/enrollment_helper_spec.rb

Co-authored-by: Zach Margolis <zachmargolis@users.noreply.github.com>

* Update app/services/usps_in_person_proofing/enrollment_helper.rb

Co-authored-by: Zach Margolis <zachmargolis@users.noreply.github.com>

* LG-7832: Remove incorrect usage of .class

* LG-7832: Feature should only be enabled by default in dev environments

* Update app/services/idv/steps/in_person/address_step.rb

Co-authored-by: Zach Margolis <zachmargolis@users.noreply.github.com>

* Update app/services/idv/steps/in_person/state_id_step.rb

Co-authored-by: Zach Margolis <zachmargolis@users.noreply.github.com>

* LG-7832: Use case no longer requires support for HashWithIndifferentAccess

* LG-7832: Clean up translation usage

* LG-7832: Update test

* LG-7832: Update test

* LG-7832: Simplify unsupported character extraction from transliterated string

* LG-7832: Clarify transliteration result documentation

* LG-7832: Refactor helper logic into validator classes

* Switch to ->() lambda syntax to remove extra parens

* Change one more proc syntax to "stabby lambda"

* un-stub the TransliterableValidator spec as much as possible

- Real ActiveModel::Errors instance
- Model fields all defined in one spot
- spy on real validator.transliterator instead of stubbing

---------

Co-authored-by: Zach Margolis <zachmargolis@users.noreply.github.com>
Co-authored-by: Zach Margolis <zachary.margolis@gsa.gov>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants