Files
rynDNS/spec/support/factory_clients_helper.rb
2021-02-25 00:04:34 -05:00

39 lines
1017 B
Ruby

# frozen_string_literal: true
def bcrypt_fake_hash
# bcrypt output is defined as follows:
# $<id>$<cost>$<salt><digest>
# with <salt> and <digest> being base64 encoded with the following alphabet:
# ./ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789
bcrypt_alphabet = [
%w[. /],
Array('A'..'Z'),
Array('a'..'z'),
Array('0'..'9')
].flatten
id = "2#{Faker::Base.sample(%w[a x y], 1).join}"
cost = format('%02d', Faker::Number.between(from: 4, to: 99))
salt = Faker::Base.sample(bcrypt_alphabet, 22).join
digest = Faker::Base.sample(bcrypt_alphabet, 31).join
"$#{id}$#{cost}$#{salt}#{digest}"
end
def nil_or_fake(fake)
Faker::Boolean.boolean ? fake : nil
end
def empty_or_fake(fake)
Faker::Boolean.boolean ? fake : ''
end
# custom alphabet for name
def random_string
alphabet = [
%w[. _ - @],
Array('A'..'Z'),
Array('a'..'z'),
Array('0'..'9')
].flatten
Faker::Base.sample(alphabet, 20).join[0, Faker::Number.between(from: 3, to: 19)]
end