mirror of
https://github.com/internetee/registry.git
synced 2025-05-16 09:27:19 +02:00
Refactor settings
This commit is contained in:
parent
26f5eda636
commit
dafcb6f78c
25 changed files with 132 additions and 282 deletions
3
Gemfile
3
Gemfile
|
@ -67,6 +67,9 @@ gem 'selectize-rails', '~> 0.11.0'
|
|||
# See https://github.com/sstephenson/execjs#readme for more supported runtimes
|
||||
gem 'therubyracer', platforms: :ruby
|
||||
|
||||
# for settings
|
||||
gem "rails-settings-cached", '0.4.1'
|
||||
|
||||
group :development, :test do
|
||||
gem 'capybara', '~> 2.4.1'
|
||||
# For feature testing
|
||||
|
|
|
@ -200,6 +200,8 @@ GEM
|
|||
bundler (>= 1.3.0, < 2.0)
|
||||
railties (= 4.1.4)
|
||||
sprockets-rails (~> 2.0)
|
||||
rails-settings-cached (0.4.1)
|
||||
rails (>= 4.0.0)
|
||||
railties (4.1.4)
|
||||
actionpack (= 4.1.4)
|
||||
activesupport (= 4.1.4)
|
||||
|
@ -376,6 +378,7 @@ DEPENDENCIES
|
|||
poltergeist (~> 1.5.1)
|
||||
pry (~> 0.10.1)
|
||||
rails (= 4.1.4)
|
||||
rails-settings-cached (= 0.4.1)
|
||||
ransack (~> 1.3.0)
|
||||
rspec-rails (~> 3.0.2)
|
||||
rubocop (~> 0.26.1)
|
||||
|
|
|
@ -1,42 +0,0 @@
|
|||
class DelegationSigner < ActiveRecord::Base
|
||||
include EppErrors
|
||||
has_one :dnskeys
|
||||
|
||||
validate :validate_dnskeys_uniqueness
|
||||
validate :validate_dnskeys_count
|
||||
|
||||
def epp_code_map
|
||||
sg = SettingGroup.domain_validation
|
||||
|
||||
{
|
||||
'2004' => [ # Parameter value range error
|
||||
[:dnskeys, :out_of_range,
|
||||
{
|
||||
min: sg.setting(Setting::DNSKEYS_MIN_COUNT).value,
|
||||
max: sg.setting(Setting::DNSKEYS_MAX_COUNT).value
|
||||
}
|
||||
]
|
||||
]
|
||||
}
|
||||
end
|
||||
|
||||
def validate_dnskeys_count
|
||||
sg = SettingGroup.domain_validation
|
||||
min, max = sg.setting(:dnskeys_min_count).value.to_i, sg.setting(:dnskeys_max_count).value.to_i
|
||||
return if dnskeys.reject(&:marked_for_destruction?).length.between?(min, max)
|
||||
errors.add(:dnskeys, :out_of_range, { min: min, max: max })
|
||||
end
|
||||
|
||||
def validate_dnskeys_uniqueness
|
||||
validated = []
|
||||
list = dnskeys.reject(&:marked_for_destruction?)
|
||||
list.each do |dnskey|
|
||||
next if dnskey.public_key.blank?
|
||||
existing = list.select { |x| x.public_key == dnskey.public_key }
|
||||
next unless existing.length > 1
|
||||
validated << dnskey.public_key
|
||||
errors.add(:dnskeys, :invalid) if errors[:dnskeys].blank?
|
||||
dnskey.errors.add(:public_key, :taken)
|
||||
end
|
||||
end
|
||||
end
|
|
@ -66,11 +66,9 @@ class Dnskey < ActiveRecord::Base
|
|||
hex = [domain.name_in_wire_format, flags_hex, protocol_hex, alg_hex, public_key_hex].join
|
||||
bin = self.class.hex_to_bin(hex)
|
||||
|
||||
sg = SettingGroup.dnskeys.setting(Setting::DS_ALGORITHM).value
|
||||
|
||||
if sg == '1'
|
||||
if Setting.ds_algorithm == 1
|
||||
self.ds_digest = Digest::SHA1.hexdigest(bin).upcase
|
||||
elsif sg == '2'
|
||||
elsif Setting.ds_algorithm == 2
|
||||
self.ds_digest = Digest::SHA256.hexdigest(bin).upcase
|
||||
end
|
||||
end
|
||||
|
|
|
@ -85,9 +85,7 @@ class Domain < ActiveRecord::Base
|
|||
|
||||
### VALIDATIONS ###
|
||||
def validate_nameservers_count
|
||||
sg = SettingGroup.domain_validation
|
||||
min, max = sg.setting(:ns_min_count).value.to_i, sg.setting(:ns_max_count).value.to_i
|
||||
|
||||
min, max = Setting.ns_min_count, Setting.ns_max_count
|
||||
return if nameservers.reject(&:marked_for_destruction?).length.between?(min, max)
|
||||
errors.add(:nameservers, :out_of_range, { min: min, max: max })
|
||||
end
|
||||
|
@ -97,8 +95,7 @@ class Domain < ActiveRecord::Base
|
|||
end
|
||||
|
||||
def validate_dnskeys_count
|
||||
sg = SettingGroup.domain_validation
|
||||
min, max = sg.setting(:dnskeys_min_count).value.to_i, sg.setting(:dnskeys_max_count).value.to_i
|
||||
min, max = Setting.dnskeys_min_count, Setting.dnskeys_max_count
|
||||
return if dnskeys.reject(&:marked_for_destruction?).length.between?(min, max)
|
||||
errors.add(:dnskeys, :out_of_range, { min: min, max: max })
|
||||
end
|
||||
|
|
|
@ -14,7 +14,7 @@ class DomainTransfer < ActiveRecord::Base
|
|||
before_create :set_wait_until
|
||||
|
||||
def set_wait_until
|
||||
wait_time = SettingGroup.domain_general.setting(:transfer_wait_time).value.to_i
|
||||
wait_time = Setting.transfer_wait_time
|
||||
return if wait_time == 0
|
||||
self.wait_until = transfer_requested_at + wait_time.hours
|
||||
end
|
||||
|
|
|
@ -6,8 +6,6 @@ class Epp::EppDomain < Domain
|
|||
validate :validate_admin_contacts_count
|
||||
|
||||
def epp_code_map # rubocop:disable Metrics/MethodLength
|
||||
domain_validation_sg = SettingGroup.domain_validation
|
||||
|
||||
{
|
||||
'2002' => [
|
||||
[:base, :domain_already_belongs_to_the_querying_registrar]
|
||||
|
@ -29,15 +27,15 @@ class Epp::EppDomain < Domain
|
|||
'2004' => [ # Parameter value range error
|
||||
[:nameservers, :out_of_range,
|
||||
{
|
||||
min: domain_validation_sg.setting(:ns_min_count).value,
|
||||
max: domain_validation_sg.setting(:ns_max_count).value
|
||||
min: Setting.ns_min_count,
|
||||
max: Setting.ns_max_count
|
||||
}
|
||||
],
|
||||
[:period, :out_of_range, { value: { obj: 'period', val: period } }],
|
||||
[:dnskeys, :out_of_range,
|
||||
{
|
||||
min: domain_validation_sg.setting(Setting::DNSKEYS_MIN_COUNT).value,
|
||||
max: domain_validation_sg.setting(Setting::DNSKEYS_MAX_COUNT).value
|
||||
min: Setting.dnskeys_min_count,
|
||||
max: Setting.dnskeys_max_count
|
||||
}
|
||||
]
|
||||
],
|
||||
|
@ -189,8 +187,7 @@ class Epp::EppDomain < Domain
|
|||
end
|
||||
|
||||
def attach_dnskeys(dnssec_data)
|
||||
sg = SettingGroup.dnskeys
|
||||
return false unless validate_dnssec_data(dnssec_data, sg)
|
||||
return false unless validate_dnssec_data(dnssec_data)
|
||||
|
||||
dnssec_data[:ds_data].each do |ds_data|
|
||||
dnskeys.build(ds_data)
|
||||
|
@ -200,41 +197,35 @@ class Epp::EppDomain < Domain
|
|||
dnskeys.build({
|
||||
ds_key_tag: SecureRandom.hex(5),
|
||||
ds_alg: 3,
|
||||
ds_digest_type: sg.setting(Setting::DS_ALGORITHM).value
|
||||
ds_digest_type: Setting.ds_algorithm
|
||||
}.merge(x))
|
||||
end
|
||||
end
|
||||
|
||||
def validate_dnssec_data(dnssec_data, sg)
|
||||
ds_data_allowed?(dnssec_data, sg)
|
||||
ds_data_with_keys_allowed?(dnssec_data, sg)
|
||||
key_data_allowed?(dnssec_data, sg)
|
||||
def validate_dnssec_data(dnssec_data)
|
||||
ds_data_allowed?(dnssec_data)
|
||||
ds_data_with_keys_allowed?(dnssec_data)
|
||||
key_data_allowed?(dnssec_data)
|
||||
|
||||
errors.empty?
|
||||
end
|
||||
|
||||
def ds_data_allowed?(dnssec_data, sg)
|
||||
ds_data_allowed = sg.setting(Setting::ALLOW_DS_DATA).value == '0' ? false : true
|
||||
|
||||
return if (dnssec_data[:ds_data].any? && ds_data_allowed) || dnssec_data[:ds_data].empty?
|
||||
def ds_data_allowed?(dnssec_data)
|
||||
return if (dnssec_data[:ds_data].any? && Setting.ds_data_allowed) || dnssec_data[:ds_data].empty?
|
||||
errors.add(:base, :ds_data_not_allowed)
|
||||
end
|
||||
|
||||
def ds_data_with_keys_allowed?(dnssec_data, sg)
|
||||
ds_data_with_keys_allowed = sg.setting(Setting::ALLOW_DS_DATA_WITH_KEYS).value == '0' ? false : true
|
||||
|
||||
def ds_data_with_keys_allowed?(dnssec_data)
|
||||
dnssec_data[:ds_data].each do |ds_data|
|
||||
if key_data?(ds_data) && !ds_data_with_keys_allowed
|
||||
if key_data?(ds_data) && !Setting.ds_data_with_key_allowed
|
||||
errors.add(:base, :ds_data_with_key_not_allowed)
|
||||
return
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def key_data_allowed?(dnssec_data, sg)
|
||||
key_data_allowed = sg.setting(Setting::ALLOW_KEY_DATA).value == '0' ? false : true
|
||||
|
||||
return if (dnssec_data[:key_data].any? && key_data_allowed) || dnssec_data[:key_data].empty?
|
||||
def key_data_allowed?(dnssec_data)
|
||||
return if (dnssec_data[:key_data].any? && Setting.key_data_allowed) || dnssec_data[:key_data].empty?
|
||||
errors.add(:base, :key_data_not_allowed)
|
||||
end
|
||||
|
||||
|
@ -244,9 +235,7 @@ class Epp::EppDomain < Domain
|
|||
end
|
||||
|
||||
def detach_dnskeys(dnssec_data)
|
||||
sg = SettingGroup.dnskeys
|
||||
|
||||
return false unless validate_dnssec_data(dnssec_data, sg)
|
||||
return false unless validate_dnssec_data(dnssec_data)
|
||||
|
||||
to_delete = []
|
||||
dnssec_data[:ds_data].each do |x|
|
||||
|
@ -305,9 +294,7 @@ class Epp::EppDomain < Domain
|
|||
|
||||
return true if pt
|
||||
|
||||
wait_time = SettingGroup.domain_general.setting(:transfer_wait_time).value.to_i
|
||||
|
||||
if wait_time > 0
|
||||
if Setting.transfer_wait_time > 0
|
||||
domain_transfers.create(
|
||||
status: DomainTransfer::PENDING,
|
||||
transfer_requested_at: Time.zone.now,
|
||||
|
|
|
@ -1,14 +1,2 @@
|
|||
class Setting < ActiveRecord::Base
|
||||
belongs_to :setting_group
|
||||
has_many :domain_statuses
|
||||
has_many :domains, through: :domain_statuses
|
||||
validates :code, uniqueness: { scope: :setting_group_id }
|
||||
|
||||
# dnskeys
|
||||
DS_ALGORITHM = 'ds_algorithm'
|
||||
ALLOW_DS_DATA = 'allow_ds_data'
|
||||
ALLOW_DS_DATA_WITH_KEYS = 'allow_ds_data_with_keys'
|
||||
ALLOW_KEY_DATA = 'allow_key_data'
|
||||
DNSKEYS_MAX_COUNT = 'dnskeys_max_count'
|
||||
DNSKEYS_MIN_COUNT = 'dnskeys_min_count'
|
||||
class Setting < RailsSettings::CachedSettings
|
||||
end
|
||||
|
|
|
@ -1,25 +0,0 @@
|
|||
class SettingGroup < ActiveRecord::Base
|
||||
has_many :settings
|
||||
|
||||
accepts_nested_attributes_for :settings
|
||||
|
||||
validates :code, uniqueness: true
|
||||
|
||||
def setting(key)
|
||||
settings.find_by(code: key.to_s)
|
||||
end
|
||||
|
||||
class << self
|
||||
def domain_validation
|
||||
find_by(code: 'domain_validation')
|
||||
end
|
||||
|
||||
def domain_general
|
||||
find_by(code: 'domain_general')
|
||||
end
|
||||
|
||||
def dnskeys
|
||||
find_by(code: 'dnskeys')
|
||||
end
|
||||
end
|
||||
end
|
|
@ -261,9 +261,9 @@ en:
|
|||
ns_max_count: 'Nameserver maximum count'
|
||||
dnskeys_min_count: 'DNS keys minimum count'
|
||||
dnskeys_max_count: 'DNS keys maximum count'
|
||||
allow_ds_data: 'Allow DS data'
|
||||
allow_ds_data_with_keys: 'Allow DS data with keys'
|
||||
allow_key_data: 'Allow key data'
|
||||
ds_data_allowed: 'DS data allowed'
|
||||
ds_data_with_key_allowed: 'Allow DS data with key'
|
||||
key_data_allowed: 'Allow key data'
|
||||
ds_algorithm: 'DS algorithm'
|
||||
|
||||
shared:
|
||||
|
|
|
@ -1,9 +0,0 @@
|
|||
class CreateSettings < ActiveRecord::Migration
|
||||
def change
|
||||
create_table :settings do |t|
|
||||
t.integer :setting_group_id
|
||||
t.string :code
|
||||
t.string :value
|
||||
end
|
||||
end
|
||||
end
|
18
db/migrate/20141015135255_create_settings.rb
Normal file
18
db/migrate/20141015135255_create_settings.rb
Normal file
|
@ -0,0 +1,18 @@
|
|||
class CreateSettings < ActiveRecord::Migration
|
||||
def self.up
|
||||
drop_table :settings
|
||||
create_table :settings do |t|
|
||||
t.string :var, :null => false
|
||||
t.text :value, :null => true
|
||||
t.integer :thing_id, :null => true
|
||||
t.string :thing_type, :limit => 30, :null => true
|
||||
t.timestamps
|
||||
end
|
||||
|
||||
add_index :settings, [ :thing_type, :thing_id, :var ], :unique => true
|
||||
end
|
||||
|
||||
def self.down
|
||||
drop_table :settings
|
||||
end
|
||||
end
|
17
db/migrate/20141015135742_correct_settings.rb
Normal file
17
db/migrate/20141015135742_correct_settings.rb
Normal file
|
@ -0,0 +1,17 @@
|
|||
class CorrectSettings < ActiveRecord::Migration
|
||||
def up
|
||||
drop_table :setting_groups
|
||||
|
||||
Setting.ds_algorithm = 2
|
||||
Setting.ds_data_allowed = true
|
||||
Setting.ds_data_with_key_allowed = true
|
||||
Setting.key_data_allowed = true
|
||||
|
||||
Setting.dnskeys_min_count = 0
|
||||
Setting.dnskeys_max_count = 9
|
||||
Setting.ns_min_count = 2
|
||||
Setting.ns_max_count = 11
|
||||
|
||||
Setting.transfer_wait_time = 0
|
||||
end
|
||||
end
|
17
db/schema.rb
17
db/schema.rb
|
@ -11,7 +11,7 @@
|
|||
#
|
||||
# It's strongly recommended that you check this file into your version control system.
|
||||
|
||||
ActiveRecord::Schema.define(version: 20141014073435) do
|
||||
ActiveRecord::Schema.define(version: 20141015135742) do
|
||||
|
||||
# These are extensions that must be enabled in order to support this database
|
||||
enable_extension "plpgsql"
|
||||
|
@ -252,15 +252,16 @@ ActiveRecord::Schema.define(version: 20141014073435) do
|
|||
t.datetime "updated_at"
|
||||
end
|
||||
|
||||
create_table "setting_groups", force: true do |t|
|
||||
t.string "code"
|
||||
create_table "settings", force: true do |t|
|
||||
t.string "var", null: false
|
||||
t.text "value"
|
||||
t.integer "thing_id"
|
||||
t.string "thing_type", limit: 30
|
||||
t.datetime "created_at"
|
||||
t.datetime "updated_at"
|
||||
end
|
||||
|
||||
create_table "settings", force: true do |t|
|
||||
t.integer "setting_group_id"
|
||||
t.string "code"
|
||||
t.string "value"
|
||||
end
|
||||
add_index "settings", ["thing_type", "thing_id", "var"], name: "index_settings_on_thing_type_and_thing_id_and_var", unique: true, using: :btree
|
||||
|
||||
create_table "users", force: true do |t|
|
||||
t.string "username"
|
||||
|
|
31
db/seeds.rb
31
db/seeds.rb
|
@ -66,27 +66,16 @@ User.where(
|
|||
country: Country.where(name: 'Estonia').first
|
||||
).first_or_create
|
||||
|
||||
sg = SettingGroup.where(code: 'domain_validation').first_or_create
|
||||
Setting.destroy_all
|
||||
|
||||
s_1 = Setting.where(code: 'ns_min_count').first_or_create
|
||||
s_1.value = 1
|
||||
Setting.create(code: Setting::DS_ALGORITHM, value: 2)
|
||||
Setting.create(code: Setting::ALLOW_DS_DATA, value: 1)
|
||||
Setting.create(code: Setting::ALLOW_DS_DATA_WITH_KEY, value: 1)
|
||||
Setting.create(code: Setting::ALLOW_KEY_DATA, value: 1)
|
||||
|
||||
s_2 = Setting.where(code: 'ns_max_count').first_or_create
|
||||
s_2.value = 13
|
||||
Setting.create(code: Setting::DNSKEYS_MIN_COUNT, value: 9)
|
||||
Setting.create(code: Setting::DNSKEYS_MAX_COUNT, value: 0)
|
||||
Setting.create(code: Setting::NS_MIN_COUNT, value: 2)
|
||||
Setting.create(code: Setting::NS_MAX_COUNT, value: 11)
|
||||
|
||||
s_3 = Setting.where(code: 'dnskeys_min_count').first_or_create
|
||||
s_3.value = 0
|
||||
|
||||
s_4 = Setting.where(code: 'dnskeys_max_count').first_or_create
|
||||
s_4.value = 9
|
||||
|
||||
sg.settings = [s_1, s_2, s_3, s_4]
|
||||
sg.save
|
||||
|
||||
sg = SettingGroup.where(code: 'domain_general').first_or_create
|
||||
|
||||
s_1 = Setting.where(code: 'transfer_wait_time').first_or_create
|
||||
s_1.value = 0
|
||||
|
||||
sg.settings = [s_1]
|
||||
sg.save
|
||||
Setting.create(code: Setting::TRANSFER_WAIT_TIME, value: 0)
|
||||
|
|
|
@ -11,8 +11,7 @@ describe 'EPP Contact', epp: true do
|
|||
Fabricate(:epp_user)
|
||||
Fabricate(:epp_user, username: 'zone', registrar: zone)
|
||||
Fabricate(:epp_user, username: 'elkdata', registrar: elkdata)
|
||||
Fabricate(:domain_validation_setting_group)
|
||||
Fabricate(:dnskeys_setting_group)
|
||||
create_settings
|
||||
end
|
||||
|
||||
context 'create command' do
|
||||
|
|
|
@ -6,14 +6,12 @@ describe 'EPP Domain', epp: true do
|
|||
let(:elkdata) { Fabricate(:registrar, { name: 'Elkdata', reg_no: '123' }) }
|
||||
let(:zone) { Fabricate(:registrar) }
|
||||
|
||||
before(:each) { create_settings }
|
||||
|
||||
context 'with valid user' do
|
||||
before(:each) do
|
||||
Fabricate(:epp_user, username: 'zone', registrar: zone)
|
||||
Fabricate(:epp_user, username: 'elkdata', registrar: elkdata)
|
||||
|
||||
Fabricate(:domain_validation_setting_group)
|
||||
Fabricate(:domain_statuses_setting_group)
|
||||
Fabricate(:dnskeys_setting_group)
|
||||
end
|
||||
|
||||
it 'returns error if contact does not exists' do
|
||||
|
@ -36,7 +34,6 @@ describe 'EPP Domain', epp: true do
|
|||
let(:domain) { Domain.first }
|
||||
|
||||
before(:each) do
|
||||
Fabricate(:domain_general_setting_group)
|
||||
Fabricate(:domain, name: 'example.ee', registrar: zone)
|
||||
end
|
||||
|
||||
|
@ -65,8 +62,7 @@ describe 'EPP Domain', epp: true do
|
|||
|
||||
expect(domain.registrar).to eq(elkdata)
|
||||
|
||||
s = Setting.find_by(code: 'transfer_wait_time')
|
||||
s.update(value: 1)
|
||||
Setting.transfer_wait_time = 1
|
||||
|
||||
domain.reload
|
||||
pw = domain.auth_info
|
||||
|
@ -209,8 +205,8 @@ describe 'EPP Domain', epp: true do
|
|||
|
||||
expect(key.ds_alg).to eq(3)
|
||||
expect(key.ds_key_tag).to_not be_blank
|
||||
sg = SettingGroup.dnskeys
|
||||
expect(key.ds_digest_type).to eq(sg.setting(Setting::DS_ALGORITHM).value.to_i)
|
||||
|
||||
expect(key.ds_digest_type).to eq(Setting.ds_algorithm)
|
||||
expect(key.flags).to eq(257)
|
||||
expect(key.protocol).to eq(3)
|
||||
expect(key.alg).to eq(5)
|
||||
|
@ -297,7 +293,7 @@ describe 'EPP Domain', epp: true do
|
|||
|
||||
response = epp_request(xml, :xml)
|
||||
expect(response[:result_code]).to eq('2004')
|
||||
expect(response[:msg]).to eq('Nameservers count must be between 1-13')
|
||||
expect(response[:msg]).to eq('Nameservers count must be between 2-11')
|
||||
end
|
||||
|
||||
it 'returns error when invalid nameservers are present' do
|
||||
|
@ -391,7 +387,7 @@ describe 'EPP Domain', epp: true do
|
|||
key_1 = d.dnskeys[0]
|
||||
expect(key_1.ds_key_tag).to_not be_blank
|
||||
expect(key_1.ds_alg).to eq(3)
|
||||
expect(key_1.ds_digest_type).to eq(SettingGroup.dnskeys.setting(Setting::DS_ALGORITHM).value.to_i)
|
||||
expect(key_1.ds_digest_type).to eq(Setting.ds_algorithm)
|
||||
|
||||
expect(d.dnskeys.pluck(:flags)).to match_array([257, 0, 256])
|
||||
expect(d.dnskeys.pluck(:protocol)).to match_array([3, 3, 3])
|
||||
|
@ -484,9 +480,7 @@ describe 'EPP Domain', epp: true do
|
|||
end
|
||||
|
||||
it 'validated dnskeys count' do
|
||||
s = Setting.find_by(code: 'dnskeys_max_count')
|
||||
s.value = 1
|
||||
s.save
|
||||
Setting.dnskeys_max_count = 1
|
||||
|
||||
xml = domain_create_xml({}, {
|
||||
_other: [
|
||||
|
@ -572,10 +566,7 @@ describe 'EPP Domain', epp: true do
|
|||
end
|
||||
|
||||
it 'prohibits dsData with key' do
|
||||
sg = SettingGroup.dnskeys
|
||||
s = sg.setting(Setting::ALLOW_DS_DATA_WITH_KEYS)
|
||||
s.value = 0
|
||||
s.save
|
||||
Setting.ds_data_with_key_allowed = false
|
||||
|
||||
xml = domain_create_xml({}, {
|
||||
_other: [
|
||||
|
@ -600,10 +591,7 @@ describe 'EPP Domain', epp: true do
|
|||
end
|
||||
|
||||
it 'prohibits dsData' do
|
||||
sg = SettingGroup.dnskeys
|
||||
s = sg.setting(Setting::ALLOW_DS_DATA)
|
||||
s.value = 0
|
||||
s.save
|
||||
Setting.ds_data_allowed = false
|
||||
|
||||
xml = domain_create_xml({}, {
|
||||
_other: [
|
||||
|
@ -628,10 +616,7 @@ describe 'EPP Domain', epp: true do
|
|||
end
|
||||
|
||||
it 'prohibits keyData' do
|
||||
sg = SettingGroup.dnskeys
|
||||
s = sg.setting(Setting::ALLOW_KEY_DATA)
|
||||
s.value = 0
|
||||
s.save
|
||||
Setting.key_data_allowed = false
|
||||
|
||||
xml = domain_create_xml({}, {
|
||||
_other: [
|
||||
|
|
|
@ -1,3 +0,0 @@
|
|||
Fabricator(:setting) do
|
||||
code 'ns_min_count'
|
||||
end
|
|
@ -1,52 +0,0 @@
|
|||
Fabricator(:setting_group) do
|
||||
code 'domain_validation'
|
||||
settings do
|
||||
[
|
||||
Fabricate(:setting, code: 'ns_min_count', value: 1),
|
||||
Fabricate(:setting, code: 'ns_max_count', value: 13)
|
||||
]
|
||||
end
|
||||
end
|
||||
|
||||
Fabricator(:domain_validation_setting_group, from: :setting_group) do
|
||||
code 'domain_validation'
|
||||
settings do
|
||||
[
|
||||
Fabricate(:setting, code: 'ns_min_count', value: 1),
|
||||
Fabricate(:setting, code: 'ns_max_count', value: 13),
|
||||
Fabricate(:setting, code: 'dnskeys_min_count', value: 0),
|
||||
Fabricate(:setting, code: 'dnskeys_max_count', value: 9)
|
||||
]
|
||||
end
|
||||
end
|
||||
|
||||
Fabricator(:domain_statuses_setting_group, from: :setting_group) do
|
||||
code 'domain_statuses'
|
||||
settings do
|
||||
[
|
||||
Fabricate(:setting, code: 'client_hold', value: 'clientHold'),
|
||||
Fabricate(:setting, code: 'client_update_prohibited', value: 'clientUpdateProhibited')
|
||||
]
|
||||
end
|
||||
end
|
||||
|
||||
Fabricator(:domain_general_setting_group, from: :setting_group) do
|
||||
code 'domain_general'
|
||||
settings do
|
||||
[
|
||||
Fabricate(:setting, code: 'transfer_wait_time', value: '0')
|
||||
]
|
||||
end
|
||||
end
|
||||
|
||||
Fabricator(:dnskeys_setting_group, from: :setting_group) do
|
||||
code 'dnskeys'
|
||||
settings do
|
||||
[
|
||||
Fabricate(:setting, code: Setting::DS_ALGORITHM, value: 2),
|
||||
Fabricate(:setting, code: Setting::ALLOW_DS_DATA, value: 1),
|
||||
Fabricate(:setting, code: Setting::ALLOW_DS_DATA_WITH_KEYS, value: 1),
|
||||
Fabricate(:setting, code: Setting::ALLOW_KEY_DATA, value: 1)
|
||||
]
|
||||
end
|
||||
end
|
|
@ -50,8 +50,7 @@ describe Contact, '#relations_with_domain?' do
|
|||
|
||||
context 'with relation' do
|
||||
before(:each) do
|
||||
Fabricate(:domain_validation_setting_group)
|
||||
Fabricate(:dnskeys_setting_group)
|
||||
create_settings
|
||||
Fabricate(:domain)
|
||||
end
|
||||
|
||||
|
|
|
@ -2,8 +2,7 @@ require 'rails_helper'
|
|||
|
||||
describe Dnskey do
|
||||
before(:each) do
|
||||
Fabricate(:domain_validation_setting_group)
|
||||
Fabricate(:dnskeys_setting_group)
|
||||
create_settings
|
||||
end
|
||||
|
||||
it { should belong_to(:domain) }
|
||||
|
|
|
@ -11,8 +11,7 @@ describe Domain do
|
|||
|
||||
context 'with sufficient settings' do
|
||||
before(:each) do
|
||||
Fabricate(:domain_validation_setting_group)
|
||||
Fabricate(:dnskeys_setting_group)
|
||||
create_settings
|
||||
end
|
||||
|
||||
it 'validates domain name' do
|
||||
|
@ -51,20 +50,13 @@ describe Domain do
|
|||
period: ['is not a number'],
|
||||
owner_contact: ['Registrant is missing'],
|
||||
admin_contacts: ['Admin contacts count must be between 1 - infinity'],
|
||||
nameservers: ['Nameservers count must be between 1-13'],
|
||||
nameservers: ['Nameservers count must be between 2-11'],
|
||||
registrar: ['Registrar is missing'],
|
||||
period: ['Period is not a number']
|
||||
})
|
||||
|
||||
sg = SettingGroup.domain_validation
|
||||
min = sg.setting(:ns_min_count)
|
||||
max = sg.setting(:ns_max_count)
|
||||
|
||||
min.value = 2
|
||||
min.save
|
||||
|
||||
max.value = 7
|
||||
max.save
|
||||
Setting.ns_min_count = 2
|
||||
Setting.ns_max_count = 7
|
||||
|
||||
expect(d.valid?).to be false
|
||||
expect(d.errors.messages[:nameservers]).to eq(['Nameservers count must be between 2-7'])
|
||||
|
|
|
@ -1,5 +0,0 @@
|
|||
require 'rails_helper'
|
||||
|
||||
describe SettingGroup do
|
||||
it { should have_many(:settings) }
|
||||
end
|
|
@ -1,21 +1,12 @@
|
|||
require 'rails_helper'
|
||||
|
||||
describe Setting do
|
||||
it { should belong_to(:setting_group) }
|
||||
|
||||
it 'validates code uniqueness' do
|
||||
sg = Fabricate(:setting_group)
|
||||
sg.settings.build(code: 'this_is_code')
|
||||
expect(sg.save).to be true
|
||||
|
||||
sg.settings.build(code: 'this_is_code')
|
||||
expect(sg.save).to be false
|
||||
err = sg.settings.last.errors[:code].first
|
||||
expect(err).to eq('Code already exists')
|
||||
|
||||
sg_2 = Fabricate(:setting_group, code: 'domain_statuses')
|
||||
|
||||
sg_2.settings.build(code: 'this_is_code')
|
||||
expect(sg_2.save).to be true
|
||||
it 'returns value' do
|
||||
create_settings
|
||||
expect(Setting.ns_min_count).to eq(2)
|
||||
Setting.ns_min_count = '2'
|
||||
expect(Setting.ns_min_count).to eq('2')
|
||||
Setting.ns_min_count = true
|
||||
expect(Setting.ns_min_count).to eq(true)
|
||||
end
|
||||
end
|
||||
|
|
20
spec/support/general.rb
Normal file
20
spec/support/general.rb
Normal file
|
@ -0,0 +1,20 @@
|
|||
module General
|
||||
def create_settings
|
||||
Setting.ds_algorithm = 2
|
||||
Setting.ds_data_allowed = true
|
||||
Setting.ds_data_with_key_allowed = true
|
||||
Setting.key_data_allowed = true
|
||||
|
||||
Setting.dnskeys_min_count = 0
|
||||
Setting.dnskeys_max_count = 9
|
||||
Setting.ns_min_count = 2
|
||||
Setting.ns_max_count = 11
|
||||
|
||||
Setting.transfer_wait_time = 0
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
RSpec.configure do |c|
|
||||
c.include General
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue