debian-mirror-gitlab/spec/factories/users.rb

194 lines
4.4 KiB
Ruby
Raw Normal View History

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