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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ def process_valid_form
'personal_key' => login_two_factor_personal_key_url,
'sms' => otp_send_url(otp_delivery_selection_form: { otp_delivery_preference: 'sms' }),
'auth_app' => login_two_factor_authenticator_url,
'piv_cac' => login_two_factor_piv_cac_url,
'webauthn' => login_two_factor_webauthn_url,
'piv_cac' => FeatureManagement.piv_cac_enabled? ? login_two_factor_piv_cac_url : nil,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if we did

factor_to_url['piv_cac'] = login_two_factor_piv_cac_url if FeatureManagement.piv_cac_enabled?`

That helps keep us from having to use a confusing ternary inside a hash

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

reek complains

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will be changed up when #2492 gets merged, so I'm not as worried about the ternary.

'webauthn' => FeatureManagement.webauthn_enabled? ? login_two_factor_webauthn_url : nil,
}
url = factor_to_url[@two_factor_options_form.selection]
redirect_to url if url
Expand Down
6 changes: 5 additions & 1 deletion app/presenters/two_factor_options_presenter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,11 @@ def options
private

def available_2fa_types
%w[sms voice auth_app webauthn] + piv_cac_if_available
%w[sms voice auth_app] + webauthn_if_available + piv_cac_if_available
end

def webauthn_if_available
FeatureManagement.webauthn_enabled? ? %w[webauthn] : []
end

def piv_cac_if_available
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,18 @@
describe '#create' do
before { sign_in_before_2fa }

it 'redirects to login_two_factor_url for sms with piv/cac and webauthn disabled' do
piv_cac_webauthn_enabled('false')

post :create, params: { two_factor_options_form: { selection: 'sms' } }

expect(response).to redirect_to otp_send_url( \
otp_delivery_selection_form: { otp_delivery_preference: 'sms' }
)

piv_cac_webauthn_enabled('true')
end

it 'redirects to login_two_factor_url if user selects sms' do
post :create, params: { two_factor_options_form: { selection: 'sms' } }

Expand Down Expand Up @@ -80,4 +92,10 @@
post :create, params: { two_factor_options_form: { selection: 'sms' } }
end
end

def piv_cac_webauthn_enabled(bool)
allow(Figaro.env).to receive(:piv_cac_enabled) { bool }
allow(Figaro.env).to receive(:webauthn_enabled) { bool }
Rails.application.reload_routes!
end
end