-
Notifications
You must be signed in to change notification settings - Fork 66
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix bug in credential email route with missing credential email #20145
Conversation
@bosawt to test this would I login with a dslogon account that doesnt have either an idme or login.gov account attached to it? I would expect there to be no email present? Or is this it just that the dslogon or mhv account should have no contact email but also have an idme or login.gov verified account? |
I left out the testing instructions because you have to set things up locally in a kind of contrived way. Basically you should always have an email on your account regardless of what you sign in as, it will be like this for all test accounts. If you really want to test, you have to:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tested via rails console, lgtm
Testing a user without user_verifications
: (line 24 was successfully skipped)
user_account = (some user with no user_verification)
...
vets-api(dev)* emails = user_account.user_verifications.each_with_object({}) do |verification, credentials|
vets-api(dev)* next unless verification.user_credential_email
vets-api(dev)*
vets-api(dev)* credentials[verification.credential_type.to_sym] = verification.user_credential_email.credential_email
vets-api(dev)> end
=> {}
Then I tested to make sure the opposite condition provides the credential emails:
vets-api(dev)> UserAccount.left_joins(:user_verifications).group('user_accounts.id').having('COUNT(user_verifications.id) = 2')
vets-api(dev)> ua2 = UserAccount.find("29bf2f0d-61d3-46e4-a0db-331b45c1d069")
vets-api(dev)* emails = ua2.user_verifications.each_with_object({}) do |verification, credentials|
vets-api(dev)* next unless verification.user_credential_email
vets-api(dev)* credentials[verification.credential_type.to_sym] = verification.user_credential_email.credential_email
vets-api(dev)> end
2025-01-08 10:59:19.339716 D [22468:11700 log_subscriber.rb:164] Rails -- Decrypt Data Key (0.0ms) Context: {:model_name=>"UserCredentialEmail", :model_id=>6}
=> {:idme=>"vets.gov.user+1@gmail.com", :logingov=>"vets.gov.user+1@gmail.com"}
@@ -19,8 +19,9 @@ def icn | |||
|
|||
def credential_emails | |||
emails = current_user.user_account.user_verifications.each_with_object({}) do |verification, credentials| | |||
credentials[verification.credential_type.to_sym] = | |||
verification.user_credential_email.credential_email | |||
next unless verification.user_credential_email |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Kind of a nitpick but I think it would be a bit cleaner if we select the user_verifications
we want first instead of looping through them
verifications = current_user.user_account.user_verifications.select { |v| v.user_credential_email }
emails = verifications.to_h { |v| [v.credential_type, v.user_credential_email.credential_email] }
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
or for that matter I suppose we could do user_verifications.where.not(user_credential_email: nil)
, and just do it with the query
fdd5133
to
2b7669d
Compare
2b7669d
to
8cc57b6
Compare
Summary
UserVerification
does not have aUserCredentialEmail
What areas of the site does it impact?
Interstitial Authentication