Skip to content
Merged
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
50 changes: 19 additions & 31 deletions spec/forms/webauthn_setup_form_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,10 @@
end
end
context 'webauthn_platform' do
let(:params) do
super().merge(platform_authenticator: true, transports: 'internal,hybrid')
end

context 'with one platform authenticator with the same name' do
let(:user) do
user = create(:user)
Expand All @@ -257,12 +261,7 @@
)
user
end
let(:params) do
super().merge(
platform_authenticator: true,
transports: 'internal,hybrid',
)
end

it 'adds a new platform device with the same existing name and appends a (1)' do
result = subject.submit(protocol, params)
expect(result.extra[:multi_factor_auth_method]).to eq 'webauthn_platform'
Expand All @@ -276,37 +275,26 @@
end

context 'with two existing platform authenticators one with the same name' do
let(:user) do
user = create(:user)
user.webauthn_configurations << create(
:webauthn_configuration,
name: device_name,
platform_authenticator: true,
transports: ['internal', 'hybrid'],
)
user.webauthn_configurations << create(
:webauthn_configuration,
name: device_name,
platform_authenticator: true,
transports: ['internal', 'hybrid'],
)
user
end
let(:params) do
super().merge(
platform_authenticator: true,
transports: 'internal,hybrid',
let!(:user) do
create(
:user,
webauthn_configurations: create_list(
:webauthn_configuration,
2,
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.

If I'm understanding correctly - this creates the 2 configurations at the same time rather than how they were being created before? Using create_list.

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.

Yep, a little trick I learned recently.

name: device_name,
platform_authenticator: true,
transports: ['internal', 'hybrid'],
),
)
end

it 'adds a second new platform device with the same existing name and appends a (2)' do
result = subject.submit(protocol, params)
expect(result.extra[:multi_factor_auth_method]).to eq 'webauthn_platform'

expect(result.success?).to eq(true)
expect(user.webauthn_configurations.platform_authenticators.count).to eq(3)
expect(
user.webauthn_configurations.platform_authenticators[2].name,
).
expect(user.webauthn_configurations.platform_authenticators.last.name).
to eq("#{device_name} (2)")
expect(result.to_h[:success]).to eq(true)
end
end
end
Expand Down