mirror of
https://github.com/internetee/registry.git
synced 2025-05-16 17:37:17 +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
|
# See https://github.com/sstephenson/execjs#readme for more supported runtimes
|
||||||
gem 'therubyracer', platforms: :ruby
|
gem 'therubyracer', platforms: :ruby
|
||||||
|
|
||||||
|
# for settings
|
||||||
|
gem "rails-settings-cached", '0.4.1'
|
||||||
|
|
||||||
group :development, :test do
|
group :development, :test do
|
||||||
gem 'capybara', '~> 2.4.1'
|
gem 'capybara', '~> 2.4.1'
|
||||||
# For feature testing
|
# For feature testing
|
||||||
|
|
|
@ -200,6 +200,8 @@ GEM
|
||||||
bundler (>= 1.3.0, < 2.0)
|
bundler (>= 1.3.0, < 2.0)
|
||||||
railties (= 4.1.4)
|
railties (= 4.1.4)
|
||||||
sprockets-rails (~> 2.0)
|
sprockets-rails (~> 2.0)
|
||||||
|
rails-settings-cached (0.4.1)
|
||||||
|
rails (>= 4.0.0)
|
||||||
railties (4.1.4)
|
railties (4.1.4)
|
||||||
actionpack (= 4.1.4)
|
actionpack (= 4.1.4)
|
||||||
activesupport (= 4.1.4)
|
activesupport (= 4.1.4)
|
||||||
|
@ -376,6 +378,7 @@ DEPENDENCIES
|
||||||
poltergeist (~> 1.5.1)
|
poltergeist (~> 1.5.1)
|
||||||
pry (~> 0.10.1)
|
pry (~> 0.10.1)
|
||||||
rails (= 4.1.4)
|
rails (= 4.1.4)
|
||||||
|
rails-settings-cached (= 0.4.1)
|
||||||
ransack (~> 1.3.0)
|
ransack (~> 1.3.0)
|
||||||
rspec-rails (~> 3.0.2)
|
rspec-rails (~> 3.0.2)
|
||||||
rubocop (~> 0.26.1)
|
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
|
hex = [domain.name_in_wire_format, flags_hex, protocol_hex, alg_hex, public_key_hex].join
|
||||||
bin = self.class.hex_to_bin(hex)
|
bin = self.class.hex_to_bin(hex)
|
||||||
|
|
||||||
sg = SettingGroup.dnskeys.setting(Setting::DS_ALGORITHM).value
|
if Setting.ds_algorithm == 1
|
||||||
|
|
||||||
if sg == '1'
|
|
||||||
self.ds_digest = Digest::SHA1.hexdigest(bin).upcase
|
self.ds_digest = Digest::SHA1.hexdigest(bin).upcase
|
||||||
elsif sg == '2'
|
elsif Setting.ds_algorithm == 2
|
||||||
self.ds_digest = Digest::SHA256.hexdigest(bin).upcase
|
self.ds_digest = Digest::SHA256.hexdigest(bin).upcase
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -85,9 +85,7 @@ class Domain < ActiveRecord::Base
|
||||||
|
|
||||||
### VALIDATIONS ###
|
### VALIDATIONS ###
|
||||||
def validate_nameservers_count
|
def validate_nameservers_count
|
||||||
sg = SettingGroup.domain_validation
|
min, max = Setting.ns_min_count, Setting.ns_max_count
|
||||||
min, max = sg.setting(:ns_min_count).value.to_i, sg.setting(:ns_max_count).value.to_i
|
|
||||||
|
|
||||||
return if nameservers.reject(&:marked_for_destruction?).length.between?(min, max)
|
return if nameservers.reject(&:marked_for_destruction?).length.between?(min, max)
|
||||||
errors.add(:nameservers, :out_of_range, { min: min, max: max })
|
errors.add(:nameservers, :out_of_range, { min: min, max: max })
|
||||||
end
|
end
|
||||||
|
@ -97,8 +95,7 @@ class Domain < ActiveRecord::Base
|
||||||
end
|
end
|
||||||
|
|
||||||
def validate_dnskeys_count
|
def validate_dnskeys_count
|
||||||
sg = SettingGroup.domain_validation
|
min, max = Setting.dnskeys_min_count, Setting.dnskeys_max_count
|
||||||
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)
|
return if dnskeys.reject(&:marked_for_destruction?).length.between?(min, max)
|
||||||
errors.add(:dnskeys, :out_of_range, { min: min, max: max })
|
errors.add(:dnskeys, :out_of_range, { min: min, max: max })
|
||||||
end
|
end
|
||||||
|
|
|
@ -14,7 +14,7 @@ class DomainTransfer < ActiveRecord::Base
|
||||||
before_create :set_wait_until
|
before_create :set_wait_until
|
||||||
|
|
||||||
def 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
|
return if wait_time == 0
|
||||||
self.wait_until = transfer_requested_at + wait_time.hours
|
self.wait_until = transfer_requested_at + wait_time.hours
|
||||||
end
|
end
|
||||||
|
|
|
@ -6,8 +6,6 @@ class Epp::EppDomain < Domain
|
||||||
validate :validate_admin_contacts_count
|
validate :validate_admin_contacts_count
|
||||||
|
|
||||||
def epp_code_map # rubocop:disable Metrics/MethodLength
|
def epp_code_map # rubocop:disable Metrics/MethodLength
|
||||||
domain_validation_sg = SettingGroup.domain_validation
|
|
||||||
|
|
||||||
{
|
{
|
||||||
'2002' => [
|
'2002' => [
|
||||||
[:base, :domain_already_belongs_to_the_querying_registrar]
|
[:base, :domain_already_belongs_to_the_querying_registrar]
|
||||||
|
@ -29,15 +27,15 @@ class Epp::EppDomain < Domain
|
||||||
'2004' => [ # Parameter value range error
|
'2004' => [ # Parameter value range error
|
||||||
[:nameservers, :out_of_range,
|
[:nameservers, :out_of_range,
|
||||||
{
|
{
|
||||||
min: domain_validation_sg.setting(:ns_min_count).value,
|
min: Setting.ns_min_count,
|
||||||
max: domain_validation_sg.setting(:ns_max_count).value
|
max: Setting.ns_max_count
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
[:period, :out_of_range, { value: { obj: 'period', val: period } }],
|
[:period, :out_of_range, { value: { obj: 'period', val: period } }],
|
||||||
[:dnskeys, :out_of_range,
|
[:dnskeys, :out_of_range,
|
||||||
{
|
{
|
||||||
min: domain_validation_sg.setting(Setting::DNSKEYS_MIN_COUNT).value,
|
min: Setting.dnskeys_min_count,
|
||||||
max: domain_validation_sg.setting(Setting::DNSKEYS_MAX_COUNT).value
|
max: Setting.dnskeys_max_count
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
],
|
],
|
||||||
|
@ -189,8 +187,7 @@ class Epp::EppDomain < Domain
|
||||||
end
|
end
|
||||||
|
|
||||||
def attach_dnskeys(dnssec_data)
|
def attach_dnskeys(dnssec_data)
|
||||||
sg = SettingGroup.dnskeys
|
return false unless validate_dnssec_data(dnssec_data)
|
||||||
return false unless validate_dnssec_data(dnssec_data, sg)
|
|
||||||
|
|
||||||
dnssec_data[:ds_data].each do |ds_data|
|
dnssec_data[:ds_data].each do |ds_data|
|
||||||
dnskeys.build(ds_data)
|
dnskeys.build(ds_data)
|
||||||
|
@ -200,41 +197,35 @@ class Epp::EppDomain < Domain
|
||||||
dnskeys.build({
|
dnskeys.build({
|
||||||
ds_key_tag: SecureRandom.hex(5),
|
ds_key_tag: SecureRandom.hex(5),
|
||||||
ds_alg: 3,
|
ds_alg: 3,
|
||||||
ds_digest_type: sg.setting(Setting::DS_ALGORITHM).value
|
ds_digest_type: Setting.ds_algorithm
|
||||||
}.merge(x))
|
}.merge(x))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def validate_dnssec_data(dnssec_data, sg)
|
def validate_dnssec_data(dnssec_data)
|
||||||
ds_data_allowed?(dnssec_data, sg)
|
ds_data_allowed?(dnssec_data)
|
||||||
ds_data_with_keys_allowed?(dnssec_data, sg)
|
ds_data_with_keys_allowed?(dnssec_data)
|
||||||
key_data_allowed?(dnssec_data, sg)
|
key_data_allowed?(dnssec_data)
|
||||||
|
|
||||||
errors.empty?
|
errors.empty?
|
||||||
end
|
end
|
||||||
|
|
||||||
def ds_data_allowed?(dnssec_data, sg)
|
def ds_data_allowed?(dnssec_data)
|
||||||
ds_data_allowed = sg.setting(Setting::ALLOW_DS_DATA).value == '0' ? false : true
|
return if (dnssec_data[:ds_data].any? && Setting.ds_data_allowed) || dnssec_data[:ds_data].empty?
|
||||||
|
|
||||||
return if (dnssec_data[:ds_data].any? && ds_data_allowed) || dnssec_data[:ds_data].empty?
|
|
||||||
errors.add(:base, :ds_data_not_allowed)
|
errors.add(:base, :ds_data_not_allowed)
|
||||||
end
|
end
|
||||||
|
|
||||||
def ds_data_with_keys_allowed?(dnssec_data, sg)
|
def ds_data_with_keys_allowed?(dnssec_data)
|
||||||
ds_data_with_keys_allowed = sg.setting(Setting::ALLOW_DS_DATA_WITH_KEYS).value == '0' ? false : true
|
|
||||||
|
|
||||||
dnssec_data[:ds_data].each do |ds_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)
|
errors.add(:base, :ds_data_with_key_not_allowed)
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def key_data_allowed?(dnssec_data, sg)
|
def key_data_allowed?(dnssec_data)
|
||||||
key_data_allowed = sg.setting(Setting::ALLOW_KEY_DATA).value == '0' ? false : true
|
return if (dnssec_data[:key_data].any? && Setting.key_data_allowed) || dnssec_data[:key_data].empty?
|
||||||
|
|
||||||
return if (dnssec_data[:key_data].any? && key_data_allowed) || dnssec_data[:key_data].empty?
|
|
||||||
errors.add(:base, :key_data_not_allowed)
|
errors.add(:base, :key_data_not_allowed)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -244,9 +235,7 @@ class Epp::EppDomain < Domain
|
||||||
end
|
end
|
||||||
|
|
||||||
def detach_dnskeys(dnssec_data)
|
def detach_dnskeys(dnssec_data)
|
||||||
sg = SettingGroup.dnskeys
|
return false unless validate_dnssec_data(dnssec_data)
|
||||||
|
|
||||||
return false unless validate_dnssec_data(dnssec_data, sg)
|
|
||||||
|
|
||||||
to_delete = []
|
to_delete = []
|
||||||
dnssec_data[:ds_data].each do |x|
|
dnssec_data[:ds_data].each do |x|
|
||||||
|
@ -305,9 +294,7 @@ class Epp::EppDomain < Domain
|
||||||
|
|
||||||
return true if pt
|
return true if pt
|
||||||
|
|
||||||
wait_time = SettingGroup.domain_general.setting(:transfer_wait_time).value.to_i
|
if Setting.transfer_wait_time > 0
|
||||||
|
|
||||||
if wait_time > 0
|
|
||||||
domain_transfers.create(
|
domain_transfers.create(
|
||||||
status: DomainTransfer::PENDING,
|
status: DomainTransfer::PENDING,
|
||||||
transfer_requested_at: Time.zone.now,
|
transfer_requested_at: Time.zone.now,
|
||||||
|
|
|
@ -1,14 +1,2 @@
|
||||||
class Setting < ActiveRecord::Base
|
class Setting < RailsSettings::CachedSettings
|
||||||
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'
|
|
||||||
end
|
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'
|
ns_max_count: 'Nameserver maximum count'
|
||||||
dnskeys_min_count: 'DNS keys minimum count'
|
dnskeys_min_count: 'DNS keys minimum count'
|
||||||
dnskeys_max_count: 'DNS keys maximum count'
|
dnskeys_max_count: 'DNS keys maximum count'
|
||||||
allow_ds_data: 'Allow DS data'
|
ds_data_allowed: 'DS data allowed'
|
||||||
allow_ds_data_with_keys: 'Allow DS data with keys'
|
ds_data_with_key_allowed: 'Allow DS data with key'
|
||||||
allow_key_data: 'Allow key data'
|
key_data_allowed: 'Allow key data'
|
||||||
ds_algorithm: 'DS algorithm'
|
ds_algorithm: 'DS algorithm'
|
||||||
|
|
||||||
shared:
|
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.
|
# 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
|
# These are extensions that must be enabled in order to support this database
|
||||||
enable_extension "plpgsql"
|
enable_extension "plpgsql"
|
||||||
|
@ -252,15 +252,16 @@ ActiveRecord::Schema.define(version: 20141014073435) do
|
||||||
t.datetime "updated_at"
|
t.datetime "updated_at"
|
||||||
end
|
end
|
||||||
|
|
||||||
create_table "setting_groups", force: true do |t|
|
create_table "settings", force: true do |t|
|
||||||
t.string "code"
|
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
|
end
|
||||||
|
|
||||||
create_table "settings", force: true do |t|
|
add_index "settings", ["thing_type", "thing_id", "var"], name: "index_settings_on_thing_type_and_thing_id_and_var", unique: true, using: :btree
|
||||||
t.integer "setting_group_id"
|
|
||||||
t.string "code"
|
|
||||||
t.string "value"
|
|
||||||
end
|
|
||||||
|
|
||||||
create_table "users", force: true do |t|
|
create_table "users", force: true do |t|
|
||||||
t.string "username"
|
t.string "username"
|
||||||
|
|
31
db/seeds.rb
31
db/seeds.rb
|
@ -66,27 +66,16 @@ User.where(
|
||||||
country: Country.where(name: 'Estonia').first
|
country: Country.where(name: 'Estonia').first
|
||||||
).first_or_create
|
).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
|
Setting.create(code: Setting::DS_ALGORITHM, value: 2)
|
||||||
s_1.value = 1
|
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
|
Setting.create(code: Setting::DNSKEYS_MIN_COUNT, value: 9)
|
||||||
s_2.value = 13
|
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
|
Setting.create(code: Setting::TRANSFER_WAIT_TIME, value: 0)
|
||||||
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
|
|
||||||
|
|
|
@ -11,8 +11,7 @@ describe 'EPP Contact', epp: true do
|
||||||
Fabricate(:epp_user)
|
Fabricate(:epp_user)
|
||||||
Fabricate(:epp_user, username: 'zone', registrar: zone)
|
Fabricate(:epp_user, username: 'zone', registrar: zone)
|
||||||
Fabricate(:epp_user, username: 'elkdata', registrar: elkdata)
|
Fabricate(:epp_user, username: 'elkdata', registrar: elkdata)
|
||||||
Fabricate(:domain_validation_setting_group)
|
create_settings
|
||||||
Fabricate(:dnskeys_setting_group)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'create command' do
|
context 'create command' do
|
||||||
|
|
|
@ -6,14 +6,12 @@ describe 'EPP Domain', epp: true do
|
||||||
let(:elkdata) { Fabricate(:registrar, { name: 'Elkdata', reg_no: '123' }) }
|
let(:elkdata) { Fabricate(:registrar, { name: 'Elkdata', reg_no: '123' }) }
|
||||||
let(:zone) { Fabricate(:registrar) }
|
let(:zone) { Fabricate(:registrar) }
|
||||||
|
|
||||||
|
before(:each) { create_settings }
|
||||||
|
|
||||||
context 'with valid user' do
|
context 'with valid user' do
|
||||||
before(:each) do
|
before(:each) do
|
||||||
Fabricate(:epp_user, username: 'zone', registrar: zone)
|
Fabricate(:epp_user, username: 'zone', registrar: zone)
|
||||||
Fabricate(:epp_user, username: 'elkdata', registrar: elkdata)
|
Fabricate(:epp_user, username: 'elkdata', registrar: elkdata)
|
||||||
|
|
||||||
Fabricate(:domain_validation_setting_group)
|
|
||||||
Fabricate(:domain_statuses_setting_group)
|
|
||||||
Fabricate(:dnskeys_setting_group)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'returns error if contact does not exists' do
|
it 'returns error if contact does not exists' do
|
||||||
|
@ -36,7 +34,6 @@ describe 'EPP Domain', epp: true do
|
||||||
let(:domain) { Domain.first }
|
let(:domain) { Domain.first }
|
||||||
|
|
||||||
before(:each) do
|
before(:each) do
|
||||||
Fabricate(:domain_general_setting_group)
|
|
||||||
Fabricate(:domain, name: 'example.ee', registrar: zone)
|
Fabricate(:domain, name: 'example.ee', registrar: zone)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -65,8 +62,7 @@ describe 'EPP Domain', epp: true do
|
||||||
|
|
||||||
expect(domain.registrar).to eq(elkdata)
|
expect(domain.registrar).to eq(elkdata)
|
||||||
|
|
||||||
s = Setting.find_by(code: 'transfer_wait_time')
|
Setting.transfer_wait_time = 1
|
||||||
s.update(value: 1)
|
|
||||||
|
|
||||||
domain.reload
|
domain.reload
|
||||||
pw = domain.auth_info
|
pw = domain.auth_info
|
||||||
|
@ -209,8 +205,8 @@ describe 'EPP Domain', epp: true do
|
||||||
|
|
||||||
expect(key.ds_alg).to eq(3)
|
expect(key.ds_alg).to eq(3)
|
||||||
expect(key.ds_key_tag).to_not be_blank
|
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.flags).to eq(257)
|
||||||
expect(key.protocol).to eq(3)
|
expect(key.protocol).to eq(3)
|
||||||
expect(key.alg).to eq(5)
|
expect(key.alg).to eq(5)
|
||||||
|
@ -297,7 +293,7 @@ describe 'EPP Domain', epp: true do
|
||||||
|
|
||||||
response = epp_request(xml, :xml)
|
response = epp_request(xml, :xml)
|
||||||
expect(response[:result_code]).to eq('2004')
|
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
|
end
|
||||||
|
|
||||||
it 'returns error when invalid nameservers are present' do
|
it 'returns error when invalid nameservers are present' do
|
||||||
|
@ -391,7 +387,7 @@ describe 'EPP Domain', epp: true do
|
||||||
key_1 = d.dnskeys[0]
|
key_1 = d.dnskeys[0]
|
||||||
expect(key_1.ds_key_tag).to_not be_blank
|
expect(key_1.ds_key_tag).to_not be_blank
|
||||||
expect(key_1.ds_alg).to eq(3)
|
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(:flags)).to match_array([257, 0, 256])
|
||||||
expect(d.dnskeys.pluck(:protocol)).to match_array([3, 3, 3])
|
expect(d.dnskeys.pluck(:protocol)).to match_array([3, 3, 3])
|
||||||
|
@ -484,9 +480,7 @@ describe 'EPP Domain', epp: true do
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'validated dnskeys count' do
|
it 'validated dnskeys count' do
|
||||||
s = Setting.find_by(code: 'dnskeys_max_count')
|
Setting.dnskeys_max_count = 1
|
||||||
s.value = 1
|
|
||||||
s.save
|
|
||||||
|
|
||||||
xml = domain_create_xml({}, {
|
xml = domain_create_xml({}, {
|
||||||
_other: [
|
_other: [
|
||||||
|
@ -572,10 +566,7 @@ describe 'EPP Domain', epp: true do
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'prohibits dsData with key' do
|
it 'prohibits dsData with key' do
|
||||||
sg = SettingGroup.dnskeys
|
Setting.ds_data_with_key_allowed = false
|
||||||
s = sg.setting(Setting::ALLOW_DS_DATA_WITH_KEYS)
|
|
||||||
s.value = 0
|
|
||||||
s.save
|
|
||||||
|
|
||||||
xml = domain_create_xml({}, {
|
xml = domain_create_xml({}, {
|
||||||
_other: [
|
_other: [
|
||||||
|
@ -600,10 +591,7 @@ describe 'EPP Domain', epp: true do
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'prohibits dsData' do
|
it 'prohibits dsData' do
|
||||||
sg = SettingGroup.dnskeys
|
Setting.ds_data_allowed = false
|
||||||
s = sg.setting(Setting::ALLOW_DS_DATA)
|
|
||||||
s.value = 0
|
|
||||||
s.save
|
|
||||||
|
|
||||||
xml = domain_create_xml({}, {
|
xml = domain_create_xml({}, {
|
||||||
_other: [
|
_other: [
|
||||||
|
@ -628,10 +616,7 @@ describe 'EPP Domain', epp: true do
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'prohibits keyData' do
|
it 'prohibits keyData' do
|
||||||
sg = SettingGroup.dnskeys
|
Setting.key_data_allowed = false
|
||||||
s = sg.setting(Setting::ALLOW_KEY_DATA)
|
|
||||||
s.value = 0
|
|
||||||
s.save
|
|
||||||
|
|
||||||
xml = domain_create_xml({}, {
|
xml = domain_create_xml({}, {
|
||||||
_other: [
|
_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
|
context 'with relation' do
|
||||||
before(:each) do
|
before(:each) do
|
||||||
Fabricate(:domain_validation_setting_group)
|
create_settings
|
||||||
Fabricate(:dnskeys_setting_group)
|
|
||||||
Fabricate(:domain)
|
Fabricate(:domain)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -2,8 +2,7 @@ require 'rails_helper'
|
||||||
|
|
||||||
describe Dnskey do
|
describe Dnskey do
|
||||||
before(:each) do
|
before(:each) do
|
||||||
Fabricate(:domain_validation_setting_group)
|
create_settings
|
||||||
Fabricate(:dnskeys_setting_group)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
it { should belong_to(:domain) }
|
it { should belong_to(:domain) }
|
||||||
|
|
|
@ -11,8 +11,7 @@ describe Domain do
|
||||||
|
|
||||||
context 'with sufficient settings' do
|
context 'with sufficient settings' do
|
||||||
before(:each) do
|
before(:each) do
|
||||||
Fabricate(:domain_validation_setting_group)
|
create_settings
|
||||||
Fabricate(:dnskeys_setting_group)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'validates domain name' do
|
it 'validates domain name' do
|
||||||
|
@ -51,20 +50,13 @@ describe Domain do
|
||||||
period: ['is not a number'],
|
period: ['is not a number'],
|
||||||
owner_contact: ['Registrant is missing'],
|
owner_contact: ['Registrant is missing'],
|
||||||
admin_contacts: ['Admin contacts count must be between 1 - infinity'],
|
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'],
|
registrar: ['Registrar is missing'],
|
||||||
period: ['Period is not a number']
|
period: ['Period is not a number']
|
||||||
})
|
})
|
||||||
|
|
||||||
sg = SettingGroup.domain_validation
|
Setting.ns_min_count = 2
|
||||||
min = sg.setting(:ns_min_count)
|
Setting.ns_max_count = 7
|
||||||
max = sg.setting(:ns_max_count)
|
|
||||||
|
|
||||||
min.value = 2
|
|
||||||
min.save
|
|
||||||
|
|
||||||
max.value = 7
|
|
||||||
max.save
|
|
||||||
|
|
||||||
expect(d.valid?).to be false
|
expect(d.valid?).to be false
|
||||||
expect(d.errors.messages[:nameservers]).to eq(['Nameservers count must be between 2-7'])
|
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'
|
require 'rails_helper'
|
||||||
|
|
||||||
describe Setting do
|
describe Setting do
|
||||||
it { should belong_to(:setting_group) }
|
it 'returns value' do
|
||||||
|
create_settings
|
||||||
it 'validates code uniqueness' do
|
expect(Setting.ns_min_count).to eq(2)
|
||||||
sg = Fabricate(:setting_group)
|
Setting.ns_min_count = '2'
|
||||||
sg.settings.build(code: 'this_is_code')
|
expect(Setting.ns_min_count).to eq('2')
|
||||||
expect(sg.save).to be true
|
Setting.ns_min_count = true
|
||||||
|
expect(Setting.ns_min_count).to eq(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
|
|
||||||
end
|
end
|
||||||
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