-
Notifications
You must be signed in to change notification settings - Fork 115
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
LG 11140 Break up webauthn selection presenter #9467
Changes from all commits
0847cca
cd22358
27ffb59
73ba2f4
3e1a309
1bfc0fe
653ed69
6ea6c11
791e797
fb4addb
371a363
3c30b5d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
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: false, | ||
show_unsupported_passkey: false, | ||
), | ||
&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 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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.login_options.webauthn') | ||
end | ||
|
||
def info | ||
t('two_factor_authentication.login_options.webauthn_info') | ||
end | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,14 @@ | ||
require 'rails_helper' | ||
|
||
RSpec.describe TwoFactorAuthentication::WebauthnSelectionPresenter do | ||
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(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 | ||
|
@@ -17,19 +17,6 @@ | |
end | ||
end | ||
|
||
describe '#render_in' do | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we lost test coverage here, we still have a |
||
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('') | ||
|
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,32 @@ | ||||||||||||||||||||||||||||||||||||||
require 'rails_helper' | ||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||
RSpec.describe TwoFactorAuthentication::SignInWebauthnPlatformSelectionPresenter 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_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_platform'), | ||||||||||||||||||||||||||||||||||||||
) | ||||||||||||||||||||||||||||||||||||||
end | ||||||||||||||||||||||||||||||||||||||
end | ||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||
describe '#info' do | ||||||||||||||||||||||||||||||||||||||
it 'raises with missing translation' do | ||||||||||||||||||||||||||||||||||||||
Comment on lines
+18
to
+26
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I just noticed these as I start work on a related ticket. These methods don't raise, so I think we should revise the expectation description accordingly.
Suggested change
|
||||||||||||||||||||||||||||||||||||||
expect(presenter.info).to eq( | ||||||||||||||||||||||||||||||||||||||
t('two_factor_authentication.login_options.webauthn_platform_info'), | ||||||||||||||||||||||||||||||||||||||
) | ||||||||||||||||||||||||||||||||||||||
end | ||||||||||||||||||||||||||||||||||||||
end | ||||||||||||||||||||||||||||||||||||||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we can remove checks below to
configuration.blank?
, since I would expect that the configuration should never be blank in the "Sign in" classes. They should be replaced withfalse
.