From 0847cca6b654fa4429d6029fbece03f2f0c220d4 Mon Sep 17 00:00:00 2001 From: kevinsmaster5 Date: Fri, 27 Oct 2023 09:04:03 -0400 Subject: [PATCH 01/12] changelog: Internal, tech debt, Break up MFA selection presenter classes for Webauthn --- ...p_webauthn_platform_selection_presenter.rb | 43 +++++++++++++++++++ .../set_up_webauthn_selection_presenter.rb | 23 ++++++++++ ...n_webauthn_platform_selection_presenter.rb | 28 ++++++++++++ .../sign_in_webauthn_selection_presenter.rb | 19 ++++++++ ...authn_platform_selection_presenter_spec.rb | 35 +++++++++++++++ ...authn_platform_selection_presenter_spec.rb | 32 ++++++++++++++ ...gn_in_webauthn_selection_presenter_spec.rb | 32 ++++++++++++++ 7 files changed, 212 insertions(+) create mode 100644 app/presenters/two_factor_authentication/set_up_webauthn_platform_selection_presenter.rb create mode 100644 app/presenters/two_factor_authentication/set_up_webauthn_selection_presenter.rb create mode 100644 app/presenters/two_factor_authentication/sign_in_webauthn_platform_selection_presenter.rb create mode 100644 app/presenters/two_factor_authentication/sign_in_webauthn_selection_presenter.rb create mode 100644 spec/presenters/two_factor_authentication/set_up_webauthn_platform_selection_presenter_spec.rb create mode 100644 spec/presenters/two_factor_authentication/sign_in_webauthn_platform_selection_presenter_spec.rb create mode 100644 spec/presenters/two_factor_authentication/sign_in_webauthn_selection_presenter_spec.rb diff --git a/app/presenters/two_factor_authentication/set_up_webauthn_platform_selection_presenter.rb b/app/presenters/two_factor_authentication/set_up_webauthn_platform_selection_presenter.rb new file mode 100644 index 00000000000..0b6b826ed24 --- /dev/null +++ b/app/presenters/two_factor_authentication/set_up_webauthn_platform_selection_presenter.rb @@ -0,0 +1,43 @@ +module TwoFactorAuthentication + class SetUpWebauthnPlatformSelectionPresenter < SetUpSelectionPresenter + def method + :webauthn_platform + end + + def initialize(user:, configuration: nil) + @user = user + @configuration = configuration + end + + def render_in(view_context, &block) + view_context.render( + WebauthnInputComponent.new( + platform: true, + passkey_supported_only: true, + show_unsupported_passkey: + IdentityConfig.store.show_unsupported_passkey_platform_authentication_setup, + ), + &block + ) + end + + def label + t('two_factor_authentication.two_factor_choice_options.webauthn_platform') + end + + def info + t( + 'two_factor_authentication.two_factor_choice_options.webauthn_platform_info', + app_name: APP_NAME, + ) + end + + def single_configuration_only? + true + end + + def mfa_configuration_count + user.webauthn_configurations.where(platform_authenticator: true).count + end + end +end diff --git a/app/presenters/two_factor_authentication/set_up_webauthn_selection_presenter.rb b/app/presenters/two_factor_authentication/set_up_webauthn_selection_presenter.rb new file mode 100644 index 00000000000..8f95676d18f --- /dev/null +++ b/app/presenters/two_factor_authentication/set_up_webauthn_selection_presenter.rb @@ -0,0 +1,23 @@ +module TwoFactorAuthentication + class SetUpWebauthnSelectionPresenter < SetUpSelectionPresenter + def method + :webauthn + end + + def render_in(view_context, &block) + view_context.render(WebauthnInputComponent.new, &block) + end + + def label + t('two_factor_authentication.two_factor_choice_options.webauthn') + end + + def info + t('two_factor_authentication.login_options.webauthn_info') + end + + def mfa_configuration_count + user.webauthn_configurations.where(platform_authenticator: [false, nil]).count + end + end +end diff --git a/app/presenters/two_factor_authentication/sign_in_webauthn_platform_selection_presenter.rb b/app/presenters/two_factor_authentication/sign_in_webauthn_platform_selection_presenter.rb new file mode 100644 index 00000000000..d5469a24c6a --- /dev/null +++ b/app/presenters/two_factor_authentication/sign_in_webauthn_platform_selection_presenter.rb @@ -0,0 +1,28 @@ +module TwoFactorAuthentication + class SignInWebauthnPlatformSelectionPresenter < SelectionPresenter + def method + :webauthn_platform + end + + def render_in(view_context, &block) + view_context.render( + WebauthnInputComponent.new( + platform: true, + passkey_supported_only: configuration.blank?, + show_unsupported_passkey: + configuration.blank? && + IdentityConfig.store.show_unsupported_passkey_platform_authentication_setup, + ), + &block + ) + end + + def label + t('two_factor_authentication.login_options.webauthn_platform') + end + + def info + t('two_factor_authentication.login_options.webauthn_platform_info', app_name: APP_NAME) + end + end +end diff --git a/app/presenters/two_factor_authentication/sign_in_webauthn_selection_presenter.rb b/app/presenters/two_factor_authentication/sign_in_webauthn_selection_presenter.rb new file mode 100644 index 00000000000..fefc53bb61a --- /dev/null +++ b/app/presenters/two_factor_authentication/sign_in_webauthn_selection_presenter.rb @@ -0,0 +1,19 @@ +module TwoFactorAuthentication + class SignInWebauthnSelectionPresenter < SignInSelectionPresenter + def method + :webauthn + end + + def render_in(view_context, &block) + view_context.render(WebauthnInputComponent.new, &block) + end + + def label + t('two_factor_authentication.two_factor_choice_options.webauthn') + end + + def info + t('two_factor_authentication.login_options.webauthn_info') + end + end +end diff --git a/spec/presenters/two_factor_authentication/set_up_webauthn_platform_selection_presenter_spec.rb b/spec/presenters/two_factor_authentication/set_up_webauthn_platform_selection_presenter_spec.rb new file mode 100644 index 00000000000..aac8a011a56 --- /dev/null +++ b/spec/presenters/two_factor_authentication/set_up_webauthn_platform_selection_presenter_spec.rb @@ -0,0 +1,35 @@ +require 'rails_helper' + +RSpec.describe TwoFactorAuthentication::SetUpWebauthnPlatformSelectionPresenter do + let(:user_without_mfa) { create(:user) } + let(:user_with_mfa) { create(:user) } + let(:configuration) {} + 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 webauthn_platform' do + expect(presenter_without_mfa.type).to eq 'webauthn_platform' + end + end + + describe '#mfa_configuration' do + it 'returns an empty string when user has not configured this authenticator' do + expect(presenter_without_mfa.mfa_configuration_description).to eq('') + end + + it 'returns an # added when user has configured this authenticator' do + create(:webauthn_configuration, platform_authenticator: true, user: user_with_mfa) + expect(presenter_with_mfa.mfa_configuration_description).to eq( + t( + 'two_factor_authentication.two_factor_choice_options.no_count_configuration_added', + count: 1, + ), + ) + end + end +end diff --git a/spec/presenters/two_factor_authentication/sign_in_webauthn_platform_selection_presenter_spec.rb b/spec/presenters/two_factor_authentication/sign_in_webauthn_platform_selection_presenter_spec.rb new file mode 100644 index 00000000000..b334fde61da --- /dev/null +++ b/spec/presenters/two_factor_authentication/sign_in_webauthn_platform_selection_presenter_spec.rb @@ -0,0 +1,32 @@ +require 'rails_helper' + +RSpec.describe TwoFactorAuthentication::SignInWebauthnPlatformSelectionPresenter do + let(:user) { create(:user) } + let(:configuration) { create(:webauthn_platform_configuration, user: user) } + + let(:presenter) do + described_class.new(user: user, configuration: configuration) + end + + describe '#type' do + it 'returns webauthn_platform' do + expect(presenter.type).to eq 'webauthn_platform' + end + end + + describe '#label' do + it 'raises with missing translation' do + expect(presenter.label).to eq( + t('two_factor_authentication.two_factor_choice_options.webauthn'), + ) + end + end + + describe '#info' do + it 'raises with missing translation' do + expect(presenter.info).to eq( + t('two_factor_authentication.login_options.webauthn_info'), + ) + end + end +end diff --git a/spec/presenters/two_factor_authentication/sign_in_webauthn_selection_presenter_spec.rb b/spec/presenters/two_factor_authentication/sign_in_webauthn_selection_presenter_spec.rb new file mode 100644 index 00000000000..4676124561f --- /dev/null +++ b/spec/presenters/two_factor_authentication/sign_in_webauthn_selection_presenter_spec.rb @@ -0,0 +1,32 @@ +require 'rails_helper' + +RSpec.describe TwoFactorAuthentication::SignInWebauthnSelectionPresenter do + let(:user) { create(:user) } + let(:configuration) { create(:webauthn_configuration, user: user) } + + let(:presenter) do + described_class.new(user: user, configuration: configuration) + end + + describe '#type' do + it 'returns webauthn' do + expect(presenter.type).to eq 'webauthn' + end + end + + describe '#label' do + it 'raises with missing translation' do + expect(presenter.label).to eq( + t('two_factor_authentication.two_factor_choice_options.webauthn'), + ) + end + end + + describe '#info' do + it 'raises with missing translation' do + expect(presenter.info).to eq( + t('two_factor_authentication.login_options.webauthn_info'), + ) + end + end +end From cd223582594045cf263c93a0b0bcfcaac3f8a8a6 Mon Sep 17 00:00:00 2001 From: kevinsmaster5 Date: Fri, 27 Oct 2023 09:08:37 -0400 Subject: [PATCH 02/12] revise selection_presenters method with new classes --- app/models/webauthn_configuration.rb | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/app/models/webauthn_configuration.rb b/app/models/webauthn_configuration.rb index 512a62a5ce0..e50c1201e19 100644 --- a/app/models/webauthn_configuration.rb +++ b/app/models/webauthn_configuration.rb @@ -29,9 +29,10 @@ def mfa_enabled? def selection_presenters if platform_authenticator? - [TwoFactorAuthentication::WebauthnPlatformSelectionPresenter.new(user:, configuration: self)] + [TwoFactorAuthentication::SignInWebauthnPlatformSelectionPresenter. + new(user:, configuration: self)] else - [TwoFactorAuthentication::WebauthnSelectionPresenter.new(user:, configuration: self)] + [TwoFactorAuthentication::SignInWebauthnSelectionPresenter.new(user:, configuration: self)] end end From 27ffb59098faa3effdaed0121959077aa5a2ef9c Mon Sep 17 00:00:00 2001 From: kevinsmaster5 Date: Fri, 27 Oct 2023 09:32:33 -0400 Subject: [PATCH 03/12] remove labels from selection_presenter --- .../two_factor_authentication/selection_presenter.rb | 8 -------- 1 file changed, 8 deletions(-) diff --git a/app/presenters/two_factor_authentication/selection_presenter.rb b/app/presenters/two_factor_authentication/selection_presenter.rb index 00ebae8b49d..214a48c5ecf 100644 --- a/app/presenters/two_factor_authentication/selection_presenter.rb +++ b/app/presenters/two_factor_authentication/selection_presenter.rb @@ -79,10 +79,6 @@ def login_label(type) 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 @@ -100,10 +96,6 @@ def setup_label(type) 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 From 73ba2f4584444d2b1aaefe69f104f03282c6f40e Mon Sep 17 00:00:00 2001 From: kevinsmaster5 Date: Fri, 27 Oct 2023 09:35:59 -0400 Subject: [PATCH 04/12] revise selected options and option methods --- app/presenters/two_factor_options_presenter.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/app/presenters/two_factor_options_presenter.rb b/app/presenters/two_factor_options_presenter.rb index 06322df6fca..d781a398a89 100644 --- a/app/presenters/two_factor_options_presenter.rb +++ b/app/presenters/two_factor_options_presenter.rb @@ -32,11 +32,11 @@ def options # add additional MFA page def all_user_selected_options [ - TwoFactorAuthentication::WebauthnPlatformSelectionPresenter.new(user: user), + TwoFactorAuthentication::SetUpWebauthnPlatformSelectionPresenter.new(user: user), TwoFactorAuthentication::SetUpAuthAppSelectionPresenter.new(user: user), TwoFactorAuthentication::PhoneSelectionPresenter.new(user: user), TwoFactorAuthentication::BackupCodeSelectionPresenter.new(user: user), - TwoFactorAuthentication::WebauthnSelectionPresenter.new(user: user), + TwoFactorAuthentication::SetUpWebauthnSelectionPresenter.new(user: user), TwoFactorAuthentication::PivCacSelectionPresenter.new(user: user), ] end @@ -104,12 +104,12 @@ def piv_cac_option def webauthn_option return [] if piv_cac_required? - [TwoFactorAuthentication::WebauthnSelectionPresenter.new(user: user)] + [TwoFactorAuthentication::SetUpWebauthnSelectionPresenter.new(user: user)] end def webauthn_platform_option return [] if piv_cac_required? || !IdentityConfig.store.platform_auth_set_up_enabled - [TwoFactorAuthentication::WebauthnPlatformSelectionPresenter.new(user: user)] + [TwoFactorAuthentication::SetUpWebauthnPlatformSelectionPresenter.new(user: user)] end def phone_options From 3e1a309b28293af5bbc03f3632c730bbb163877b Mon Sep 17 00:00:00 2001 From: kevinsmaster5 Date: Fri, 27 Oct 2023 09:39:02 -0400 Subject: [PATCH 05/12] update class reference in spec --- spec/presenters/two_factor_options_presenter_spec.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/spec/presenters/two_factor_options_presenter_spec.rb b/spec/presenters/two_factor_options_presenter_spec.rb index 76616520c7f..3d5cd02b2c5 100644 --- a/spec/presenters/two_factor_options_presenter_spec.rb +++ b/spec/presenters/two_factor_options_presenter_spec.rb @@ -33,7 +33,7 @@ TwoFactorAuthentication::SetUpAuthAppSelectionPresenter, TwoFactorAuthentication::PhoneSelectionPresenter, TwoFactorAuthentication::BackupCodeSelectionPresenter, - TwoFactorAuthentication::WebauthnSelectionPresenter, + TwoFactorAuthentication::SetUpWebauthnSelectionPresenter, TwoFactorAuthentication::PivCacSelectionPresenter, ] end @@ -48,7 +48,7 @@ it 'only displays phishing-resistant MFA methods' do expect(presenter.options.map(&:class)).to eq [ - TwoFactorAuthentication::WebauthnSelectionPresenter, + TwoFactorAuthentication::SetUpWebauthnSelectionPresenter, TwoFactorAuthentication::PivCacSelectionPresenter, ] end @@ -63,7 +63,7 @@ expect(presenter.options.map(&:class)).to eq [ TwoFactorAuthentication::SetUpAuthAppSelectionPresenter, TwoFactorAuthentication::BackupCodeSelectionPresenter, - TwoFactorAuthentication::WebauthnSelectionPresenter, + TwoFactorAuthentication::SetUpWebauthnSelectionPresenter, TwoFactorAuthentication::PivCacSelectionPresenter, ] end @@ -80,7 +80,7 @@ TwoFactorAuthentication::SetUpAuthAppSelectionPresenter, TwoFactorAuthentication::PhoneSelectionPresenter, TwoFactorAuthentication::BackupCodeSelectionPresenter, - TwoFactorAuthentication::WebauthnSelectionPresenter, + TwoFactorAuthentication::SetUpWebauthnSelectionPresenter, TwoFactorAuthentication::PivCacSelectionPresenter, ] end From 1bfc0fe5dbe979abf24b1607c22d39fe31f68dcd Mon Sep 17 00:00:00 2001 From: kevinsmaster5 Date: Fri, 27 Oct 2023 10:22:44 -0400 Subject: [PATCH 06/12] fix spec tests for platform sign in --- .../sign_in_webauthn_platform_selection_presenter_spec.rb | 6 +++--- spec/presenters/two_factor_options_presenter_spec.rb | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/spec/presenters/two_factor_authentication/sign_in_webauthn_platform_selection_presenter_spec.rb b/spec/presenters/two_factor_authentication/sign_in_webauthn_platform_selection_presenter_spec.rb index b334fde61da..ac48c040517 100644 --- a/spec/presenters/two_factor_authentication/sign_in_webauthn_platform_selection_presenter_spec.rb +++ b/spec/presenters/two_factor_authentication/sign_in_webauthn_platform_selection_presenter_spec.rb @@ -2,7 +2,7 @@ RSpec.describe TwoFactorAuthentication::SignInWebauthnPlatformSelectionPresenter do let(:user) { create(:user) } - let(:configuration) { create(:webauthn_platform_configuration, user: user) } + let(:configuration) { create(:webauthn_configuration, user: user) } let(:presenter) do described_class.new(user: user, configuration: configuration) @@ -17,7 +17,7 @@ describe '#label' do it 'raises with missing translation' do expect(presenter.label).to eq( - t('two_factor_authentication.two_factor_choice_options.webauthn'), + t('two_factor_authentication.two_factor_choice_options.webauthn_platform'), ) end end @@ -25,7 +25,7 @@ describe '#info' do it 'raises with missing translation' do expect(presenter.info).to eq( - t('two_factor_authentication.login_options.webauthn_info'), + t('two_factor_authentication.login_options.webauthn_platform_info'), ) end end diff --git a/spec/presenters/two_factor_options_presenter_spec.rb b/spec/presenters/two_factor_options_presenter_spec.rb index 3d5cd02b2c5..5c39b846dd4 100644 --- a/spec/presenters/two_factor_options_presenter_spec.rb +++ b/spec/presenters/two_factor_options_presenter_spec.rb @@ -76,7 +76,7 @@ it 'supplies all the options except webauthn' do expect(presenter.options.map(&:class)).to eq [ - TwoFactorAuthentication::WebauthnPlatformSelectionPresenter, + TwoFactorAuthentication::SetUpWebauthnPlatformSelectionPresenter, TwoFactorAuthentication::SetUpAuthAppSelectionPresenter, TwoFactorAuthentication::PhoneSelectionPresenter, TwoFactorAuthentication::BackupCodeSelectionPresenter, From 653ed69ef7cc01ee534fd03b753a1234a7d86574 Mon Sep 17 00:00:00 2001 From: kevinsmaster5 Date: Fri, 27 Oct 2023 10:41:54 -0400 Subject: [PATCH 07/12] removes split classes and specs --- .../webauthn_platform_selection_presenter.rb | 28 --------- .../webauthn_selection_presenter.rb | 15 ----- ...authn_platform_selection_presenter_spec.rb | 61 ------------------- .../webauthn_selection_presenter_spec.rb | 48 --------------- 4 files changed, 152 deletions(-) delete mode 100644 app/presenters/two_factor_authentication/webauthn_platform_selection_presenter.rb delete mode 100644 app/presenters/two_factor_authentication/webauthn_selection_presenter.rb delete mode 100644 spec/presenters/two_factor_authentication/webauthn_platform_selection_presenter_spec.rb delete mode 100644 spec/presenters/two_factor_authentication/webauthn_selection_presenter_spec.rb diff --git a/app/presenters/two_factor_authentication/webauthn_platform_selection_presenter.rb b/app/presenters/two_factor_authentication/webauthn_platform_selection_presenter.rb deleted file mode 100644 index 0a9641f0f25..00000000000 --- a/app/presenters/two_factor_authentication/webauthn_platform_selection_presenter.rb +++ /dev/null @@ -1,28 +0,0 @@ -module TwoFactorAuthentication - class WebauthnPlatformSelectionPresenter < SelectionPresenter - def method - :webauthn_platform - end - - def render_in(view_context, &block) - view_context.render( - WebauthnInputComponent.new( - platform: true, - passkey_supported_only: configuration.blank?, - show_unsupported_passkey: - configuration.blank? && - IdentityConfig.store.show_unsupported_passkey_platform_authentication_setup, - ), - &block - ) - end - - def single_configuration_only? - true - end - - def mfa_configuration_count - user.webauthn_configurations.where(platform_authenticator: true).count - end - end -end diff --git a/app/presenters/two_factor_authentication/webauthn_selection_presenter.rb b/app/presenters/two_factor_authentication/webauthn_selection_presenter.rb deleted file mode 100644 index 6a091402679..00000000000 --- a/app/presenters/two_factor_authentication/webauthn_selection_presenter.rb +++ /dev/null @@ -1,15 +0,0 @@ -module TwoFactorAuthentication - class WebauthnSelectionPresenter < SelectionPresenter - def method - :webauthn - end - - def render_in(view_context, &block) - view_context.render(WebauthnInputComponent.new, &block) - end - - def mfa_configuration_count - user.webauthn_configurations.where(platform_authenticator: [false, nil]).count - end - end -end diff --git a/spec/presenters/two_factor_authentication/webauthn_platform_selection_presenter_spec.rb b/spec/presenters/two_factor_authentication/webauthn_platform_selection_presenter_spec.rb deleted file mode 100644 index 2c15519e3fe..00000000000 --- a/spec/presenters/two_factor_authentication/webauthn_platform_selection_presenter_spec.rb +++ /dev/null @@ -1,61 +0,0 @@ -require 'rails_helper' - -RSpec.describe TwoFactorAuthentication::WebauthnPlatformSelectionPresenter do - let(:user) { create(:user) } - subject(:presenter) do - TwoFactorAuthentication::WebauthnPlatformSelectionPresenter.new( - user:, - configuration: user.webauthn_configurations.platform_authenticators.first, - ) - end - - describe '#type' do - it 'returns webauthn_platform' do - expect(presenter.type).to eq 'webauthn_platform' - end - end - - describe '#render_in' do - it 'renders a WebauthnInputComponent' do - view_context = instance_double(ActionView::Base) - expect(view_context).to receive(:render) do |component, &block| - expect(component).to be_instance_of(WebauthnInputComponent) - expect(component.passkey_supported_only?).to be(true) - expect(block.call).to eq('content') - end - - presenter.render_in(view_context) { 'content' } - end - - context 'with configured authenticator' do - let(:user) { create(:user, :with_webauthn_platform) } - - it 'renders a WebauthnInputComponent with passkey_supported_only false' do - view_context = instance_double(ActionView::Base) - expect(view_context).to receive(:render) do |component, &block| - expect(component.passkey_supported_only?).to be(false) - end - - presenter.render_in(view_context) - end - end - end - - describe '#mfa_configuration' do - it 'returns an empty string when user has not configured this authenticator' do - expect(presenter.mfa_configuration_description).to eq('') - end - - context 'with configured authenticator' do - let(:user) { create(:user, :with_webauthn_platform) } - - it 'returns the translated string for added when user has configured this authenticator' do - expect(presenter.mfa_configuration_description).to eq( - t( - 'two_factor_authentication.two_factor_choice_options.no_count_configuration_added', - ), - ) - end - end - end -end diff --git a/spec/presenters/two_factor_authentication/webauthn_selection_presenter_spec.rb b/spec/presenters/two_factor_authentication/webauthn_selection_presenter_spec.rb deleted file mode 100644 index a0c92de0429..00000000000 --- a/spec/presenters/two_factor_authentication/webauthn_selection_presenter_spec.rb +++ /dev/null @@ -1,48 +0,0 @@ -require 'rails_helper' - -RSpec.describe TwoFactorAuthentication::WebauthnSelectionPresenter do - let(:user_without_mfa) { create(:user) } - let(:user_with_mfa) { create(:user) } - let(:configuration) {} - 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 webauthn' do - expect(presenter_without_mfa.type).to eq 'webauthn' - end - end - - describe '#render_in' do - it 'renders a WebauthnInputComponent' do - view_context = ActionController::Base.new.view_context - - expect(view_context).to receive(:render) do |component, &block| - expect(component).to be_instance_of(WebauthnInputComponent) - expect(block.call).to eq('content') - end - - presenter_without_mfa.render_in(view_context) { 'content' } - end - end - - describe '#mfa_configuration' do - it 'returns an empty string when user has not configured this authenticator' do - expect(presenter_without_mfa.mfa_configuration_description).to eq('') - end - - it 'returns an # added when user has configured this authenticator' do - create(:webauthn_configuration, platform_authenticator: false, user: user_with_mfa) - expect(presenter_with_mfa.mfa_configuration_description).to eq( - t( - 'two_factor_authentication.two_factor_choice_options.configurations_added', - count: 1, - ), - ) - end - end -end From 6ea6c110a16f78412ed69b0eaebd6383cac76c68 Mon Sep 17 00:00:00 2001 From: kevinsmaster5 Date: Fri, 27 Oct 2023 11:12:23 -0400 Subject: [PATCH 08/12] fix new class references --- .../two_factor_login_options_presenter_spec.rb | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/spec/presenters/two_factor_login_options_presenter_spec.rb b/spec/presenters/two_factor_login_options_presenter_spec.rb index ce1ace484d0..5034a82da56 100644 --- a/spec/presenters/two_factor_login_options_presenter_spec.rb +++ b/spec/presenters/two_factor_login_options_presenter_spec.rb @@ -84,7 +84,7 @@ [ TwoFactorAuthentication::SmsSelectionPresenter, TwoFactorAuthentication::VoiceSelectionPresenter, - TwoFactorAuthentication::WebauthnSelectionPresenter, + TwoFactorAuthentication::SignInWebauthnSelectionPresenter, TwoFactorAuthentication::BackupCodeSelectionPresenter, TwoFactorAuthentication::PivCacSelectionPresenter, TwoFactorAuthentication::SignInAuthAppSelectionPresenter, @@ -95,7 +95,7 @@ it 'has only one webauthn selection presenter' do webauthn_selection_presenter_count = options_classes.count do |klass| - klass == TwoFactorAuthentication::WebauthnSelectionPresenter + klass == TwoFactorAuthentication::SignInWebauthnSelectionPresenter end expect(webauthn_selection_presenter_count).to eq 1 @@ -116,7 +116,7 @@ [ TwoFactorAuthentication::SmsSelectionPresenter, TwoFactorAuthentication::VoiceSelectionPresenter, - TwoFactorAuthentication::WebauthnSelectionPresenter, + TwoFactorAuthentication::SignInWebauthnSelectionPresenter, TwoFactorAuthentication::BackupCodeSelectionPresenter, TwoFactorAuthentication::PivCacSelectionPresenter, TwoFactorAuthentication::SignInAuthAppSelectionPresenter, @@ -133,7 +133,7 @@ it 'filters to phishing resistant methods' do expect(options_classes).to eq( [ - TwoFactorAuthentication::WebauthnSelectionPresenter, + TwoFactorAuthentication::SignInWebauthnSelectionPresenter, TwoFactorAuthentication::PivCacSelectionPresenter, ], ) @@ -147,7 +147,7 @@ [ TwoFactorAuthentication::SmsSelectionPresenter, TwoFactorAuthentication::VoiceSelectionPresenter, - TwoFactorAuthentication::WebauthnSelectionPresenter, + TwoFactorAuthentication::SignInWebauthnSelectionPresenter, TwoFactorAuthentication::BackupCodeSelectionPresenter, TwoFactorAuthentication::PivCacSelectionPresenter, TwoFactorAuthentication::SignInAuthAppSelectionPresenter, From 791e797c451d692f92934f60781f907c8891f3e0 Mon Sep 17 00:00:00 2001 From: kevinsmaster5 Date: Fri, 27 Oct 2023 11:53:11 -0400 Subject: [PATCH 09/12] fix with correct label translation --- .../sign_in_webauthn_selection_presenter.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/presenters/two_factor_authentication/sign_in_webauthn_selection_presenter.rb b/app/presenters/two_factor_authentication/sign_in_webauthn_selection_presenter.rb index fefc53bb61a..542ea6a1289 100644 --- a/app/presenters/two_factor_authentication/sign_in_webauthn_selection_presenter.rb +++ b/app/presenters/two_factor_authentication/sign_in_webauthn_selection_presenter.rb @@ -9,7 +9,7 @@ def render_in(view_context, &block) end def label - t('two_factor_authentication.two_factor_choice_options.webauthn') + t('two_factor_authentication.login_options.webauthn') end def info From fb4addb07cb8bac8d4fc2882a19a2ce853df6b21 Mon Sep 17 00:00:00 2001 From: kevinsmaster5 Date: Fri, 27 Oct 2023 12:02:23 -0400 Subject: [PATCH 10/12] add test coverage for setup webauthn --- ...et_up_webauthn_selection_presenter_spec.rb | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 spec/presenters/two_factor_authentication/set_up_webauthn_selection_presenter_spec.rb diff --git a/spec/presenters/two_factor_authentication/set_up_webauthn_selection_presenter_spec.rb b/spec/presenters/two_factor_authentication/set_up_webauthn_selection_presenter_spec.rb new file mode 100644 index 00000000000..ee36e194f3a --- /dev/null +++ b/spec/presenters/two_factor_authentication/set_up_webauthn_selection_presenter_spec.rb @@ -0,0 +1,35 @@ +require 'rails_helper' + +RSpec.describe TwoFactorAuthentication::SetUpWebauthnSelectionPresenter do + let(:user_without_mfa) { create(:user) } + let(:user_with_mfa) { create(:user) } + let(:configuration) {} + 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 webauthn' do + expect(presenter_without_mfa.type).to eq 'webauthn' + end + end + + describe '#mfa_configuration' do + it 'returns an empty string when user has not configured this authenticator' do + expect(presenter_without_mfa.mfa_configuration_description).to eq('') + end + + it 'returns an # added when user has configured this authenticator' do + create(:webauthn_configuration, platform_authenticator: false, user: user_with_mfa) + expect(presenter_with_mfa.mfa_configuration_description).to eq( + t( + 'two_factor_authentication.two_factor_choice_options.configurations_added', + count: 1, + ), + ) + end + end +end From 371a363b5f8391a527b69304d224abb246b03342 Mon Sep 17 00:00:00 2001 From: kevinsmaster5 Date: Mon, 30 Oct 2023 07:50:38 -0400 Subject: [PATCH 11/12] point spec to sign in webauthn class --- spec/models/webauthn_configuration_spec.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/spec/models/webauthn_configuration_spec.rb b/spec/models/webauthn_configuration_spec.rb index 28e856699f7..e1c84e1cad4 100644 --- a/spec/models/webauthn_configuration_spec.rb +++ b/spec/models/webauthn_configuration_spec.rb @@ -16,7 +16,7 @@ presenters = subject.selection_presenters expect(presenters.count).to eq 1 expect(presenters.first).to be_instance_of( - TwoFactorAuthentication::WebauthnSelectionPresenter, + TwoFactorAuthentication::SignInWebauthnSelectionPresenter, ) end end @@ -27,7 +27,7 @@ presenters = subject.selection_presenters expect(presenters.count).to eq 1 expect(presenters.first).to be_instance_of( - TwoFactorAuthentication::WebauthnPlatformSelectionPresenter, + TwoFactorAuthentication::SignInWebauthnPlatformSelectionPresenter, ) end end From 3c30b5d4840568aeb66d452351cc150215d4964f Mon Sep 17 00:00:00 2001 From: kevinsmaster5 Date: Tue, 31 Oct 2023 12:53:28 -0400 Subject: [PATCH 12/12] correct some small code inconsistency --- .../set_up_webauthn_platform_selection_presenter.rb | 8 ++++---- .../sign_in_webauthn_platform_selection_presenter.rb | 6 ++---- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/app/presenters/two_factor_authentication/set_up_webauthn_platform_selection_presenter.rb b/app/presenters/two_factor_authentication/set_up_webauthn_platform_selection_presenter.rb index 0b6b826ed24..278fb3b1ad9 100644 --- a/app/presenters/two_factor_authentication/set_up_webauthn_platform_selection_presenter.rb +++ b/app/presenters/two_factor_authentication/set_up_webauthn_platform_selection_presenter.rb @@ -1,14 +1,14 @@ module TwoFactorAuthentication class SetUpWebauthnPlatformSelectionPresenter < SetUpSelectionPresenter - def method - :webauthn_platform - end - def initialize(user:, configuration: nil) @user = user @configuration = configuration end + def method + :webauthn_platform + end + def render_in(view_context, &block) view_context.render( WebauthnInputComponent.new( diff --git a/app/presenters/two_factor_authentication/sign_in_webauthn_platform_selection_presenter.rb b/app/presenters/two_factor_authentication/sign_in_webauthn_platform_selection_presenter.rb index d5469a24c6a..b1632c78998 100644 --- a/app/presenters/two_factor_authentication/sign_in_webauthn_platform_selection_presenter.rb +++ b/app/presenters/two_factor_authentication/sign_in_webauthn_platform_selection_presenter.rb @@ -8,10 +8,8 @@ def render_in(view_context, &block) view_context.render( WebauthnInputComponent.new( platform: true, - passkey_supported_only: configuration.blank?, - show_unsupported_passkey: - configuration.blank? && - IdentityConfig.store.show_unsupported_passkey_platform_authentication_setup, + passkey_supported_only: false, + show_unsupported_passkey: false, ), &block )