From d3e9073bfd9bb21eead7dcc12ab892f87162e28f Mon Sep 17 00:00:00 2001 From: Malick Diarra Date: Tue, 12 Sep 2023 11:12:26 -0400 Subject: [PATCH 01/11] commit --- .../set_up_auth_app_selection_presenter.rb | 12 +++ .../set_up_selection_presenter.rb | 79 +++++++++++++++++++ 2 files changed, 91 insertions(+) create mode 100644 app/presenters/two_factor_authentication/set_up_auth_app_selection_presenter.rb create mode 100644 app/presenters/two_factor_authentication/set_up_selection_presenter.rb diff --git a/app/presenters/two_factor_authentication/set_up_auth_app_selection_presenter.rb b/app/presenters/two_factor_authentication/set_up_auth_app_selection_presenter.rb new file mode 100644 index 00000000000..1528ab23d8b --- /dev/null +++ b/app/presenters/two_factor_authentication/set_up_auth_app_selection_presenter.rb @@ -0,0 +1,12 @@ +module TwoFactorAuthentication + class SetUpAuthAppSelectionPresenter < SetUpSelectionPresenter + def method + :auth_app + end + + def mfa_configuration_count + user.auth_app_configurations.count + end + end + end + \ No newline at end of file diff --git a/app/presenters/two_factor_authentication/set_up_selection_presenter.rb b/app/presenters/two_factor_authentication/set_up_selection_presenter.rb new file mode 100644 index 00000000000..a51dc489a37 --- /dev/null +++ b/app/presenters/two_factor_authentication/set_up_selection_presenter.rb @@ -0,0 +1,79 @@ +module TwoFactorAuthentication + class SetUpSelectionPresenter + include ActionView::Helpers::TranslationHelper + + attr_reader :user + + def initialize(user:) + @user = user + end + + def render_in(view_context, &block) + view_context.capture(&block) + end + + def type + method.to_s + end + + def label + case type + when 'auth_app' + t('two_factor_authentication.two_factor_choice_options.auth_app') + 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' + t('two_factor_authentication.two_factor_choice_options.phone') + when 'sms' + t('two_factor_authentication.two_factor_choice_options.sms') + when 'voice' + t('two_factor_authentication.two_factor_choice_options.voice') + when 'webauthn' + t('two_factor_authentication.two_factor_choice_options.webauthn') + when 'webauthn_platform' + t('two_factor_authentication.two_factor_choice_options.webauthn_platform') + else + raise "Unsupported setup method: #{type}" + end + end + + def info + case type + when 'auth_app' + t('two_factor_authentication.two_factor_choice_options.auth_app_info') + when 'backup_code' + t('two_factor_authentication.two_factor_choice_options.backup_code_info') + when 'piv_cac' + t('two_factor_authentication.two_factor_choice_options.piv_cac_info') + when 'webauthn' + t('two_factor_authentication.two_factor_choice_options.webauthn_info') + when 'webauthn_platform' + t( + 'two_factor_authentication.two_factor_choice_options.webauthn_platform_info', + app_name: APP_NAME, + ) + else + raise "Unsupported setup method: #{type}" + end + end + + def mfa_added_label + if single_configuration_only? + '' + else + "(#{mfa_configuration_description})" + end + end + + def single_configuration_only? + false + end + + def disabled? + configuration.blank? && single_configuration_only? && mfa_configuration_count > 0 + end + end + end + \ No newline at end of file From 535d68e91072c810af448b791a7018cbdc357a97 Mon Sep 17 00:00:00 2001 From: Malick Diarra Date: Tue, 12 Sep 2023 17:15:52 -0400 Subject: [PATCH 02/11] Separate auth app selections configurations --- app/models/auth_app_configuration.rb | 2 +- .../set_up_selection_presenter.rb | 14 ++++- .../sign_in_auth_app_selection_presenter.rb | 8 +++ .../sign_in_selection_presenter.rb | 63 +++++++++++++++++++ .../two_factor_options_presenter.rb | 2 +- 5 files changed, 86 insertions(+), 3 deletions(-) create mode 100644 app/presenters/two_factor_authentication/sign_in_auth_app_selection_presenter.rb create mode 100644 app/presenters/two_factor_authentication/sign_in_selection_presenter.rb diff --git a/app/models/auth_app_configuration.rb b/app/models/auth_app_configuration.rb index 4789c319229..a0dc3abe526 100644 --- a/app/models/auth_app_configuration.rb +++ b/app/models/auth_app_configuration.rb @@ -13,7 +13,7 @@ def mfa_enabled? def selection_presenters if mfa_enabled? - [TwoFactorAuthentication::AuthAppSelectionPresenter.new(user:, configuration: self)] + [TwoFactorAuthentication::SignInAuthAppSelectionPresenter.new(user:, configuration: self)] else [] end diff --git a/app/presenters/two_factor_authentication/set_up_selection_presenter.rb b/app/presenters/two_factor_authentication/set_up_selection_presenter.rb index a51dc489a37..ef958805fb4 100644 --- a/app/presenters/two_factor_authentication/set_up_selection_presenter.rb +++ b/app/presenters/two_factor_authentication/set_up_selection_presenter.rb @@ -70,9 +70,21 @@ def mfa_added_label def single_configuration_only? false end + + def mfa_configuration_description + return '' if mfa_configuration_count == 0 + if single_configuration_only? + t('two_factor_authentication.two_factor_choice_options.no_count_configuration_added') + else + t( + 'two_factor_authentication.two_factor_choice_options.configurations_added', + count: mfa_configuration_count, + ) + end + end def disabled? - configuration.blank? && single_configuration_only? && mfa_configuration_count > 0 + single_configuration_only? && mfa_configuration_count > 0 end end end diff --git a/app/presenters/two_factor_authentication/sign_in_auth_app_selection_presenter.rb b/app/presenters/two_factor_authentication/sign_in_auth_app_selection_presenter.rb new file mode 100644 index 00000000000..8e2224133fe --- /dev/null +++ b/app/presenters/two_factor_authentication/sign_in_auth_app_selection_presenter.rb @@ -0,0 +1,8 @@ +module TwoFactorAuthentication + class SignInAuthAppSelectionPresenter < SignInSelectionPresenter + def method + :auth_app + end + end +end + \ No newline at end of file diff --git a/app/presenters/two_factor_authentication/sign_in_selection_presenter.rb b/app/presenters/two_factor_authentication/sign_in_selection_presenter.rb new file mode 100644 index 00000000000..b04ccc529aa --- /dev/null +++ b/app/presenters/two_factor_authentication/sign_in_selection_presenter.rb @@ -0,0 +1,63 @@ +module TwoFactorAuthentication + class SignInSelectionPresenter + include ActionView::Helpers::TranslationHelper + + attr_reader :configuration, :user + + def initialize(user:, configuration:) + @user = user + @configuration = configuration + end + + def render_in(view_context, &block) + view_context.capture(&block) + end + + def type + method.to_s + end + + def label + case type + when 'auth_app' + t('two_factor_authentication.login_options.auth_app') + when 'backup_code' + t('two_factor_authentication.login_options.backup_code') + when 'personal_key' + t('two_factor_authentication.login_options.personal_key') + when 'piv_cac' + t('two_factor_authentication.login_options.piv_cac') + when 'sms' + t('two_factor_authentication.login_options.sms') + when 'voice' + t('two_factor_authentication.login_options.voice') + when 'webauthn' + t('two_factor_authentication.login_options.webauthn') + when 'webauthn_platform' + t('two_factor_authentication.login_options.webauthn_platform') + else + raise "Unsupported login method: #{type}" + end + end + + def info + case type + when 'auth_app' + t('two_factor_authentication.login_options.auth_app_info') + when 'backup_code' + t('two_factor_authentication.login_options.backup_code_info') + when 'personal_key' + t('two_factor_authentication.login_options.personal_key_info') + when 'piv_cac' + t('two_factor_authentication.login_options.piv_cac_info') + when 'webauthn' + t('two_factor_authentication.login_options.webauthn_info') + when 'webauthn_platform' + t('two_factor_authentication.login_options.webauthn_platform_info', app_name: APP_NAME) + else + raise "Unsupported login method: #{type}" + end + end + end +end + \ No newline at end of file diff --git a/app/presenters/two_factor_options_presenter.rb b/app/presenters/two_factor_options_presenter.rb index 37ce24c5408..39f8572343b 100644 --- a/app/presenters/two_factor_options_presenter.rb +++ b/app/presenters/two_factor_options_presenter.rb @@ -91,7 +91,7 @@ def phone_options def totp_option return [] if piv_cac_required? || phishing_resistant_only? - [TwoFactorAuthentication::AuthAppSelectionPresenter.new(user: user)] + [TwoFactorAuthentication::SetUpAuthAppSelectionPresenter.new(user: user)] end def backup_code_option From 1c24154e6a2bacfb16e4a7cf8f008db04423df44 Mon Sep 17 00:00:00 2001 From: Malick Diarra Date: Thu, 14 Sep 2023 08:26:06 -0400 Subject: [PATCH 03/11] break up mfa presenters --- .../auth_app_selection_presenter.rb | 11 ----------- 1 file changed, 11 deletions(-) delete mode 100644 app/presenters/two_factor_authentication/auth_app_selection_presenter.rb diff --git a/app/presenters/two_factor_authentication/auth_app_selection_presenter.rb b/app/presenters/two_factor_authentication/auth_app_selection_presenter.rb deleted file mode 100644 index de6a7be3f69..00000000000 --- a/app/presenters/two_factor_authentication/auth_app_selection_presenter.rb +++ /dev/null @@ -1,11 +0,0 @@ -module TwoFactorAuthentication - class AuthAppSelectionPresenter < SelectionPresenter - def method - :auth_app - end - - def mfa_configuration_count - user.auth_app_configurations.count - end - end -end From 9ba137c444b78b4aa1e2d6fe60c5edfc9ee5c531 Mon Sep 17 00:00:00 2001 From: Malick Diarra Date: Thu, 14 Sep 2023 13:21:04 -0400 Subject: [PATCH 04/11] changelog: Internal, Authentication, Refactor presenter logic to separate sign in and set up --- .../set_up_selection_presenter.rb | 4 + ...et_up_auth_app_selection_presenter_spec.rb | 33 ++++++ .../set_up_selection_presenter_spec.rb | 105 ++++++++++++++++++ 3 files changed, 142 insertions(+) create mode 100644 spec/presenters/two_factor_authentication/set_up_auth_app_selection_presenter_spec.rb create mode 100644 spec/presenters/two_factor_authentication/set_up_selection_presenter_spec.rb diff --git a/app/presenters/two_factor_authentication/set_up_selection_presenter.rb b/app/presenters/two_factor_authentication/set_up_selection_presenter.rb index ef958805fb4..285b363d6d7 100644 --- a/app/presenters/two_factor_authentication/set_up_selection_presenter.rb +++ b/app/presenters/two_factor_authentication/set_up_selection_presenter.rb @@ -71,6 +71,10 @@ def single_configuration_only? false end + def mfa_configuration_count + 0 + end + def mfa_configuration_description return '' if mfa_configuration_count == 0 if single_configuration_only? diff --git a/spec/presenters/two_factor_authentication/set_up_auth_app_selection_presenter_spec.rb b/spec/presenters/two_factor_authentication/set_up_auth_app_selection_presenter_spec.rb new file mode 100644 index 00000000000..ada58bceb8d --- /dev/null +++ b/spec/presenters/two_factor_authentication/set_up_auth_app_selection_presenter_spec.rb @@ -0,0 +1,33 @@ +require 'rails_helper' + +RSpec.describe TwoFactorAuthentication::SetUpAuthAppSelectionPresenter do + let(:configuration) {} + let(:user_without_mfa) { create(:user) } + let(:user_with_mfa) { create(:user, :with_authentication_app) } + let(:presenter_without_mfa) do + described_class.new(user: user_without_mfa) + end + let(:presenter_with_mfa) do + described_class.new(user: user_with_mfa) + end + + describe '#type' do + it 'returns auth_app' do + expect(presenter_without_mfa.type).to eq 'auth_app' + end + end + + describe '#mfa_configuration' do + it 'return an empty string when user has not configured this authenticator' do + expect(presenter_without_mfa.mfa_configuration_description).to eq('') + end + it 'return an # added when user has configured this authenticator' do + expect(presenter_with_mfa.mfa_configuration_description).to eq( + t( + 'two_factor_authentication.two_factor_choice_options.configurations_added', + count: 1, + ), + ) + end + end +end diff --git a/spec/presenters/two_factor_authentication/set_up_selection_presenter_spec.rb b/spec/presenters/two_factor_authentication/set_up_selection_presenter_spec.rb new file mode 100644 index 00000000000..768ab03ede8 --- /dev/null +++ b/spec/presenters/two_factor_authentication/set_up_selection_presenter_spec.rb @@ -0,0 +1,105 @@ +require 'rails_helper' + +RSpec.describe TwoFactorAuthentication::SetUpSelectionPresenter do + class PlaceholderPresenter < TwoFactorAuthentication::SetUpSelectionPresenter + def method + :missing + end + end + + let(:user) { build(:user) } + + subject(:presenter) { described_class.new(user: user) } + + describe '#render_in' do + it 'renders captured block content' do + view_context = ActionController::Base.new.view_context + + expect(view_context).to receive(:capture) do |*args, &block| + expect(block.call).to eq('content') + end + + presenter.render_in(view_context) { 'content' } + end + end + + describe '#disabled?' do + let(:single_configuration_only) {} + let(:mfa_configuration_count) {} + + before do + allow(presenter).to receive(:single_configuration_only?).and_return(single_configuration_only) + allow(presenter).to receive(:mfa_configuration_count).and_return(mfa_configuration_count) + end + + context 'without single configuration restriction' do + let(:single_configuration_only) { false } + + it 'is an mfa that allows multiple configurations' do + expect(presenter.disabled?).to eq(false) + end + end + + context 'with single configuration only' do + let(:single_configuration_only) { true } + + context 'with default mfa count implementation' do + before do + allow(presenter).to receive(:mfa_configuration_count).and_call_original + end + + it 'is mfa with unimplemented mfa count and single config' do + expect(presenter.disabled?).to eq(false) + end + end + + context 'with no configured mfas' do + let(:mfa_configuration_count) { 0 } + + it 'is configured with no mfa' do + expect(presenter.disabled?).to eq(false) + end + end + + context 'with at least one configured mfa' do + let(:mfa_configuration_count) { 1 } + + it 'is mfa with at least one configured' do + expect(presenter.disabled?).to eq(true) + end + end + end + end + + describe '#mfa_added_label' do + subject(:mfa_added_label) { presenter.mfa_added_label } + before do + allow(presenter).to receive(:mfa_configuration_count).and_return('1') + end + it 'is a count of configured MFAs' do + expect(presenter.mfa_added_label).to include('added') + end + + context 'with single configuration only' do + before do + allow(presenter).to receive(:single_configuration_only?).and_return(true) + end + + it 'is an empty string' do + expect(presenter.mfa_added_label).to eq('') + end + end + end + + describe '#label' do + it 'raises with missing translation' do + expect { PlaceholderPresenter.new(user: user).label }.to raise_error(RuntimeError) + end + end + + describe '#info' do + it 'raises with missing translation' do + expect { PlaceholderPresenter.new(user: user).info }.to raise_error(RuntimeError) + end + end +end From 4d54f697aef6e74757b74ce258747bd451c90140 Mon Sep 17 00:00:00 2001 From: Malick Diarra Date: Thu, 14 Sep 2023 13:21:42 -0400 Subject: [PATCH 05/11] rubocop --- .../set_up_auth_app_selection_presenter.rb | 17 +- .../set_up_selection_presenter.rb | 171 +++++++++--------- .../sign_in_auth_app_selection_presenter.rb | 1 - .../sign_in_selection_presenter.rb | 1 - 4 files changed, 93 insertions(+), 97 deletions(-) diff --git a/app/presenters/two_factor_authentication/set_up_auth_app_selection_presenter.rb b/app/presenters/two_factor_authentication/set_up_auth_app_selection_presenter.rb index 1528ab23d8b..46288adcf43 100644 --- a/app/presenters/two_factor_authentication/set_up_auth_app_selection_presenter.rb +++ b/app/presenters/two_factor_authentication/set_up_auth_app_selection_presenter.rb @@ -1,12 +1,11 @@ module TwoFactorAuthentication - class SetUpAuthAppSelectionPresenter < SetUpSelectionPresenter - def method - :auth_app - end - - def mfa_configuration_count - user.auth_app_configurations.count - end + class SetUpAuthAppSelectionPresenter < SetUpSelectionPresenter + def method + :auth_app end + + def mfa_configuration_count + user.auth_app_configurations.count + end + end end - \ No newline at end of file diff --git a/app/presenters/two_factor_authentication/set_up_selection_presenter.rb b/app/presenters/two_factor_authentication/set_up_selection_presenter.rb index 285b363d6d7..21b06b25fa9 100644 --- a/app/presenters/two_factor_authentication/set_up_selection_presenter.rb +++ b/app/presenters/two_factor_authentication/set_up_selection_presenter.rb @@ -1,95 +1,94 @@ module TwoFactorAuthentication - class SetUpSelectionPresenter - include ActionView::Helpers::TranslationHelper - - attr_reader :user - - def initialize(user:) - @user = user - end - - def render_in(view_context, &block) - view_context.capture(&block) - end - - def type - method.to_s - end - - def label - case type - when 'auth_app' - t('two_factor_authentication.two_factor_choice_options.auth_app') - 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' - t('two_factor_authentication.two_factor_choice_options.phone') - when 'sms' - t('two_factor_authentication.two_factor_choice_options.sms') - when 'voice' - t('two_factor_authentication.two_factor_choice_options.voice') - when 'webauthn' - t('two_factor_authentication.two_factor_choice_options.webauthn') - when 'webauthn_platform' - t('two_factor_authentication.two_factor_choice_options.webauthn_platform') - else - raise "Unsupported setup method: #{type}" - end - end - - def info - case type - when 'auth_app' - t('two_factor_authentication.two_factor_choice_options.auth_app_info') - when 'backup_code' - t('two_factor_authentication.two_factor_choice_options.backup_code_info') - when 'piv_cac' - t('two_factor_authentication.two_factor_choice_options.piv_cac_info') - when 'webauthn' - t('two_factor_authentication.two_factor_choice_options.webauthn_info') - when 'webauthn_platform' - t( - 'two_factor_authentication.two_factor_choice_options.webauthn_platform_info', - app_name: APP_NAME, - ) - else - raise "Unsupported setup method: #{type}" - end - end - - def mfa_added_label - if single_configuration_only? - '' - else - "(#{mfa_configuration_description})" - end - end - - def single_configuration_only? - false + class SetUpSelectionPresenter + include ActionView::Helpers::TranslationHelper + + attr_reader :user + + def initialize(user:) + @user = user + end + + def render_in(view_context, &block) + view_context.capture(&block) + end + + def type + method.to_s + end + + def label + case type + when 'auth_app' + t('two_factor_authentication.two_factor_choice_options.auth_app') + 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' + t('two_factor_authentication.two_factor_choice_options.phone') + when 'sms' + t('two_factor_authentication.two_factor_choice_options.sms') + when 'voice' + t('two_factor_authentication.two_factor_choice_options.voice') + when 'webauthn' + t('two_factor_authentication.two_factor_choice_options.webauthn') + when 'webauthn_platform' + t('two_factor_authentication.two_factor_choice_options.webauthn_platform') + else + raise "Unsupported setup method: #{type}" end + end - def mfa_configuration_count - 0 + def info + case type + when 'auth_app' + t('two_factor_authentication.two_factor_choice_options.auth_app_info') + when 'backup_code' + t('two_factor_authentication.two_factor_choice_options.backup_code_info') + when 'piv_cac' + t('two_factor_authentication.two_factor_choice_options.piv_cac_info') + when 'webauthn' + t('two_factor_authentication.two_factor_choice_options.webauthn_info') + when 'webauthn_platform' + t( + 'two_factor_authentication.two_factor_choice_options.webauthn_platform_info', + app_name: APP_NAME, + ) + else + raise "Unsupported setup method: #{type}" end + end - def mfa_configuration_description - return '' if mfa_configuration_count == 0 - if single_configuration_only? - t('two_factor_authentication.two_factor_choice_options.no_count_configuration_added') - else - t( - 'two_factor_authentication.two_factor_choice_options.configurations_added', - count: mfa_configuration_count, - ) - end + def mfa_added_label + if single_configuration_only? + '' + else + "(#{mfa_configuration_description})" end - - def disabled? - single_configuration_only? && mfa_configuration_count > 0 + end + + def single_configuration_only? + false + end + + def mfa_configuration_count + 0 + end + + def mfa_configuration_description + return '' if mfa_configuration_count == 0 + if single_configuration_only? + t('two_factor_authentication.two_factor_choice_options.no_count_configuration_added') + else + t( + 'two_factor_authentication.two_factor_choice_options.configurations_added', + count: mfa_configuration_count, + ) end end + + def disabled? + single_configuration_only? && mfa_configuration_count > 0 + end + end end - \ No newline at end of file diff --git a/app/presenters/two_factor_authentication/sign_in_auth_app_selection_presenter.rb b/app/presenters/two_factor_authentication/sign_in_auth_app_selection_presenter.rb index 8e2224133fe..3a330852f3b 100644 --- a/app/presenters/two_factor_authentication/sign_in_auth_app_selection_presenter.rb +++ b/app/presenters/two_factor_authentication/sign_in_auth_app_selection_presenter.rb @@ -5,4 +5,3 @@ def method end end end - \ No newline at end of file diff --git a/app/presenters/two_factor_authentication/sign_in_selection_presenter.rb b/app/presenters/two_factor_authentication/sign_in_selection_presenter.rb index b04ccc529aa..b8fb7d6a092 100644 --- a/app/presenters/two_factor_authentication/sign_in_selection_presenter.rb +++ b/app/presenters/two_factor_authentication/sign_in_selection_presenter.rb @@ -60,4 +60,3 @@ def info end end end - \ No newline at end of file From 11490e7d8985ff833edff294c0f695bba8f60f9b Mon Sep 17 00:00:00 2001 From: Malick Diarra Date: Thu, 14 Sep 2023 14:04:03 -0400 Subject: [PATCH 06/11] auth app selection --- .../auth_app_selection_presentor.rb | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 app/presenters/two_factor_authentication/auth_app_selection_presentor.rb diff --git a/app/presenters/two_factor_authentication/auth_app_selection_presentor.rb b/app/presenters/two_factor_authentication/auth_app_selection_presentor.rb new file mode 100644 index 00000000000..ac2cb8c2389 --- /dev/null +++ b/app/presenters/two_factor_authentication/auth_app_selection_presentor.rb @@ -0,0 +1,12 @@ +module TwoFactorAuthentication + class AuthAppSelectionPresenter < SelectionPresenter + def method + :auth_app + end + + def mfa_configuration_count + user.auth_app_configurations.count + end + end + end + \ No newline at end of file From 4c2c732946152bd3d2a3fbbec1c8243faa4e7fe5 Mon Sep 17 00:00:00 2001 From: Malick Diarra Date: Thu, 14 Sep 2023 16:19:19 -0400 Subject: [PATCH 07/11] remove authentication app slection presenter --- .../auth_app_selection_presentor.rb | 12 ------- .../auth_app_selection_presenter_spec.rb | 33 ------------------- .../two_factor_options_presenter_spec.rb | 6 ++-- .../_mfa_selection.html.erb_spec.rb | 2 +- 4 files changed, 4 insertions(+), 49 deletions(-) delete mode 100644 app/presenters/two_factor_authentication/auth_app_selection_presentor.rb delete mode 100644 spec/presenters/two_factor_authentication/auth_app_selection_presenter_spec.rb diff --git a/app/presenters/two_factor_authentication/auth_app_selection_presentor.rb b/app/presenters/two_factor_authentication/auth_app_selection_presentor.rb deleted file mode 100644 index ac2cb8c2389..00000000000 --- a/app/presenters/two_factor_authentication/auth_app_selection_presentor.rb +++ /dev/null @@ -1,12 +0,0 @@ -module TwoFactorAuthentication - class AuthAppSelectionPresenter < SelectionPresenter - def method - :auth_app - end - - def mfa_configuration_count - user.auth_app_configurations.count - end - end - end - \ No newline at end of file diff --git a/spec/presenters/two_factor_authentication/auth_app_selection_presenter_spec.rb b/spec/presenters/two_factor_authentication/auth_app_selection_presenter_spec.rb deleted file mode 100644 index 58695461877..00000000000 --- a/spec/presenters/two_factor_authentication/auth_app_selection_presenter_spec.rb +++ /dev/null @@ -1,33 +0,0 @@ -require 'rails_helper' - -RSpec.describe TwoFactorAuthentication::AuthAppSelectionPresenter do - let(:configuration) {} - let(:user_without_mfa) { create(:user) } - let(:user_with_mfa) { create(:user, :with_authentication_app) } - let(:presenter_without_mfa) do - described_class.new(configuration: configuration, user: user_without_mfa) - end - let(:presenter_with_mfa) do - described_class.new(configuration: configuration, user: user_with_mfa) - end - - describe '#type' do - it 'returns auth_app' do - expect(presenter_without_mfa.type).to eq 'auth_app' - end - end - - describe '#mfa_configruation' do - it 'return an empty string when user has not configured this authenticator' do - expect(presenter_without_mfa.mfa_configuration_description).to eq('') - end - it 'return an # added when user has configured this authenticator' do - expect(presenter_with_mfa.mfa_configuration_description).to eq( - t( - 'two_factor_authentication.two_factor_choice_options.configurations_added', - count: 1, - ), - ) - end - end -end diff --git a/spec/presenters/two_factor_options_presenter_spec.rb b/spec/presenters/two_factor_options_presenter_spec.rb index 383fdeb3595..d50a32c32d0 100644 --- a/spec/presenters/two_factor_options_presenter_spec.rb +++ b/spec/presenters/two_factor_options_presenter_spec.rb @@ -30,7 +30,7 @@ describe '#options' do it 'supplies all the options for a user' do expect(presenter.options.map(&:class)).to eq [ - TwoFactorAuthentication::AuthAppSelectionPresenter, + TwoFactorAuthentication::SetUpAuthAppSelectionPresenter, TwoFactorAuthentication::PhoneSelectionPresenter, TwoFactorAuthentication::BackupCodeSelectionPresenter, TwoFactorAuthentication::WebauthnSelectionPresenter, @@ -61,7 +61,7 @@ it 'supplies all the options except phone' do expect(presenter.options.map(&:class)).to eq [ - TwoFactorAuthentication::AuthAppSelectionPresenter, + TwoFactorAuthentication::SetUpAuthAppSelectionPresenter, TwoFactorAuthentication::BackupCodeSelectionPresenter, TwoFactorAuthentication::WebauthnSelectionPresenter, TwoFactorAuthentication::PivCacSelectionPresenter, @@ -77,7 +77,7 @@ it 'supplies all the options except webauthn' do expect(presenter.options.map(&:class)).to eq [ TwoFactorAuthentication::WebauthnPlatformSelectionPresenter, - TwoFactorAuthentication::AuthAppSelectionPresenter, + TwoFactorAuthentication::SetUpAuthAppSelectionPresenter, TwoFactorAuthentication::PhoneSelectionPresenter, TwoFactorAuthentication::BackupCodeSelectionPresenter, TwoFactorAuthentication::WebauthnSelectionPresenter, 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 05f196cbdea..0ad3bfa59d0 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 @@ -41,7 +41,7 @@ render partial: 'mfa_selection', locals: { form: form_builder, option: presenter.options.find do |option| - option.is_a?(TwoFactorAuthentication::AuthAppSelectionPresenter) + option.is_a?(TwoFactorAuthentication::SetUpAuthAppSelectionPresenter) end, } end From 3d0a093587d22de77579190ffac8f440de5fbc1c Mon Sep 17 00:00:00 2001 From: Malick Diarra Date: Mon, 18 Sep 2023 09:28:49 -0400 Subject: [PATCH 08/11] remove association with selection presenter --- .../set_up_auth_app_selection_presenter.rb | 9 +++- .../set_up_selection_presenter.rb | 41 ++----------------- .../sign_in_auth_app_selection_presenter.rb | 8 ++++ .../sign_in_selection_presenter.rb | 38 +---------------- 4 files changed, 21 insertions(+), 75 deletions(-) diff --git a/app/presenters/two_factor_authentication/set_up_auth_app_selection_presenter.rb b/app/presenters/two_factor_authentication/set_up_auth_app_selection_presenter.rb index 46288adcf43..507c1147d62 100644 --- a/app/presenters/two_factor_authentication/set_up_auth_app_selection_presenter.rb +++ b/app/presenters/two_factor_authentication/set_up_auth_app_selection_presenter.rb @@ -7,5 +7,12 @@ def method def mfa_configuration_count user.auth_app_configurations.count end - end + + def label + t('two_factor_authentication.two_factor_choice_options.auth_app') + end + + def info + t('two_factor_authentication.two_factor_choice_options.auth_app_info') + end end diff --git a/app/presenters/two_factor_authentication/set_up_selection_presenter.rb b/app/presenters/two_factor_authentication/set_up_selection_presenter.rb index 21b06b25fa9..0c4e798eb89 100644 --- a/app/presenters/two_factor_authentication/set_up_selection_presenter.rb +++ b/app/presenters/two_factor_authentication/set_up_selection_presenter.rb @@ -17,46 +17,11 @@ def type end def label - case type - when 'auth_app' - t('two_factor_authentication.two_factor_choice_options.auth_app') - 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' - t('two_factor_authentication.two_factor_choice_options.phone') - when 'sms' - t('two_factor_authentication.two_factor_choice_options.sms') - when 'voice' - t('two_factor_authentication.two_factor_choice_options.voice') - when 'webauthn' - t('two_factor_authentication.two_factor_choice_options.webauthn') - when 'webauthn_platform' - t('two_factor_authentication.two_factor_choice_options.webauthn_platform') - else - raise "Unsupported setup method: #{type}" - end + raise "Unsupported setup method: #{type}" end def info - case type - when 'auth_app' - t('two_factor_authentication.two_factor_choice_options.auth_app_info') - when 'backup_code' - t('two_factor_authentication.two_factor_choice_options.backup_code_info') - when 'piv_cac' - t('two_factor_authentication.two_factor_choice_options.piv_cac_info') - when 'webauthn' - t('two_factor_authentication.two_factor_choice_options.webauthn_info') - when 'webauthn_platform' - t( - 'two_factor_authentication.two_factor_choice_options.webauthn_platform_info', - app_name: APP_NAME, - ) - else - raise "Unsupported setup method: #{type}" - end + raise "Unsupported setup method: #{type}" end def mfa_added_label @@ -91,4 +56,4 @@ def disabled? single_configuration_only? && mfa_configuration_count > 0 end end - end +end diff --git a/app/presenters/two_factor_authentication/sign_in_auth_app_selection_presenter.rb b/app/presenters/two_factor_authentication/sign_in_auth_app_selection_presenter.rb index 3a330852f3b..59e268502ba 100644 --- a/app/presenters/two_factor_authentication/sign_in_auth_app_selection_presenter.rb +++ b/app/presenters/two_factor_authentication/sign_in_auth_app_selection_presenter.rb @@ -3,5 +3,13 @@ class SignInAuthAppSelectionPresenter < SignInSelectionPresenter def method :auth_app end + + def label + t('two_factor_authentication.login_options.auth_app') + end + + def info + t('two_factor_authentication.login_options.auth_app_info') + end end end diff --git a/app/presenters/two_factor_authentication/sign_in_selection_presenter.rb b/app/presenters/two_factor_authentication/sign_in_selection_presenter.rb index b8fb7d6a092..a9dc30574e8 100644 --- a/app/presenters/two_factor_authentication/sign_in_selection_presenter.rb +++ b/app/presenters/two_factor_authentication/sign_in_selection_presenter.rb @@ -18,45 +18,11 @@ def type end def label - case type - when 'auth_app' - t('two_factor_authentication.login_options.auth_app') - when 'backup_code' - t('two_factor_authentication.login_options.backup_code') - when 'personal_key' - t('two_factor_authentication.login_options.personal_key') - when 'piv_cac' - t('two_factor_authentication.login_options.piv_cac') - when 'sms' - t('two_factor_authentication.login_options.sms') - when 'voice' - t('two_factor_authentication.login_options.voice') - when 'webauthn' - t('two_factor_authentication.login_options.webauthn') - when 'webauthn_platform' - t('two_factor_authentication.login_options.webauthn_platform') - else - raise "Unsupported login method: #{type}" - end + raise "Unsupported login method: #{type}" end def info - case type - when 'auth_app' - t('two_factor_authentication.login_options.auth_app_info') - when 'backup_code' - t('two_factor_authentication.login_options.backup_code_info') - when 'personal_key' - t('two_factor_authentication.login_options.personal_key_info') - when 'piv_cac' - t('two_factor_authentication.login_options.piv_cac_info') - when 'webauthn' - t('two_factor_authentication.login_options.webauthn_info') - when 'webauthn_platform' - t('two_factor_authentication.login_options.webauthn_platform_info', app_name: APP_NAME) - else - raise "Unsupported login method: #{type}" - end + raise "Unsupported login method: #{type}" end end end From 8c46ca94d21c131f3482024317f2cd0699859361 Mon Sep 17 00:00:00 2001 From: Malick Diarra Date: Mon, 18 Sep 2023 11:53:50 -0400 Subject: [PATCH 09/11] add end --- .../set_up_auth_app_selection_presenter.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/app/presenters/two_factor_authentication/set_up_auth_app_selection_presenter.rb b/app/presenters/two_factor_authentication/set_up_auth_app_selection_presenter.rb index 507c1147d62..0763712895d 100644 --- a/app/presenters/two_factor_authentication/set_up_auth_app_selection_presenter.rb +++ b/app/presenters/two_factor_authentication/set_up_auth_app_selection_presenter.rb @@ -16,3 +16,4 @@ def info t('two_factor_authentication.two_factor_choice_options.auth_app_info') end end +end From 80f20a690ed37d460bf4e41bed71d74e499171d3 Mon Sep 17 00:00:00 2001 From: Malick Diarra Date: Mon, 18 Sep 2023 14:00:07 -0400 Subject: [PATCH 10/11] make sure to include disabled? --- .../two_factor_authentication/sign_in_selection_presenter.rb | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/app/presenters/two_factor_authentication/sign_in_selection_presenter.rb b/app/presenters/two_factor_authentication/sign_in_selection_presenter.rb index a9dc30574e8..fbffd1a0960 100644 --- a/app/presenters/two_factor_authentication/sign_in_selection_presenter.rb +++ b/app/presenters/two_factor_authentication/sign_in_selection_presenter.rb @@ -24,5 +24,9 @@ def label def info raise "Unsupported login method: #{type}" end + + def disabled? + false + end end end From d76bac04bbe8f480417fd48fff558bc03889d778 Mon Sep 17 00:00:00 2001 From: Malick Diarra Date: Wed, 27 Sep 2023 13:29:49 -0400 Subject: [PATCH 11/11] add rspec for sign in auth app spec --- .../selection_presenter.rb | 4 -- ...gn_in_auth_app_selection_presenter_spec.rb | 28 +++++++++++ .../sign_in_selection_presenter_spec.rb | 48 +++++++++++++++++++ 3 files changed, 76 insertions(+), 4 deletions(-) create mode 100644 spec/presenters/two_factor_authentication/sign_in_auth_app_selection_presenter_spec.rb create mode 100644 spec/presenters/two_factor_authentication/sign_in_selection_presenter_spec.rb diff --git a/app/presenters/two_factor_authentication/selection_presenter.rb b/app/presenters/two_factor_authentication/selection_presenter.rb index ddae517c1e7..00ebae8b49d 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 'auth_app' - t('two_factor_authentication.login_options.auth_app') when 'backup_code' t('two_factor_authentication.login_options.backup_code') when 'personal_key' @@ -92,8 +90,6 @@ def login_label(type) def setup_label(type) case type - when 'auth_app' - t('two_factor_authentication.two_factor_choice_options.auth_app') when 'backup_code' t('two_factor_authentication.two_factor_choice_options.backup_code') when 'piv_cac' diff --git a/spec/presenters/two_factor_authentication/sign_in_auth_app_selection_presenter_spec.rb b/spec/presenters/two_factor_authentication/sign_in_auth_app_selection_presenter_spec.rb new file mode 100644 index 00000000000..5fe3027a668 --- /dev/null +++ b/spec/presenters/two_factor_authentication/sign_in_auth_app_selection_presenter_spec.rb @@ -0,0 +1,28 @@ +require 'rails_helper' + +RSpec.describe TwoFactorAuthentication::SignInAuthAppSelectionPresenter do + let(:user) { create(:user) } + let(:configuration) { create(:auth_app_configuration, user: user) } + + let(:presenter) do + described_class.new(user: user, configuration: configuration) + end + + describe '#type' do + it 'returns auth_app' do + expect(presenter.type).to eq 'auth_app' + end + end + + describe '#label' do + it 'raises with missing translation' do + expect(presenter.label).to eq(t('two_factor_authentication.login_options.auth_app')) + end + end + + describe '#info' do + it 'raises with missing translation' do + expect(presenter.info).to eq(t('two_factor_authentication.login_options.auth_app_info')) + end + end +end diff --git a/spec/presenters/two_factor_authentication/sign_in_selection_presenter_spec.rb b/spec/presenters/two_factor_authentication/sign_in_selection_presenter_spec.rb new file mode 100644 index 00000000000..d1c1ccbe709 --- /dev/null +++ b/spec/presenters/two_factor_authentication/sign_in_selection_presenter_spec.rb @@ -0,0 +1,48 @@ +require 'rails_helper' + +RSpec.describe TwoFactorAuthentication::SignInSelectionPresenter do + class PlaceholderPresenter < TwoFactorAuthentication::SignInSelectionPresenter + def method + :missing + end + end + + let(:user) { build(:user) } + let(:configuration) { create(:phone_configuration, user: user) } + + subject(:presenter) { PlaceholderPresenter.new(user: user, configuration: configuration) } + + describe '#render_in' do + it 'renders captured block content' do + view_context = ActionController::Base.new.view_context + + expect(view_context).to receive(:capture) do |*args, &block| + expect(block.call).to eq('content') + end + + presenter.render_in(view_context) { 'content' } + end + end + + describe '#label' do + it 'raises with missing translation' do + expect do + presenter.label + end.to raise_error(RuntimeError) + end + end + + describe '#type' do + it 'returns missing as type' do + expect(presenter.type).to eq('missing') + end + end + + describe '#info' do + it 'raises with missing translation' do + expect do + presenter.info + end.to raise_error(RuntimeError) + end + end +end