Skip to content

Fix personal key 2fa selection#2337

Merged
jmhooper merged 2 commits intomasterfrom
jmhooper-fix-personal-key-2fa-selection
Jul 19, 2018
Merged

Fix personal key 2fa selection#2337
jmhooper merged 2 commits intomasterfrom
jmhooper-fix-personal-key-2fa-selection

Conversation

@jmhooper
Copy link
Contributor

This branch has 2 commits:

  • The first commit reverts the reversion to remove the personal key changes that broke on master
  • The second commit fixes the bug that broke the 2FA selection form on master

Hi! Before submitting your PR for review, and/or before merging it, please
go through the following checklist:

  • For DB changes, check for missing indexes, check to see if the changes
    affect other apps (such as the dashboard), make sure the DB columns in the
    various environments are properly populated, coordinate with devops, plan
    migrations in separate steps.

  • For route changes, make sure GET requests don't change state or result in
    destructive behavior. GET requests should only result in information being
    read, not written.

  • For encryption changes, make sure it is compatible with data that was
    encrypted with the old code.

  • For secrets changes, make sure to update the S3 secrets bucket with the
    new configs in all environments.

  • Do not disable Rubocop or Reek offenses unless you are absolutely sure
    they are false positives. If you're not sure how to fix the offense, please
    ask a teammate.

  • When reading data, write tests for nil values, empty strings,
    and invalid formats.

  • When calling redirect_to in a controller, use _url, not _path.

  • When adding user data to the session, use the user_session helper
    instead of the session helper so the data does not persist beyond the user's
    session.

  • When adding a new controller that requires the user to be fully
    authenticated, make sure to add before_action :confirm_two_factor_authenticated.

jmhooper added 2 commits July 18, 2018 10:45
**Why**: Personal key has been changed to behave like password, where it
is nil until a key is assigned to the user during a request. This commit
checks the digest instead of the personal key method to determine if a
user can sign in with a personal key.

def personal_key
@personal_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.

What do you think about making this point to encrypted_recovery_code_digest? That way, we can still keep the old calls to user.personal_key, which matches what we call it on the site, and is clearer than encrypted_recovery_code_digest.

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 in the revert commit which is code that was already merged.

But, I didn't do that because we did a touch of refactoring here to make the personal_key and personal_key= methods work like the password and password= methods since that is how we actually use it.

context 'when email is valid and user exists' do
it 'returns hash with properties about the event and the user' do
user = build(:user, :signed_up, email: 'test1@test.com')
user = create(:user, :signed_up, email: 'test1@test.com')
Copy link
Contributor

Choose a reason for hiding this comment

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

Why does this require creating vs building?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The the test is testing the behavior when a user exists. The app does not know the user exists without creating them. This is a bug that was uncovered when changing the personal key behavior. Previously, setting the personal key (which is done in the factory here) was saving the record.

Copy link
Contributor

Choose a reason for hiding this comment

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

Are you sure? This test was working fine before. It knows that the user exists because we are building a user with the same email address as the one that gets passed into the form in the line below this one. If you change the user's email address on line 12, the test will fail.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah. I see what you mean. The factory was saving the user, so it was acting as create instead of build. I think the fix is to stub User.find_with_email so that it returns a user. We want to minimize accessing the DB in specs. The user doesn't need a personal key in this spec.

Copy link
Contributor

Choose a reason for hiding this comment

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

Anyways, we can do this later since it's not specific to this PR.

Copy link
Contributor

@monfresh monfresh left a comment

Choose a reason for hiding this comment

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

LGTM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants