Skip to content

OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub

Add a factory for webauthn

Klaus Zanders9e14b667075a
diff --git a/modules/two_factor_authentication/spec/factories/two_factor_authentication_device_factory.rb b/modules/two_factor_authentication/spec/factories/two_factor_authentication_device_factory.rb
index da49de55f7e..661aaf49356 100644
--- a/modules/two_factor_authentication/spec/factories/two_factor_authentication_device_factory.rb
+++ b/modules/two_factor_authentication/spec/factories/two_factor_authentication_device_factory.rb
@@ -3,7 +3,6 @@ FactoryBot.define do
user
channel { :sms }
active { true }
- default { true }
phone_number { '+49 123456789' }
identifier { 'Phone number (+49 123456789)' }
@@ -15,14 +14,11 @@ FactoryBot.define do
device.make_default! if evaluator.make_default
end
end
-end
-FactoryBot.define do
factory :two_factor_authentication_device_totp, class: '::TwoFactorAuthentication::Device::Totp' do
user
channel { :totp }
active { true }
- default { true }
identifier { 'TOTP device' }
transient do
@@ -33,4 +29,29 @@ FactoryBot.define do
device.make_default! if evaluator.make_default
end
end
+
+ factory :two_factor_authentication_device_webauthn, class: '::TwoFactorAuthentication::Device::Webauthn' do
+ user
+ channel { :webauthn }
+ active { true }
+ identifier { 'WebAuthn device' }
+
+ webauthn_external_id { "foo" }
+ webauthn_public_key { "bar" }
+
+ transient do
+ make_default { false }
+ end
+
+ callback(:after_create) do |device, evaluator|
+ # Ensure user has a webauthn id
+ if device.user.webauthn_id.blank?
+ device.user.update!(webauthn_id: WebAuthn.generate_user_id)
+ end
+
+ # Generate Fake Credential, see https://github.com/cedarcode/webauthn-ruby/blob/master/spec/spec_helper.rb#L26
+
+ device.make_default! if evaluator.make_default
+ end
+ end
end