Skip to content

[LG-423] Redirect piv/cac errors to cleanup url#2380

Merged
jgsmith-usds merged 1 commit intomasterfrom
jgs/lg-423-redirect-to-view-for-pivcac-token
Aug 20, 2018
Merged

[LG-423] Redirect piv/cac errors to cleanup url#2380
jgsmith-usds merged 1 commit intomasterfrom
jgs/lg-423-redirect-to-view-for-pivcac-token

Conversation

@jgsmith-usds
Copy link
Contributor

@jgsmith-usds jgsmith-usds commented Jul 25, 2018

Why:
We want to remove the token from the piv/cac service so
that it doesn't leak into logs or other services.

How:
When there's an error, we store the messaging in the flash
and redirect to the same page to show the error and provide
another attempt.

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.

if params.key?(:token)
process_piv_cac_setup
elsif flash[:error].present?
render :error
Copy link
Contributor

Choose a reason for hiding this comment

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

Code Climate says this is not tested.

it 'renders the error template' do
get :new, params: { token: bad_token }
expect(response).to render_template(:error)
expect(response).to redirect_to setup_piv_cac_path
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we move this to a feature spec, please? We learned from a recent production 500 error that controller specs that don't render views will not catch any issues with views that call objects such as presenters.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'll add a feature spec to check for this. That should catch the untested line above. In personal manual testing, this worked, but it would be nice to know it works down the road if we change things up.

@jgsmith-usds jgsmith-usds force-pushed the jgs/lg-423-redirect-to-view-for-pivcac-token branch from 94d3bc4 to 6129dd0 Compare August 8, 2018 20:00
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there a reason we can't use @presenter.description and @presenter.heading directly in the view?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We redirect before showing the view, so we don't have a presenter with the information.

Copy link
Contributor

Choose a reason for hiding this comment

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

I see. I would have suggested passing in the error as a params, and then defining the presenter before rendering the error view:

elsif flash[:error].present?
  @presenter = PivCacAuthenticationSetupErrorPresenter.new(params[:error])
  render :error
end

The problem is that the presenter class expects to be initialized with an entire form object, even though the only thing it needs from it is its error_type. The solution is to change the presenter to be initialized with the error, but that's a refactoring for later. The controller would look like this:

def process_invalid_submission
  form_error = user_piv_cac_form.error_type
  @presenter = PivCacAuthenticationSetupErrorPresenter.new(form_error)
  clear_piv_cac_information
  flash[:error] = @presenter.title
  redirect_to setup_piv_cac_url(error: form_error)
end

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point. I was trying to keep the error condition out of the URL, but I could have just put that in the flash and rebuilt the presenter from there after the redirect.

monfresh
monfresh previously approved these changes Aug 10, 2018
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

@jgsmith-usds jgsmith-usds force-pushed the jgs/lg-423-redirect-to-view-for-pivcac-token branch 2 times, most recently from 700fbdc to bbbb301 Compare August 13, 2018 19:19
**Why**:
We want to remove the token from the piv/cac service so
that it doesn't leak into logs or other services.

**How**:
When there's an error, we store the messaging in the flash
and redirect to the same page to show the error and provide
another attempt.
@jgsmith-usds jgsmith-usds force-pushed the jgs/lg-423-redirect-to-view-for-pivcac-token branch from bbbb301 to b58d77f Compare August 13, 2018 19:23
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

@jgsmith-usds jgsmith-usds merged commit 41f7315 into master Aug 20, 2018
@jgsmith-usds jgsmith-usds deleted the jgs/lg-423-redirect-to-view-for-pivcac-token branch August 20, 2018 12:58
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