-
Notifications
You must be signed in to change notification settings - Fork 166
[LG-358] Allow piv/cac as 2fa for account creation #2234
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| class TwoFactorOptionsPresenter | ||
| include ActionView::Helpers::TranslationHelper | ||
|
|
||
| attr_reader :current_user, :service_provider | ||
|
|
||
| def initialize(current_user, sp) | ||
| @current_user = current_user | ||
| @service_provider = sp | ||
| end | ||
|
|
||
| def title | ||
| t('titles.two_factor_setup') | ||
| end | ||
|
|
||
| def heading | ||
| t('devise.two_factor_authentication.two_factor_choice') | ||
| end | ||
|
|
||
| def info | ||
| t('devise.two_factor_authentication.two_factor_choice_intro') | ||
| end | ||
|
|
||
| def label | ||
| t('forms.two_factor_choice.legend') + ':' | ||
| end | ||
|
|
||
| def options | ||
| available_2fa_types.map do |type| | ||
| OpenStruct.new( | ||
| type: type, | ||
| label: t("devise.two_factor_authentication.two_factor_choice_options.#{type}"), | ||
| info: t("devise.two_factor_authentication.two_factor_choice_options.#{type}_info"), | ||
| selected: type == :sms | ||
| ) | ||
| end | ||
| end | ||
|
|
||
| private | ||
|
|
||
| def available_2fa_types | ||
| %w[sms voice auth_app] + piv_cac_if_available | ||
| end | ||
|
|
||
| def piv_cac_if_available | ||
| return [] if current_user.piv_cac_enabled? | ||
| return [] unless current_user.piv_cac_available? || service_provider&.piv_cac_available? | ||
| %w[piv_cac] | ||
| end | ||
| end |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,40 +1,25 @@ | ||
| - title t('titles.two_factor_setup') | ||
| - title @presenter.title | ||
|
|
||
| h1.h3.my0 = t('devise.two_factor_authentication.two_factor_choice') | ||
| p.mt-tiny.mb3 | ||
| = t('devise.two_factor_authentication.two_factor_choice_intro') | ||
| h1.h3.my0 = @presenter.heading | ||
| p.mt-tiny.mb3 = @presenter.info | ||
|
|
||
| = simple_form_for(@two_factor_options_form, | ||
| html: { autocomplete: 'off', role: 'form' }, | ||
| method: :patch, | ||
| url: two_factor_options_path) do |f| | ||
| .mb3 | ||
| fieldset.m0.p0.border-none. | ||
| legend.mb1.h4.serif.bold = t('forms.two_factor_choice.legend') + ':' | ||
| label.btn-border.col-12.mb1 for="two_factor_options_form_selection_sms" | ||
| .radio | ||
| = radio_button_tag 'two_factor_options_form[selection]', :sms, true | ||
| span.indicator.mt-tiny | ||
| span.blue.bold.fs-20p | ||
| = t('devise.two_factor_authentication.two_factor_choice_options.sms') | ||
| .regular.gray-dark.fs-10p.mb-tiny | ||
| = t('devise.two_factor_authentication.two_factor_choice_options.sms_info') | ||
| label.btn-border.col-12.mb1 for="two_factor_options_form_selection_voice" | ||
| .radio | ||
| = radio_button_tag 'two_factor_options_form[selection]', :voice, false | ||
| span.indicator.mt-tiny | ||
| span.blue.bold.fs-20p | ||
| = t('devise.two_factor_authentication.two_factor_choice_options.voice') | ||
| .regular.gray-dark.fs-10p.mb-tiny | ||
| = t('devise.two_factor_authentication.two_factor_choice_options.voice_info') | ||
| label.btn-border.col-12.mb1 for="two_factor_options_form_selection_auth_app" | ||
| .radio | ||
| = radio_button_tag 'two_factor_options_form[selection]', :auth_app, false | ||
| span.indicator.mt-tiny | ||
| span.blue.bold.fs-20p | ||
| = t('devise.two_factor_authentication.two_factor_choice_options.auth_app') | ||
| .regular.gray-dark.fs-10p.mb-tiny | ||
| = t('devise.two_factor_authentication.two_factor_choice_options.auth_app_info') | ||
| legend.mb1.h4.serif.bold = @presenter.label | ||
| - @presenter.options.each do |option| | ||
| label.btn-border.col-12.mb1 for="two_factor_options_form_selection_#{option.type}" | ||
| .radio | ||
| = radio_button_tag('two_factor_options_form[selection]', | ||
| option.type, | ||
| @two_factor_options_form.selected?(option.type)) | ||
| span.indicator.mt-tiny | ||
| span.blue.bold.fs-20p = option.label | ||
| .regular.gray-dark.fs-10p.mb-tiny = option.info | ||
|
|
||
| = f.button :submit, t('forms.buttons.continue') | ||
|
|
||
| = render 'shared/cancel', link: destroy_user_session_path |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -163,6 +163,42 @@ | |
| expect(page).to have_current_path account_path | ||
| end | ||
|
|
||
| it 'does not allow a user to choose piv/cac as 2FA method during sign up' do | ||
|
||
| allow(PivCacService).to receive(:piv_cac_available_for_agency?).and_return(false) | ||
| allow(FeatureManagement).to receive(:piv_cac_enabled?).and_return(true) | ||
| begin_sign_up_with_sp_and_loa(loa3: false) | ||
|
|
||
| expect(page).to have_current_path two_factor_options_path | ||
| expect(page).not_to have_content( | ||
| t('devise.two_factor_authentication.two_factor_choice_options.piv_cac') | ||
| ) | ||
| end | ||
|
|
||
| context 'when piv/cac is allowed' do | ||
| it 'allows a user to choose piv/cac as 2FA method during sign up' do | ||
| allow(PivCacService).to receive(:piv_cac_available_for_agency?).and_return(true) | ||
| allow(FeatureManagement).to receive(:piv_cac_enabled?).and_return(true) | ||
|
|
||
| begin_sign_up_with_sp_and_loa(loa3: false) | ||
|
|
||
| expect(page).to have_current_path two_factor_options_path | ||
| expect(page).to have_content( | ||
| t('devise.two_factor_authentication.two_factor_choice_options.piv_cac') | ||
| ) | ||
| end | ||
|
|
||
| it 'directs to the piv/cac setup page' do | ||
| allow(PivCacService).to receive(:piv_cac_available_for_agency?).and_return(true) | ||
| allow(FeatureManagement).to receive(:piv_cac_enabled?).and_return(true) | ||
|
|
||
| begin_sign_up_with_sp_and_loa(loa3: false) | ||
|
|
||
| expect(page).to have_current_path two_factor_options_path | ||
| select_2fa_option('piv_cac') | ||
| expect(page).to have_current_path setup_piv_cac_path | ||
| end | ||
| end | ||
|
|
||
| it 'does not bypass 2FA when accessing authenticator_setup_path if the user is 2FA enabled' do | ||
| user = create(:user, :signed_up) | ||
| sign_in_user(user) | ||
|
|
||
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.
Should the last 2 conditions be reversed, so that if someone has both PIV/CAC and phone, it defaults to PIV/CAC?
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 was going for minimal touch on this. If doing so doesn't result in a mass of tests breaking, I don't see why I wouldn't. Let me see what happens.