-
Notifications
You must be signed in to change notification settings - Fork 166
Complete path for users to setup an additional method #6276
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
Merged
Merged
Changes from all commits
Commits
Show all changes
27 commits
Select commit
Hold shift + click to select a range
9acd946
refactor two factor options to use partial, create mfa setup path
jmdembe 924c5f0
refactor mfa setup screen using partials and pass through path
jmdembe 4a5a48f
Fix tests and add title to mfa setup screen
jmdembe e24fe7b
address lint errors
jmdembe 9393561
fix tests again
jmdembe 94a08c6
move mfa setup path behind a the mfa selection feature flag
jmdembe 0303ffb
fix tests again
jmdembe cc11056
Merge branch 'main' into jd-finish-sad-path
jmdembe ff93ed1
change redirect to use confirmation path
jmdembe 4c9d201
Merge branch 'main' into jd-finish-sad-path
jmdembe d7687c6
Merge branch 'main' into jd-finish-sad-path
jmdembe f799faa
WIP: add test for mfa selection controller
jmdembe bb72d51
fix indentation
jmdembe d710d84
WIP: change tests for mfa selection controller
jmdembe 6b35b5e
write get test for mfa selection controller
jmdembe e4d8cd0
fix lint error
jmdembe 0d103ac
update controller action
jmdembe 87ae88c
change action, update test
jmdembe 2ae8a1d
Merge branch 'main' into jd-finish-sad-path
jmdembe fca7307
Merge branch 'main' into jd-finish-sad-path
jmdembe cb2ff9a
address style comments for spec
jmdembe 25fb7bb
Update spec/controllers/users/mfa_selection_controller_spec.rb
jmdembe 50f0d77
undo removal of analytics test
jmdembe 0e0c0ba
Merge branch 'main' into jd-finish-sad-path
jmdembe 880782d
Merge branch 'main' into jd-finish-sad-path
jmdembe 21a4581
reconcile changes with force selecting mfa option
jmdembe 25f05a0
fix test for reconciled partial
jmdembe File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| module Users | ||
| class MfaSelectionController < ApplicationController | ||
| include UserAuthenticator | ||
| include MfaSetupConcern | ||
|
|
||
| def index | ||
| @two_factor_options_form = TwoFactorOptionsForm.new(current_user) | ||
| @presenter = two_factor_options_presenter | ||
| analytics.track_event(Analytics::USER_REGISTRATION_2FA_SETUP_VISIT) | ||
| end | ||
|
|
||
| def update | ||
| result = submit_form | ||
| analytics.track_event(Analytics::USER_REGISTRATION_2FA_SETUP, result.to_h) | ||
|
|
||
| if result.success? | ||
| process_valid_form | ||
| else | ||
| @presenter = two_factor_options_presenter | ||
| render :index | ||
| end | ||
| end | ||
|
|
||
| private | ||
|
|
||
| def submit_form | ||
| @two_factor_options_form = TwoFactorOptionsForm.new(current_user) | ||
| @two_factor_options_form.submit(two_factor_options_form_params) | ||
| end | ||
|
|
||
| def two_factor_options_presenter | ||
| TwoFactorOptionsPresenter.new( | ||
| user_agent: request.user_agent, | ||
| user: current_user, | ||
| aal3_required: service_provider_mfa_policy.aal3_required?, | ||
| piv_cac_required: service_provider_mfa_policy.piv_cac_required?, | ||
| ) | ||
| end | ||
|
|
||
| def process_valid_form | ||
| user_session[:selected_mfa_options] = @two_factor_options_form.selection | ||
| redirect_to confirmation_path(user_session[:selected_mfa_options].first) | ||
| end | ||
|
|
||
| def two_factor_options_form_params | ||
| params.require(:two_factor_options_form).permit(:selection, selection: []) | ||
| end | ||
| end | ||
| end | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| <%= title t('two_factor_authentication.two_factor_choice') %> | ||
|
|
||
| <%= render PageHeadingComponent.new.with_content(t('two_factor_authentication.two_factor_choice')) %> | ||
|
|
||
| <% if IdentityConfig.store.select_multiple_mfa_options %> | ||
| <%= render AlertComponent.new(type: :info, class: 'margin-bottom-4') do %> | ||
| <%= t('mfa.info') %> | ||
| <% end %> | ||
| <% end %> | ||
|
|
||
| <%= validated_form_for @two_factor_options_form, | ||
| html: { autocomplete: 'off' }, | ||
| method: :patch, | ||
| url: mfa_setup_path do |f| %> | ||
| <div class="margin-bottom-4"> | ||
| <fieldset class="margin-0 padding-0 border-0"> | ||
| <legend class="margin-bottom-2 usa-sr-only"><%= @presenter.intro %></legend> | ||
| <% @presenter.options.each do |option| %> | ||
| <div id="<%= "select_#{option.type}" %>" class="<%= option.html_class %>"> | ||
| <%= render partial: 'partials/multi_factor_authentication/mfa_selection', | ||
| locals: { form: f, option: option } %> | ||
| </div> | ||
| <% end %> | ||
| </fieldset> | ||
| </div> | ||
|
|
||
| <%= f.button :submit, t('forms.buttons.continue'), class: 'usa-button--big usa-button--wide margin-bottom-1' %> | ||
| <% end %> | ||
|
|
||
| <%= render 'shared/cancel', link: destroy_user_session_path %> | ||
|
|
||
| <%= javascript_packs_tag_once('webauthn-unhide') %> | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
157 changes: 157 additions & 0 deletions
157
spec/controllers/users/mfa_selection_controller_spec.rb
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,157 @@ | ||
| require 'rails_helper' | ||
|
|
||
| describe Users::MfaSelectionController do | ||
| let(:current_sp) { create(:service_provider) } | ||
|
|
||
| describe '#index' do | ||
| before do | ||
| allow(IdentityConfig.store).to receive(:select_multiple_mfa_options).and_return(true) | ||
| user = build(:user, :signed_up) | ||
| stub_sign_in(user) | ||
| end | ||
|
|
||
| context 'when the user is using one authenticator option' do | ||
| it 'shows the mfa setup screen' do | ||
| controller.user_session[:selected_mfa_options] = ['backup_code'] | ||
|
|
||
| get :index | ||
|
|
||
| expect(response).to render_template(:index) | ||
| end | ||
| end | ||
| end | ||
|
|
||
| describe '#update' do | ||
| it 'submits the TwoFactorOptionsForm' do | ||
| user = build(:user) | ||
| stub_sign_in_before_2fa(user) | ||
|
|
||
| voice_params = { | ||
| two_factor_options_form: { | ||
| selection: 'voice', | ||
| }, | ||
| } | ||
| params = ActionController::Parameters.new(voice_params) | ||
| response = FormResponse.new(success: true, errors: {}, extra: { selection: ['voice'] }) | ||
|
|
||
| form = instance_double(TwoFactorOptionsForm) | ||
| allow(TwoFactorOptionsForm).to receive(:new).with(user).and_return(form) | ||
| expect(form).to receive(:submit). | ||
| with(params.require(:two_factor_options_form).permit(:selection)). | ||
| and_return(response) | ||
| expect(form).to receive(:selection).and_return(['voice']) | ||
|
|
||
| patch :update, params: voice_params | ||
jmdembe marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| end | ||
|
|
||
| context 'when the selection is phone' do | ||
| it 'redirects to phone setup page' do | ||
| stub_sign_in_before_2fa | ||
|
|
||
| patch :update, params: { | ||
| two_factor_options_form: { | ||
| selection: 'phone', | ||
| }, | ||
| } | ||
|
|
||
| expect(response).to redirect_to phone_setup_url | ||
| end | ||
| end | ||
|
|
||
| context 'when multi selection with phone first' do | ||
| it 'redirects properly' do | ||
| stub_sign_in_before_2fa | ||
| patch :update, params: { | ||
| two_factor_options_form: { | ||
| selection: ['phone', 'auth_app'], | ||
| }, | ||
| } | ||
|
|
||
| expect(response).to redirect_to phone_setup_url | ||
| end | ||
| end | ||
|
|
||
| context 'when multi selection with auth app first' do | ||
| it 'redirects properly' do | ||
| stub_sign_in_before_2fa | ||
| patch :update, params: { | ||
| two_factor_options_form: { | ||
| selection: ['auth_app', 'phone', 'webauthn'], | ||
| }, | ||
| } | ||
|
|
||
| expect(response).to redirect_to authenticator_setup_url | ||
| end | ||
| end | ||
|
|
||
| context 'when the selection is auth_app' do | ||
| it 'redirects to authentication app setup page' do | ||
| stub_sign_in_before_2fa | ||
|
|
||
| patch :update, params: { | ||
| two_factor_options_form: { | ||
| selection: 'auth_app', | ||
| }, | ||
| } | ||
|
|
||
| expect(response).to redirect_to authenticator_setup_url | ||
| end | ||
| end | ||
|
|
||
| context 'when the selection is webauthn' do | ||
| it 'redirects to webauthn setup page' do | ||
| stub_sign_in_before_2fa | ||
|
|
||
| patch :update, params: { | ||
| two_factor_options_form: { | ||
| selection: 'webauthn', | ||
| }, | ||
| } | ||
|
|
||
| expect(response).to redirect_to webauthn_setup_url | ||
| end | ||
| end | ||
|
|
||
| context 'when the selection is webauthn platform authenticator' do | ||
| it 'redirects to webauthn setup page with the platform param' do | ||
| stub_sign_in_before_2fa | ||
|
|
||
| patch :update, params: { | ||
| two_factor_options_form: { | ||
| selection: 'webauthn_platform', | ||
| }, | ||
| } | ||
|
|
||
| expect(response).to redirect_to webauthn_setup_url(platform: true) | ||
| end | ||
| end | ||
|
|
||
| context 'when the selection is piv_cac' do | ||
| it 'redirects to piv/cac setup page' do | ||
| stub_sign_in_before_2fa | ||
|
|
||
| patch :update, params: { | ||
| two_factor_options_form: { | ||
| selection: 'piv_cac', | ||
| }, | ||
| } | ||
|
|
||
| expect(response).to redirect_to setup_piv_cac_url | ||
| end | ||
| end | ||
|
|
||
| context 'when the selection is not valid' do | ||
| it 'renders index page' do | ||
| stub_sign_in_before_2fa | ||
|
|
||
| patch :update, params: { | ||
| two_factor_options_form: { | ||
| selection: 'foo', | ||
| }, | ||
| } | ||
|
|
||
| expect(response).to render_template(:index) | ||
| end | ||
| end | ||
| end | ||
| end | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
can we ensure user is authenticated.
We also want to ensure that users arrive at this page properly.
before_action :authenticate_user before_action :confirm_user_authenticated_for_2fa_setupThere 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.
Was this suggestion implemented?
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.
it had been originally, but I believe what happened is that with a merge that I had to make with another PR that it got lost in a merge somewhere. I created a patch in LG-6236