Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/models/backup_code_configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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'
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
4 changes: 2 additions & 2 deletions app/presenters/two_factor_options_presenter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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),
]
Expand Down Expand Up @@ -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?
Expand Down
6 changes: 4 additions & 2 deletions spec/models/backup_code_configuration_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -140,15 +140,17 @@ 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
bc = BackupCodeConfiguration.new
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
Expand Down
6 changes: 3 additions & 3 deletions spec/presenters/two_factor_login_options_presenter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@
TwoFactorAuthentication::SmsSelectionPresenter,
TwoFactorAuthentication::VoiceSelectionPresenter,
TwoFactorAuthentication::SignInWebauthnSelectionPresenter,
TwoFactorAuthentication::BackupCodeSelectionPresenter,
TwoFactorAuthentication::SignInBackupCodeSelectionPresenter,
TwoFactorAuthentication::PivCacSelectionPresenter,
TwoFactorAuthentication::SignInAuthAppSelectionPresenter,
TwoFactorAuthentication::SignInPersonalKeySelectionPresenter,
Expand Down Expand Up @@ -117,7 +117,7 @@
TwoFactorAuthentication::SmsSelectionPresenter,
TwoFactorAuthentication::VoiceSelectionPresenter,
TwoFactorAuthentication::SignInWebauthnSelectionPresenter,
TwoFactorAuthentication::BackupCodeSelectionPresenter,
TwoFactorAuthentication::SignInBackupCodeSelectionPresenter,
TwoFactorAuthentication::PivCacSelectionPresenter,
TwoFactorAuthentication::SignInAuthAppSelectionPresenter,
TwoFactorAuthentication::SignInPersonalKeySelectionPresenter,
Expand Down Expand Up @@ -148,7 +148,7 @@
TwoFactorAuthentication::SmsSelectionPresenter,
TwoFactorAuthentication::VoiceSelectionPresenter,
TwoFactorAuthentication::SignInWebauthnSelectionPresenter,
TwoFactorAuthentication::BackupCodeSelectionPresenter,
TwoFactorAuthentication::SignInBackupCodeSelectionPresenter,
TwoFactorAuthentication::PivCacSelectionPresenter,
TwoFactorAuthentication::SignInAuthAppSelectionPresenter,
TwoFactorAuthentication::SignInPersonalKeySelectionPresenter,
Expand Down
21 changes: 19 additions & 2 deletions spec/presenters/two_factor_options_presenter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
TwoFactorAuthentication::SetUpWebauthnPlatformSelectionPresenter,
TwoFactorAuthentication::SetUpAuthAppSelectionPresenter,
TwoFactorAuthentication::PhoneSelectionPresenter,
TwoFactorAuthentication::BackupCodeSelectionPresenter,
TwoFactorAuthentication::SetUpBackupCodeSelectionPresenter,
TwoFactorAuthentication::SetUpWebauthnSelectionPresenter,
TwoFactorAuthentication::PivCacSelectionPresenter,
]
Expand Down Expand Up @@ -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,
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down