2019-07-25 05:11:48 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-12-14 00:13:44 +00:00
|
|
|
FactoryBot.define do
|
2017-08-09 09:31:25 +00:00
|
|
|
factory :user, aliases: [:author, :assignee, :recipient, :owner, :resource_owner] do
|
2017-03-23 13:08:39 +00:00
|
|
|
email { generate(:email) }
|
|
|
|
name { generate(:name) }
|
|
|
|
username { generate(:username) }
|
2019-10-02 00:06:26 +00:00
|
|
|
password { "12345678" }
|
2019-10-18 21:06:37 +00:00
|
|
|
role { 'software_developer' }
|
2016-02-17 03:55:24 +00:00
|
|
|
confirmed_at { Time.now }
|
|
|
|
confirmation_token { nil }
|
2019-10-02 00:06:26 +00:00
|
|
|
can_create_group { true }
|
2016-02-17 03:55:24 +00:00
|
|
|
|
|
|
|
trait :admin do
|
2019-10-02 00:06:26 +00:00
|
|
|
admin { true }
|
2016-02-17 03:55:24 +00:00
|
|
|
end
|
|
|
|
|
2021-10-28 18:14:18 +00:00
|
|
|
trait :public_email do
|
|
|
|
public_email { email }
|
|
|
|
end
|
|
|
|
|
2017-02-01 18:21:28 +00:00
|
|
|
trait :blocked do
|
|
|
|
after(:build) { |user, _| user.block! }
|
|
|
|
end
|
|
|
|
|
2020-10-06 12:08:38 +00:00
|
|
|
trait :blocked_pending_approval do
|
|
|
|
after(:build) { |user, _| user.block_pending_approval! }
|
|
|
|
end
|
|
|
|
|
2021-05-14 18:10:34 +00:00
|
|
|
trait :banned do
|
|
|
|
after(:build) { |user, _| user.ban! }
|
|
|
|
end
|
|
|
|
|
2020-10-06 12:08:38 +00:00
|
|
|
trait :ldap_blocked do
|
|
|
|
after(:build) { |user, _| user.ldap_block! }
|
|
|
|
end
|
|
|
|
|
2020-02-06 12:10:29 +00:00
|
|
|
trait :bot do
|
2020-03-18 09:09:31 +00:00
|
|
|
user_type { :alert_bot }
|
2020-02-06 12:10:29 +00:00
|
|
|
end
|
|
|
|
|
2020-11-23 12:09:11 +00:00
|
|
|
trait :deactivated do
|
|
|
|
after(:build) { |user, _| user.deactivate! }
|
|
|
|
end
|
|
|
|
|
2020-04-21 15:21:10 +00:00
|
|
|
trait :project_bot do
|
|
|
|
user_type { :project_bot }
|
|
|
|
end
|
|
|
|
|
2020-05-04 21:09:41 +00:00
|
|
|
trait :migration_bot do
|
|
|
|
user_type { :migration_bot }
|
|
|
|
end
|
|
|
|
|
2020-12-11 18:09:57 +00:00
|
|
|
trait :security_bot do
|
|
|
|
user_type { :security_bot }
|
|
|
|
end
|
|
|
|
|
2017-02-01 18:21:28 +00:00
|
|
|
trait :external do
|
2019-10-02 00:06:26 +00:00
|
|
|
external { true }
|
2017-02-01 18:21:28 +00:00
|
|
|
end
|
|
|
|
|
2016-02-17 03:55:24 +00:00
|
|
|
trait :two_factor do
|
2016-06-06 04:38:42 +00:00
|
|
|
two_factor_via_otp
|
|
|
|
end
|
|
|
|
|
2017-02-06 12:07:05 +00:00
|
|
|
trait :ghost do
|
2020-04-24 18:09:46 +00:00
|
|
|
user_type { :ghost }
|
2017-02-17 14:58:12 +00:00
|
|
|
after(:build) { |user, _| user.block! }
|
2017-02-06 12:07:05 +00:00
|
|
|
end
|
|
|
|
|
2020-05-27 21:08:05 +00:00
|
|
|
trait :unconfirmed do
|
|
|
|
confirmed_at { nil }
|
|
|
|
end
|
|
|
|
|
2017-05-03 15:25:31 +00:00
|
|
|
trait :with_avatar do
|
2018-02-01 19:24:59 +00:00
|
|
|
avatar { fixture_file_upload('spec/fixtures/dk.png') }
|
2017-05-03 15:25:31 +00:00
|
|
|
end
|
|
|
|
|
2019-08-30 21:30:51 +00:00
|
|
|
trait :with_sign_ins do
|
2019-10-02 00:06:26 +00:00
|
|
|
sign_in_count { 3 }
|
2020-11-13 00:09:49 +00:00
|
|
|
current_sign_in_at { FFaker::Time.between(10.days.ago, 1.day.ago) }
|
2019-08-30 21:30:51 +00:00
|
|
|
last_sign_in_at { FFaker::Time.between(10.days.ago, 1.day.ago) }
|
2019-10-02 00:06:26 +00:00
|
|
|
current_sign_in_ip { '127.0.0.1' }
|
|
|
|
last_sign_in_ip { '127.0.0.1' }
|
2019-08-30 21:30:51 +00:00
|
|
|
end
|
|
|
|
|
2021-05-05 00:10:41 +00:00
|
|
|
trait :with_credit_card_validation do
|
|
|
|
after :create do |user|
|
|
|
|
create :credit_card_validation, user: user
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-06-06 04:38:42 +00:00
|
|
|
trait :two_factor_via_otp do
|
2016-02-17 03:55:24 +00:00
|
|
|
before(:create) do |user|
|
2016-06-06 04:38:42 +00:00
|
|
|
user.otp_required_for_login = true
|
2016-02-17 03:55:24 +00:00
|
|
|
user.otp_secret = User.generate_otp_secret(32)
|
|
|
|
user.otp_grace_period_started_at = Time.now
|
|
|
|
user.generate_otp_backup_codes!
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-06-06 04:38:42 +00:00
|
|
|
trait :two_factor_via_u2f do
|
2019-10-02 00:06:26 +00:00
|
|
|
transient { registrations_count { 5 } }
|
2016-06-06 04:38:42 +00:00
|
|
|
|
|
|
|
after(:create) do |user, evaluator|
|
|
|
|
create_list(:u2f_registration, evaluator.registrations_count, user: user)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-09-07 12:08:27 +00:00
|
|
|
trait :two_factor_via_webauthn do
|
|
|
|
transient { registrations_count { 5 } }
|
|
|
|
|
|
|
|
after(:create) do |user, evaluator|
|
|
|
|
create_list(:webauthn_registration, evaluator.registrations_count, user: user)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-11-21 17:58:42 +00:00
|
|
|
trait :readme do
|
2019-10-02 00:06:26 +00:00
|
|
|
project_view { :readme }
|
2017-11-21 17:58:42 +00:00
|
|
|
end
|
|
|
|
|
2018-09-17 13:14:58 +00:00
|
|
|
trait :commit_email do
|
|
|
|
after(:create) do |user, evaluator|
|
|
|
|
additional = create(:email, :confirmed, user: user, email: "commit-#{user.email}")
|
|
|
|
|
|
|
|
user.update!(commit_email: additional.email)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-04-11 15:21:18 +00:00
|
|
|
transient do
|
2019-10-02 00:06:26 +00:00
|
|
|
developer_projects { [] }
|
2020-04-21 15:21:10 +00:00
|
|
|
maintainer_projects { [] }
|
2019-04-11 15:21:18 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
after(:create) do |user, evaluator|
|
|
|
|
evaluator.developer_projects.each do |project|
|
|
|
|
project.add_developer(user)
|
|
|
|
end
|
2020-04-21 15:21:10 +00:00
|
|
|
|
|
|
|
evaluator.maintainer_projects.each do |project|
|
|
|
|
project.add_maintainer(user)
|
|
|
|
end
|
2019-04-11 15:21:18 +00:00
|
|
|
end
|
|
|
|
|
2016-02-17 03:55:24 +00:00
|
|
|
factory :omniauth_user do
|
2021-09-29 12:11:22 +00:00
|
|
|
password_automatically_set { true }
|
|
|
|
|
2016-02-17 03:55:24 +00:00
|
|
|
transient do
|
2019-10-02 00:06:26 +00:00
|
|
|
extern_uid { '123456' }
|
|
|
|
provider { 'ldapmain' }
|
2016-02-17 03:55:24 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
after(:create) do |user, evaluator|
|
2019-02-14 17:56:34 +00:00
|
|
|
identity_attrs = {
|
2016-02-17 03:55:24 +00:00
|
|
|
provider: evaluator.provider,
|
|
|
|
extern_uid: evaluator.extern_uid
|
2019-02-14 17:56:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if evaluator.respond_to?(:saml_provider)
|
|
|
|
identity_attrs[:saml_provider] = evaluator.saml_provider
|
|
|
|
end
|
|
|
|
|
|
|
|
user.identities << create(:identity, identity_attrs)
|
2016-02-17 03:55:24 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-09-10 18:08:54 +00:00
|
|
|
factory :atlassian_user do
|
|
|
|
transient do
|
|
|
|
extern_uid { generate(:username) }
|
|
|
|
end
|
|
|
|
|
|
|
|
after(:create) do |user, evaluator|
|
|
|
|
create(:atlassian_identity, user: user, extern_uid: evaluator.extern_uid)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-02-17 03:55:24 +00:00
|
|
|
factory :admin, traits: [:admin]
|
|
|
|
end
|
|
|
|
end
|