[add] initial commit
This commit is contained in:
3
spec/support/factory_bot.rb
Normal file
3
spec/support/factory_bot.rb
Normal file
@@ -0,0 +1,3 @@
|
||||
RSpec.configure do |config|
|
||||
config.include FactoryBot::Syntax::Methods
|
||||
end
|
||||
38
spec/support/factory_clients_helper.rb
Normal file
38
spec/support/factory_clients_helper.rb
Normal file
@@ -0,0 +1,38 @@
|
||||
# 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
|
||||
31
spec/support/request_spec_helper.rb
Normal file
31
spec/support/request_spec_helper.rb
Normal file
@@ -0,0 +1,31 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
module RequestSpecHelper
|
||||
def json_response
|
||||
JSON.parse(response.body)
|
||||
end
|
||||
|
||||
def api_key_header(client, api_key = nil)
|
||||
api_key ||= [RynDNS::Application::API_KEY_PREFIX, client.name_id, client.description].join('.')
|
||||
{ RynDNS::Application::API_KEY_HEADER =>
|
||||
api_key }
|
||||
end
|
||||
|
||||
def parse_permission(perm_r, perm_w, perm_x)
|
||||
"#{'r' if perm_r}#{'w' if perm_w}#{'x' if perm_x}"
|
||||
end
|
||||
|
||||
def list_equals_db?(client_list)
|
||||
return false unless Client.count == client_list.count
|
||||
|
||||
client_list.each do |client|
|
||||
db_client = Client.find_by name: client[:name.to_s]
|
||||
return false unless db_client.description == client[:description.to_s] &&
|
||||
db_client.permission == client[:permission.to_s] &&
|
||||
db_client.public_ip == client[:public_ip.to_s] &&
|
||||
db_client.ipv4 == client[:ipv4.to_s]
|
||||
end
|
||||
true
|
||||
end
|
||||
|
||||
end
|
||||
Reference in New Issue
Block a user