mirror of
https://github.com/internetee/registry.git
synced 2025-05-16 09:27:19 +02:00
Validate DNS keys count
This commit is contained in:
parent
9519538744
commit
39ebabf064
10 changed files with 70 additions and 9 deletions
|
@ -32,6 +32,10 @@ class Client::DomainsController < ClientController
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def show
|
||||||
|
@domain.all_dependencies_valid?
|
||||||
|
end
|
||||||
|
|
||||||
def edit
|
def edit
|
||||||
build_associations
|
build_associations
|
||||||
end
|
end
|
||||||
|
@ -70,7 +74,7 @@ class Client::DomainsController < ClientController
|
||||||
nameservers_attributes: [:id, :hostname, :ipv4, :ipv6, :_destroy],
|
nameservers_attributes: [:id, :hostname, :ipv4, :ipv6, :_destroy],
|
||||||
domain_contacts_attributes: [:id, :contact_type, :contact_id, :value_typeahead, :_destroy],
|
domain_contacts_attributes: [:id, :contact_type, :contact_id, :value_typeahead, :_destroy],
|
||||||
domain_statuses_attributes: [:id, :value, :description, :_destroy],
|
domain_statuses_attributes: [:id, :value, :description, :_destroy],
|
||||||
dnskeys_attributes: [:id, :flags, :alg, :protocol, :public_key]
|
dnskeys_attributes: [:id, :flags, :alg, :protocol, :public_key, :_destroy]
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -49,6 +49,7 @@ class Domain < ActiveRecord::Base
|
||||||
validate :validate_period
|
validate :validate_period
|
||||||
validate :validate_nameservers_count
|
validate :validate_nameservers_count
|
||||||
validate :validate_admin_contacts_count
|
validate :validate_admin_contacts_count
|
||||||
|
validate :validate_dnskeys_count
|
||||||
validate :validate_nameservers_uniqueness
|
validate :validate_nameservers_uniqueness
|
||||||
validate :validate_tech_contacts_uniqueness
|
validate :validate_tech_contacts_uniqueness
|
||||||
validate :validate_admin_contacts_uniqueness
|
validate :validate_admin_contacts_uniqueness
|
||||||
|
@ -95,6 +96,13 @@ class Domain < ActiveRecord::Base
|
||||||
errors.add(:admin_contacts, :out_of_range) if admin_contacts_count.zero?
|
errors.add(:admin_contacts, :out_of_range) if admin_contacts_count.zero?
|
||||||
end
|
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_nameservers_uniqueness
|
def validate_nameservers_uniqueness
|
||||||
validated = []
|
validated = []
|
||||||
nameservers.reject(&:marked_for_destruction?).each do |ns|
|
nameservers.reject(&:marked_for_destruction?).each do |ns|
|
||||||
|
@ -176,6 +184,7 @@ class Domain < ActiveRecord::Base
|
||||||
|
|
||||||
def all_dependencies_valid?
|
def all_dependencies_valid?
|
||||||
validate_nameservers_count
|
validate_nameservers_count
|
||||||
|
validate_dnskeys_count
|
||||||
validate_admin_contacts_count
|
validate_admin_contacts_count
|
||||||
|
|
||||||
errors.empty?
|
errors.empty?
|
||||||
|
|
|
@ -29,6 +29,12 @@ class Epp::EppDomain < Domain
|
||||||
max: domain_validation_sg.setting(:ns_max_count).value
|
max: domain_validation_sg.setting(:ns_max_count).value
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
|
[:dnskeys, :out_of_range,
|
||||||
|
{
|
||||||
|
min: domain_validation_sg.setting(:dnskeys_min_count).value,
|
||||||
|
max: domain_validation_sg.setting(:dnskeys_max_count).value
|
||||||
|
}
|
||||||
|
],
|
||||||
[:period, :out_of_range, { value: { obj: 'period', val: period } }]
|
[:period, :out_of_range, { value: { obj: 'period', val: period } }]
|
||||||
],
|
],
|
||||||
'2200' => [
|
'2200' => [
|
||||||
|
|
|
@ -1,5 +0,0 @@
|
||||||
class NsSet < ActiveRecord::Base
|
|
||||||
belongs_to :registrar
|
|
||||||
has_many :domains
|
|
||||||
has_and_belongs_to_many :nameservers
|
|
||||||
end
|
|
|
@ -14,7 +14,7 @@
|
||||||
.row
|
.row
|
||||||
.col-md-4
|
.col-md-4
|
||||||
.form-group
|
.form-group
|
||||||
= key_fields.label :flags, t('shared.flag')
|
= key_fields.label :flags
|
||||||
= key_fields.text_field :flags, class: 'form-control'
|
= key_fields.text_field :flags, class: 'form-control'
|
||||||
.col-md-4
|
.col-md-4
|
||||||
.form-group
|
.form-group
|
||||||
|
|
|
@ -109,6 +109,7 @@ en:
|
||||||
dnskeys:
|
dnskeys:
|
||||||
invalid: 'DNS keys are invalid'
|
invalid: 'DNS keys are invalid'
|
||||||
not_found: 'Dnskey was not found'
|
not_found: 'Dnskey was not found'
|
||||||
|
out_of_range: 'DNS keys count must be between %{min}-%{max}'
|
||||||
|
|
||||||
domain:
|
domain:
|
||||||
<<: *epp_domain_ar_attributes
|
<<: *epp_domain_ar_attributes
|
||||||
|
@ -211,6 +212,11 @@ en:
|
||||||
nameservers: 'Nameservers'
|
nameservers: 'Nameservers'
|
||||||
domain:
|
domain:
|
||||||
<<: *epp_domain_attributes
|
<<: *epp_domain_attributes
|
||||||
|
dnskey:
|
||||||
|
flags: 'Flag'
|
||||||
|
protocol: 'Protocol'
|
||||||
|
alg: 'Algorithm'
|
||||||
|
public_key: 'Public key'
|
||||||
|
|
||||||
|
|
||||||
errors:
|
errors:
|
||||||
|
|
7
db/migrate/20141006124904_add_dnskey_range_validation.rb
Normal file
7
db/migrate/20141006124904_add_dnskey_range_validation.rb
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
class AddDnskeyRangeValidation < ActiveRecord::Migration
|
||||||
|
def change
|
||||||
|
sg = SettingGroup.find_by(code: 'domain_validation')
|
||||||
|
sg.settings << Setting.create(code: 'dnskeys_min_count'.underscore, value: '0')
|
||||||
|
sg.settings << Setting.create(code: 'dnskeys_max_count'.underscore, value: '9')
|
||||||
|
end
|
||||||
|
end
|
|
@ -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: 20141001085322) do
|
ActiveRecord::Schema.define(version: 20141006124904) 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"
|
||||||
|
|
|
@ -447,6 +447,38 @@ describe 'EPP Domain', epp: true do
|
||||||
expect(response[:msg]).to eq('Public key already exists')
|
expect(response[:msg]).to eq('Public key already exists')
|
||||||
expect(response[:results][0][:value]).to eq('700b97b591ed27ec2590d19f06f88bba700b97b591ed27ec2590d19f')
|
expect(response[:results][0][:value]).to eq('700b97b591ed27ec2590d19f06f88bba700b97b591ed27ec2590d19f')
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it 'validated dnskeys count' do
|
||||||
|
s = Setting.find_by(code: 'dnskeys_max_count')
|
||||||
|
s.value = 1
|
||||||
|
s.save
|
||||||
|
|
||||||
|
xml = domain_create_xml({
|
||||||
|
dnssec: [
|
||||||
|
{
|
||||||
|
dnskey: {
|
||||||
|
flags: { value: '257' },
|
||||||
|
protocol: { value: '3' },
|
||||||
|
alg: { value: '3' },
|
||||||
|
pubKey: { value: 'AwEAAddt2AkLfYGKgiEZB5SmIF8EvrjxNMH6HtxWEA4RJ9Ao6LCWheg8' }
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
dnskey: {
|
||||||
|
flags: { value: '0' },
|
||||||
|
protocol: { value: '3' },
|
||||||
|
alg: { value: '5' },
|
||||||
|
pubKey: { value: '700b97b591ed27ec2590d19f06f88bba700b97b591ed27ec2590d19f' }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
})
|
||||||
|
|
||||||
|
response = epp_request(xml, :xml)
|
||||||
|
|
||||||
|
expect(response[:result_code]).to eq('2004')
|
||||||
|
expect(response[:msg]).to eq('DNS keys count must be between 0-1')
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'with juridical persion as an owner' do
|
context 'with juridical persion as an owner' do
|
||||||
|
|
|
@ -13,7 +13,9 @@ Fabricator(:domain_validation_setting_group, from: :setting_group) do
|
||||||
settings do
|
settings do
|
||||||
[
|
[
|
||||||
Fabricate(:setting, code: 'ns_min_count', value: 1),
|
Fabricate(:setting, code: 'ns_min_count', value: 1),
|
||||||
Fabricate(:setting, code: 'ns_max_count', value: 13)
|
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
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue