mirror of
https://github.com/internetee/registry.git
synced 2025-08-02 16:02:03 +02:00
Validate dnskey uniqueness
This commit is contained in:
parent
416128823b
commit
f6ac22df52
5 changed files with 51 additions and 1 deletions
|
@ -15,6 +15,9 @@ class Dnskey < ActiveRecord::Base
|
|||
[:protocol, :invalid, { value: { obj: 'protocol', val: protocol } }],
|
||||
[:flags, :invalid, { value: { obj: 'flags', val: flags } }]
|
||||
],
|
||||
'2302' => [
|
||||
[:public_key, :taken, { value: { obj: 'pubKye', val: public_key } }]
|
||||
],
|
||||
'2303' => [
|
||||
[:base, :dnskey_not_found, { value: { obj: 'pubKey', val: public_key } }]
|
||||
],
|
||||
|
@ -28,16 +31,19 @@ class Dnskey < ActiveRecord::Base
|
|||
end
|
||||
|
||||
def validate_algorithm
|
||||
return if alg.blank?
|
||||
return if %w(3 5 6 7 8 252 253 254 255).include?(alg.to_s)
|
||||
errors.add(:alg, :invalid)
|
||||
end
|
||||
|
||||
def validate_protocol
|
||||
return if protocol.blank?
|
||||
return if %w(3).include?(protocol.to_s)
|
||||
errors.add(:protocol, :invalid)
|
||||
end
|
||||
|
||||
def validate_flags
|
||||
return if flags.blank?
|
||||
return if %w(0 256 257).include?(flags.to_s)
|
||||
errors.add(:flags, :invalid)
|
||||
end
|
||||
|
|
|
@ -53,6 +53,7 @@ class Domain < ActiveRecord::Base
|
|||
validate :validate_tech_contacts_uniqueness
|
||||
validate :validate_admin_contacts_uniqueness
|
||||
validate :validate_domain_statuses_uniqueness
|
||||
validate :validate_dnskeys_uniqueness
|
||||
validate :validate_nameserver_ips
|
||||
|
||||
attr_accessor :owner_contact_typeahead
|
||||
|
@ -148,6 +149,18 @@ class Domain < ActiveRecord::Base
|
|||
end
|
||||
end
|
||||
|
||||
def validate_dnskeys_uniqueness
|
||||
validated = []
|
||||
dnskeys.reject(&:marked_for_destruction?).each do |dnskey|
|
||||
next if dnskey.public_key.blank?
|
||||
existing = dnskeys.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
|
||||
|
||||
def validate_period
|
||||
return unless period.present?
|
||||
if period_unit == 'd'
|
||||
|
|
|
@ -14,7 +14,7 @@
|
|||
.row
|
||||
.col-md-4
|
||||
.form-group
|
||||
= key_fields.label :flags
|
||||
= key_fields.label :flags, t('shared.flag')
|
||||
= key_fields.text_field :flags, class: 'form-control'
|
||||
.col-md-4
|
||||
.form-group
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue