2024-06-04 15:42:53 +08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
Fabricator(:user_password) do
|
|
|
|
transient password: "myawesomefakepassword"
|
|
|
|
|
2024-10-10 09:23:06 +08:00
|
|
|
user { Fabricate(:user, password: nil) }
|
|
|
|
password_salt { SecureRandom.hex(UserPassword::PASSWORD_SALT_LENGTH) }
|
|
|
|
password_algorithm { UserPassword::TARGET_PASSWORD_ALGORITHM }
|
2024-06-04 15:42:53 +08:00
|
|
|
|
|
|
|
after_build do |user_password, transients|
|
2024-10-10 09:23:06 +08:00
|
|
|
if transients[:password].present?
|
|
|
|
user_password.password_hash =
|
|
|
|
PasswordHasher.hash_password(
|
|
|
|
password: transients[:password],
|
|
|
|
salt: user_password.password_salt,
|
|
|
|
algorithm: user_password.password_algorithm,
|
|
|
|
)
|
|
|
|
end
|
2024-06-04 15:42:53 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
Fabricator(:expired_user_password, from: :user_password) { password_expired_at { 1.day.ago } }
|