Skip to content

Commit

Permalink
LG-11147: Break up MFA selection presenter classes for PivCac (#9581)
Browse files Browse the repository at this point in the history
* create setup and sign in piv cac files

* remove login and setup label

changelog: Internal, Presenter improvements, break up PIV/CAC presenter

* make changes in configuration and two fact options presenter

* create setup piv cac selection presenter

* test for sign in piv cac selection presenter

* run the build again

* modify set up piv_cac_selection_presenter and spec

* delete piv_cac_presenter, modify two factor login options presenter

* more fixing up two factor login options presenter spec

* more changes for piv cac setup and sign in presenters

* modify for set up piv cac selection

* mess with setup selection presenter some more

* fix setup test

* delete `configuration` from test
  • Loading branch information
jmdembe authored Nov 15, 2023
1 parent 6b1150a commit 6a38687
Show file tree
Hide file tree
Showing 11 changed files with 88 additions and 38 deletions.
2 changes: 1 addition & 1 deletion app/models/piv_cac_configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ def mfa_enabled?

def selection_presenters
if mfa_enabled?
[TwoFactorAuthentication::PivCacSelectionPresenter.new(user:, configuration: self)]
[TwoFactorAuthentication::SignInPivCacSelectionPresenter.new(user:, configuration: self)]
else
[]
end
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 'piv_cac'
t('two_factor_authentication.login_options.piv_cac')
when 'sms'
t('two_factor_authentication.login_options.sms')
when 'voice'
Expand All @@ -82,8 +80,6 @@ def login_label(type)

def setup_label(type)
case type
when 'piv_cac'
t('two_factor_authentication.two_factor_choice_options.piv_cac')
when 'phone'
t('two_factor_authentication.two_factor_choice_options.phone')
when 'sms'
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
module TwoFactorAuthentication
class SetUpPivCacSelectionPresenter < SetUpSelectionPresenter
def method
:piv_cac
end

def label
t('two_factor_authentication.two_factor_choice_options.piv_cac')
end

def info
t('two_factor_authentication.two_factor_choice_options.piv_cac_info')
end

def single_configuration_only?
true
end

def mfa_configuration_count
user.piv_cac_configurations.count
end
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
module TwoFactorAuthentication
class SignInPivCacSelectionPresenter < SignInSelectionPresenter
def method
:piv_cac
end

def label
t('two_factor_authentication.login_options.piv_cac')
end

def info
t('two_factor_authentication.login_options.piv_cac_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 @@ -37,7 +37,7 @@ def all_user_selected_options
TwoFactorAuthentication::PhoneSelectionPresenter.new(user: user),
TwoFactorAuthentication::SetUpBackupCodeSelectionPresenter.new(user: user),
TwoFactorAuthentication::SetUpWebauthnSelectionPresenter.new(user: user),
TwoFactorAuthentication::PivCacSelectionPresenter.new(user: user),
TwoFactorAuthentication::SetUpPivCacSelectionPresenter.new(user: user),
]
end

Expand Down Expand Up @@ -99,7 +99,7 @@ def skip_label

def piv_cac_option
return [] unless current_device_is_desktop?
[TwoFactorAuthentication::PivCacSelectionPresenter.new(user: user)]
[TwoFactorAuthentication::SetUpPivCacSelectionPresenter.new(user: user)]
end

def webauthn_option
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
require 'rails_helper'

RSpec.describe TwoFactorAuthentication::PivCacSelectionPresenter do
RSpec.describe TwoFactorAuthentication::SetUpPivCacSelectionPresenter do
let(:user_without_mfa) { create(:user) }
let(:user_with_mfa) { create(:user, :with_piv_or_cac) }
let(:configuration) {}
let(:presenter_without_mfa) do
described_class.new(configuration: configuration, user: user_without_mfa)
described_class.new(user: user_without_mfa)
end
let(:presenter_with_mfa) do
described_class.new(configuration: configuration, user: user_with_mfa)
described_class.new(user: user_with_mfa)
end

describe '#type' do
Expand All @@ -18,10 +17,10 @@
end

describe '#mfa_configruation' do
it 'returns an empty string when user has not configured this authenticator' do
it 'returns an empty string when user has not configured piv/cac' do
expect(presenter_without_mfa.mfa_configuration_description).to eq('')
end
it 'returns the translated string for added when user has configured this authenticator' do
it 'returns the translated string for added when user has configured piv/cac' do
expect(presenter_with_mfa.mfa_configuration_description).to eq(
t(
'two_factor_authentication.two_factor_choice_options.no_count_configuration_added',
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
require 'rails_helper'

RSpec.describe TwoFactorAuthentication::SignInPivCacSelectionPresenter do
let(:user) { create(:user) }
let(:configuration) { create(:piv_cac_configuration, user: user) }

let(:presenter) do
described_class.new(user: user, configuration: configuration)
end

describe '#type' do
it 'returns piv_cac' do
expect(presenter.type).to eq 'piv_cac'
end
end

describe '#label' do
it 'returns the label text' do
expect(presenter.label).to eq(
t('two_factor_authentication.two_factor_choice_options.piv_cac'),
)
end
end

describe '#info' do
it 'returns the info text' do
expect(presenter.info).to eq(
t('two_factor_authentication.login_options.piv_cac_info'),
)
end
end
end
10 changes: 5 additions & 5 deletions spec/presenters/two_factor_login_options_presenter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@
TwoFactorAuthentication::VoiceSelectionPresenter,
TwoFactorAuthentication::SignInWebauthnSelectionPresenter,
TwoFactorAuthentication::SignInBackupCodeSelectionPresenter,
TwoFactorAuthentication::PivCacSelectionPresenter,
TwoFactorAuthentication::SignInPivCacSelectionPresenter,
TwoFactorAuthentication::SignInAuthAppSelectionPresenter,
TwoFactorAuthentication::SignInPersonalKeySelectionPresenter,
],
Expand All @@ -105,7 +105,7 @@
let(:piv_cac_required) { true }

it 'filters to piv method' do
expect(options_classes).to eq([TwoFactorAuthentication::PivCacSelectionPresenter])
expect(options_classes).to eq([TwoFactorAuthentication::SignInPivCacSelectionPresenter])
end

context 'in reauthentication context' do
Expand All @@ -118,7 +118,7 @@
TwoFactorAuthentication::VoiceSelectionPresenter,
TwoFactorAuthentication::SignInWebauthnSelectionPresenter,
TwoFactorAuthentication::SignInBackupCodeSelectionPresenter,
TwoFactorAuthentication::PivCacSelectionPresenter,
TwoFactorAuthentication::SignInPivCacSelectionPresenter,
TwoFactorAuthentication::SignInAuthAppSelectionPresenter,
TwoFactorAuthentication::SignInPersonalKeySelectionPresenter,
],
Expand All @@ -134,7 +134,7 @@
expect(options_classes).to eq(
[
TwoFactorAuthentication::SignInWebauthnSelectionPresenter,
TwoFactorAuthentication::PivCacSelectionPresenter,
TwoFactorAuthentication::SignInPivCacSelectionPresenter,
],
)
end
Expand All @@ -149,7 +149,7 @@
TwoFactorAuthentication::VoiceSelectionPresenter,
TwoFactorAuthentication::SignInWebauthnSelectionPresenter,
TwoFactorAuthentication::SignInBackupCodeSelectionPresenter,
TwoFactorAuthentication::PivCacSelectionPresenter,
TwoFactorAuthentication::SignInPivCacSelectionPresenter,
TwoFactorAuthentication::SignInAuthAppSelectionPresenter,
TwoFactorAuthentication::SignInPersonalKeySelectionPresenter,
],
Expand Down
8 changes: 4 additions & 4 deletions spec/presenters/two_factor_options_presenter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
TwoFactorAuthentication::PhoneSelectionPresenter,
TwoFactorAuthentication::SetUpBackupCodeSelectionPresenter,
TwoFactorAuthentication::SetUpWebauthnSelectionPresenter,
TwoFactorAuthentication::PivCacSelectionPresenter,
TwoFactorAuthentication::SetUpPivCacSelectionPresenter,
]
end

