From 600a3f36996c2875521eed30e97a76abe4d2b024 Mon Sep 17 00:00:00 2001 From: Andrew Duthie Date: Wed, 24 Jan 2024 08:33:25 -0500 Subject: [PATCH 1/3] Improve reliability of WebauthnSetupForm spec changelog: Internal, Automated Testing, Improve reliability of tests --- spec/forms/webauthn_setup_form_spec.rb | 49 ++++++++++---------------- 1 file changed, 18 insertions(+), 31 deletions(-) diff --git a/spec/forms/webauthn_setup_form_spec.rb b/spec/forms/webauthn_setup_form_spec.rb index e467c404ec0..5c4f08ef95c 100644 --- a/spec/forms/webauthn_setup_form_spec.rb +++ b/spec/forms/webauthn_setup_form_spec.rb @@ -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) @@ -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' @@ -276,37 +275,25 @@ 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, + name: device_name, + platform_authenticator: true, + ), ) 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 From 7f0603fc9bf620815e3e9317aa17bb43c7be2d9a Mon Sep 17 00:00:00 2001 From: Andrew Duthie Date: Wed, 24 Jan 2024 08:36:01 -0500 Subject: [PATCH 2/3] Assign transports for consistency --- spec/forms/webauthn_setup_form_spec.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/spec/forms/webauthn_setup_form_spec.rb b/spec/forms/webauthn_setup_form_spec.rb index 5c4f08ef95c..718a8928be3 100644 --- a/spec/forms/webauthn_setup_form_spec.rb +++ b/spec/forms/webauthn_setup_form_spec.rb @@ -283,6 +283,7 @@ 2, name: device_name, platform_authenticator: true, + transports: 'internal,hybrid', ), ) end From 041721f8087c383b5c13bad15f25418c577abdc0 Mon Sep 17 00:00:00 2001 From: Andrew Duthie Date: Wed, 24 Jan 2024 09:03:04 -0500 Subject: [PATCH 3/3] Use correct value format --- spec/forms/webauthn_setup_form_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/forms/webauthn_setup_form_spec.rb b/spec/forms/webauthn_setup_form_spec.rb index 718a8928be3..284b5811446 100644 --- a/spec/forms/webauthn_setup_form_spec.rb +++ b/spec/forms/webauthn_setup_form_spec.rb @@ -283,7 +283,7 @@ 2, name: device_name, platform_authenticator: true, - transports: 'internal,hybrid', + transports: ['internal', 'hybrid'], ), ) end