-
Notifications
You must be signed in to change notification settings - Fork 167
LG-10687 Break Up MFA Presenters #9211
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 7 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
d3e9073
commit
mdiarra3 535d68e
Separate auth app selections configurations
mdiarra3 1c24154
break up mfa presenters
mdiarra3 9ba137c
changelog: Internal, Authentication, Refactor presenter logic to sepa…
mdiarra3 4d54f69
rubocop
mdiarra3 11490e7
auth app selection
mdiarra3 4c2c732
remove authentication app slection presenter
mdiarra3 3d0a093
remove association with selection presenter
mdiarra3 790f5ab
Merge remote-tracking branch 'origin/main' into LG-10687-break-up-mfa…
mdiarra3 82a5e83
Merge remote-tracking branch 'origin/main' into LG-10687-break-up-mfa…
mdiarra3 8c46ca9
add end
mdiarra3 80f20a6
make sure to include disabled?
mdiarra3 0b35ef5
Merge remote-tracking branch 'origin/main' into LG-10687-break-up-mfa…
mdiarra3 2be4ea4
Merge remote-tracking branch 'origin/main' into LG-10687-break-up-mfa…
mdiarra3 d76bac0
add rspec for sign in auth app spec
mdiarra3 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
94 changes: 94 additions & 0 deletions
94
app/presenters/two_factor_authentication/set_up_selection_presenter.rb
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +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 | ||
| 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 | ||
7 changes: 7 additions & 0 deletions
7
app/presenters/two_factor_authentication/sign_in_auth_app_selection_presenter.rb
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| module TwoFactorAuthentication | ||
| class SignInAuthAppSelectionPresenter < SignInSelectionPresenter | ||
| def method | ||
| :auth_app | ||
| end | ||
| end | ||
| end |
62 changes: 62 additions & 0 deletions
62
app/presenters/two_factor_authentication/sign_in_selection_presenter.rb
|
mdiarra3 marked this conversation as resolved.
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| 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 | ||
|
aduth marked this conversation as resolved.
|
||
| end | ||
| end | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
105 changes: 105 additions & 0 deletions
105
spec/presenters/two_factor_authentication/set_up_selection_presenter_spec.rb
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.