[add] initial commit

This commit is contained in:
2021-02-24 03:22:52 -05:00
commit c8c91b21d9
57 changed files with 2707 additions and 0 deletions

View File

@@ -0,0 +1,3 @@
RSpec.configure do |config|
config.include FactoryBot::Syntax::Methods
end

View 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

View 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