Expand All @@ -46,7 +46,7 @@
expect(presenter.options.map(&:class)).to eq [
TwoFactorAuthentication::SetUpWebauthnPlatformSelectionPresenter,
TwoFactorAuthentication::SetUpWebauthnSelectionPresenter,
TwoFactorAuthentication::PivCacSelectionPresenter,
TwoFactorAuthentication::SetUpPivCacSelectionPresenter,
]
end
end
Expand All @@ -62,7 +62,7 @@
TwoFactorAuthentication::SetUpAuthAppSelectionPresenter,
TwoFactorAuthentication::SetUpBackupCodeSelectionPresenter,
TwoFactorAuthentication::SetUpWebauthnSelectionPresenter,
TwoFactorAuthentication::PivCacSelectionPresenter,
TwoFactorAuthentication::SetUpPivCacSelectionPresenter,
]
end
end
Expand All @@ -79,7 +79,7 @@
TwoFactorAuthentication::PhoneSelectionPresenter,
TwoFactorAuthentication::SetUpBackupCodeSelectionPresenter,
TwoFactorAuthentication::SetUpWebauthnSelectionPresenter,
TwoFactorAuthentication::PivCacSelectionPresenter,
TwoFactorAuthentication::SetUpPivCacSelectionPresenter,
]
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@
render partial: 'mfa_selection', locals: {
form: form_builder,
option: presenter.options.find do |option|
option.is_a?(TwoFactorAuthentication::PivCacSelectionPresenter)
option.is_a?(TwoFactorAuthentication::SetUpPivCacSelectionPresenter)
end,
}
end
Expand Down

0 comments on commit 6a38687

Please sign in to comment.