diff --git a/app/models/backup_code_configuration.rb b/app/models/backup_code_configuration.rb index 4a3bab4648d..8cbb9e0f825 100644 --- a/app/models/backup_code_configuration.rb +++ b/app/models/backup_code_configuration.rb @@ -14,7 +14,7 @@ def mfa_enabled? end def selection_presenters - [TwoFactorAuthentication::BackupCodeSelectionPresenter.new(user:, configuration: self)] + [TwoFactorAuthentication::SignInBackupCodeSelectionPresenter.new(user:, configuration: self)] end def friendly_name diff --git a/app/presenters/two_factor_authentication/backup_code_selection_presenter.rb b/app/presenters/two_factor_authentication/backup_code_selection_presenter.rb deleted file mode 100644 index 63a038a67ca..00000000000 --- a/app/presenters/two_factor_authentication/backup_code_selection_presenter.rb +++ /dev/null @@ -1,15 +0,0 @@ -module TwoFactorAuthentication - class BackupCodeSelectionPresenter < SelectionPresenter - def method - :backup_code - end - - def single_configuration_only? - true - end - - def mfa_configuration_count - user.backup_code_configurations.unused.count - end - end -end diff --git a/app/presenters/two_factor_authentication/selection_presenter.rb b/app/presenters/two_factor_authentication/selection_presenter.rb index 63adc3e3456..2a1eb22279e 100644 --- a/app/presenters/two_factor_authentication/selection_presenter.rb +++ b/app/presenters/two_factor_authentication/selection_presenter.rb @@ -69,8 +69,6 @@ def disabled? def login_label(type) case type - when 'backup_code' - t('two_factor_authentication.login_options.backup_code') when 'piv_cac' t('two_factor_authentication.login_options.piv_cac') when 'sms' @@ -84,8 +82,6 @@ def login_label(type) def setup_label(type) case type - when 'backup_code' - t('two_factor_authentication.two_factor_choice_options.backup_code') when 'piv_cac' t('two_factor_authentication.two_factor_choice_options.piv_cac') when 'phone' diff --git a/app/presenters/two_factor_authentication/set_up_backup_code_selection_presenter.rb b/app/presenters/two_factor_authentication/set_up_backup_code_selection_presenter.rb new file mode 100644 index 00000000000..890ad3248a9 --- /dev/null +++ b/app/presenters/two_factor_authentication/set_up_backup_code_selection_presenter.rb @@ -0,0 +1,23 @@ +module TwoFactorAuthentication + class SetUpBackupCodeSelectionPresenter < SetUpSelectionPresenter + def method + :backup_code + end + + def label + t('two_factor_authentication.two_factor_choice_options.backup_code') + end + + def info + t('two_factor_authentication.two_factor_choice_options.backup_code_info') + end + + def single_configuration_only? + true + end + + def mfa_configuration_count + user.backup_code_configurations.unused.count + end + end +end diff --git a/app/presenters/two_factor_authentication/sign_in_backup_code_selection_presenter.rb b/app/presenters/two_factor_authentication/sign_in_backup_code_selection_presenter.rb new file mode 100644 index 00000000000..40b65dcff3b --- /dev/null +++ b/app/presenters/two_factor_authentication/sign_in_backup_code_selection_presenter.rb @@ -0,0 +1,15 @@ +module TwoFactorAuthentication + class SignInBackupCodeSelectionPresenter < SignInSelectionPresenter + def method + :backup_code + end + + def label + t('two_factor_authentication.login_options.backup_code') + end + + def info + t('two_factor_authentication.login_options.backup_code_info') + end + end +end diff --git a/app/presenters/two_factor_options_presenter.rb b/app/presenters/two_factor_options_presenter.rb index 1cb2418f111..2ce6d138f28 100644 --- a/app/presenters/two_factor_options_presenter.rb +++ b/app/presenters/two_factor_options_presenter.rb @@ -35,7 +35,7 @@ def all_user_selected_options TwoFactorAuthentication::SetUpWebauthnPlatformSelectionPresenter.new(user: user), TwoFactorAuthentication::SetUpAuthAppSelectionPresenter.new(user: user), TwoFactorAuthentication::PhoneSelectionPresenter.new(user: user), - TwoFactorAuthentication::BackupCodeSelectionPresenter.new(user: user), + TwoFactorAuthentication::SetUpBackupCodeSelectionPresenter.new(user: user), TwoFactorAuthentication::SetUpWebauthnSelectionPresenter.new(user: user), TwoFactorAuthentication::PivCacSelectionPresenter.new(user: user), ] @@ -127,7 +127,7 @@ def totp_option def backup_code_option return [] if piv_cac_required? || phishing_resistant_only? - [TwoFactorAuthentication::BackupCodeSelectionPresenter.new(user: user)] + [TwoFactorAuthentication::SetUpBackupCodeSelectionPresenter.new(user: user)] end def current_device_is_desktop? diff --git a/spec/models/backup_code_configuration_spec.rb b/spec/models/backup_code_configuration_spec.rb index 9a346dd7278..dc0c3787975 100644 --- a/spec/models/backup_code_configuration_spec.rb +++ b/spec/models/backup_code_configuration_spec.rb @@ -140,7 +140,8 @@ def save_and_find(find:, save: 'just-some-not-null-value') bc = BackupCodeConfiguration.new set = BackupCodeConfiguration.selection_presenters([bc]) - expect(set.first).instance_of? TwoFactorAuthentication::BackupCodeSelectionPresenter.class + expect(set.first). + instance_of? TwoFactorAuthentication::SignInBackupCodeSelectionPresenter.class end it 'returns only one selection presenter if multiple backup code configurations' do @@ -148,7 +149,8 @@ def save_and_find(find:, save: 'just-some-not-null-value') bc2 = BackupCodeConfiguration.new set = BackupCodeConfiguration.selection_presenters([bc, bc2]) - expect(set.first).instance_of? TwoFactorAuthentication::BackupCodeSelectionPresenter.class + expect(set.first). + instance_of? TwoFactorAuthentication::SignInBackupCodeSelectionPresenter.class expect(set.size).to eq(1) end end diff --git a/spec/presenters/two_factor_login_options_presenter_spec.rb b/spec/presenters/two_factor_login_options_presenter_spec.rb index 4a348d9ba15..f479aae3000 100644 --- a/spec/presenters/two_factor_login_options_presenter_spec.rb +++ b/spec/presenters/two_factor_login_options_presenter_spec.rb @@ -85,7 +85,7 @@ TwoFactorAuthentication::SmsSelectionPresenter, TwoFactorAuthentication::VoiceSelectionPresenter, TwoFactorAuthentication::SignInWebauthnSelectionPresenter, - TwoFactorAuthentication::BackupCodeSelectionPresenter, + TwoFactorAuthentication::SignInBackupCodeSelectionPresenter, TwoFactorAuthentication::PivCacSelectionPresenter, TwoFactorAuthentication::SignInAuthAppSelectionPresenter, TwoFactorAuthentication::SignInPersonalKeySelectionPresenter, @@ -117,7 +117,7 @@ TwoFactorAuthentication::SmsSelectionPresenter, TwoFactorAuthentication::VoiceSelectionPresenter, TwoFactorAuthentication::SignInWebauthnSelectionPresenter, - TwoFactorAuthentication::BackupCodeSelectionPresenter, + TwoFactorAuthentication::SignInBackupCodeSelectionPresenter, TwoFactorAuthentication::PivCacSelectionPresenter, TwoFactorAuthentication::SignInAuthAppSelectionPresenter, TwoFactorAuthentication::SignInPersonalKeySelectionPresenter, @@ -148,7 +148,7 @@ TwoFactorAuthentication::SmsSelectionPresenter, TwoFactorAuthentication::VoiceSelectionPresenter, TwoFactorAuthentication::SignInWebauthnSelectionPresenter, - TwoFactorAuthentication::BackupCodeSelectionPresenter, + TwoFactorAuthentication::SignInBackupCodeSelectionPresenter, TwoFactorAuthentication::PivCacSelectionPresenter, TwoFactorAuthentication::SignInAuthAppSelectionPresenter, TwoFactorAuthentication::SignInPersonalKeySelectionPresenter, diff --git a/spec/presenters/two_factor_options_presenter_spec.rb b/spec/presenters/two_factor_options_presenter_spec.rb index 52f2acf6ab0..3ba33e567a6 100644 --- a/spec/presenters/two_factor_options_presenter_spec.rb +++ b/spec/presenters/two_factor_options_presenter_spec.rb @@ -28,7 +28,7 @@ TwoFactorAuthentication::SetUpWebauthnPlatformSelectionPresenter, TwoFactorAuthentication::SetUpAuthAppSelectionPresenter, TwoFactorAuthentication::PhoneSelectionPresenter, - TwoFactorAuthentication::BackupCodeSelectionPresenter, + TwoFactorAuthentication::SetUpBackupCodeSelectionPresenter, TwoFactorAuthentication::SetUpWebauthnSelectionPresenter, TwoFactorAuthentication::PivCacSelectionPresenter, ] @@ -60,7 +60,24 @@ expect(presenter.options.map(&:class)).to eq [ TwoFactorAuthentication::SetUpWebauthnPlatformSelectionPresenter, TwoFactorAuthentication::SetUpAuthAppSelectionPresenter, - TwoFactorAuthentication::BackupCodeSelectionPresenter, + TwoFactorAuthentication::SetUpBackupCodeSelectionPresenter, + TwoFactorAuthentication::SetUpWebauthnSelectionPresenter, + TwoFactorAuthentication::PivCacSelectionPresenter, + ] + end + end + context 'when platform_auth_set_up_enabled is enabled' do + before do + allow(IdentityConfig.store).to receive(:platform_auth_set_up_enabled). + and_return(true) + end + + it 'supplies all the options except webauthn' do + expect(presenter.options.map(&:class)).to eq [ + TwoFactorAuthentication::SetUpWebauthnPlatformSelectionPresenter, + TwoFactorAuthentication::SetUpAuthAppSelectionPresenter, + TwoFactorAuthentication::PhoneSelectionPresenter, + TwoFactorAuthentication::SetUpBackupCodeSelectionPresenter, TwoFactorAuthentication::SetUpWebauthnSelectionPresenter, TwoFactorAuthentication::PivCacSelectionPresenter, ] diff --git a/spec/views/partials/multi_factor_authentication/_mfa_selection.html.erb_spec.rb b/spec/views/partials/multi_factor_authentication/_mfa_selection.html.erb_spec.rb index 0ad3bfa59d0..c92ee6507e5 100644 --- a/spec/views/partials/multi_factor_authentication/_mfa_selection.html.erb_spec.rb +++ b/spec/views/partials/multi_factor_authentication/_mfa_selection.html.erb_spec.rb @@ -79,7 +79,7 @@ render partial: 'mfa_selection', locals: { form: form_builder, option: presenter.options.find do |option| - option.is_a?(TwoFactorAuthentication::BackupCodeSelectionPresenter) + option.is_a?(TwoFactorAuthentication::SetUpBackupCodeSelectionPresenter) end, } end