mirror of
https://github.com/internetee/registry.git
synced 2025-07-21 02:05:57 +02:00
Refactor EPP Errors once again
This commit is contained in:
parent
6ab58767c3
commit
a740ed34f3
7 changed files with 74 additions and 32 deletions
|
@ -41,7 +41,7 @@ module Epp::Common
|
|||
def handle_errors(obj = nil)
|
||||
@errors ||= []
|
||||
if obj
|
||||
obj.construct_epp_errors
|
||||
obj.generate_epp_errors
|
||||
@errors += obj.errors[:epp_errors]
|
||||
end
|
||||
|
||||
|
|
|
@ -1,6 +1,36 @@
|
|||
module EppErrors
|
||||
extend ActiveSupport::Concern
|
||||
|
||||
def generate_epp_errors
|
||||
epp_errors = []
|
||||
errors.messages.each do |key, values|
|
||||
key = key.to_s.split('.')[0].to_sym
|
||||
if self.class.reflect_on_association(key)
|
||||
send(key).each do |x|
|
||||
epp_errors << x.generate_epp_errors
|
||||
end
|
||||
end
|
||||
|
||||
epp_errors << collect_parent_errors(values)
|
||||
end
|
||||
|
||||
errors[:epp_errors] = epp_errors
|
||||
errors[:epp_errors].flatten!
|
||||
# epp_errors = []
|
||||
# errors.messages.each do |key, values|
|
||||
# if self.class.reflect_on_association(key)
|
||||
# send(key).each do |x|
|
||||
# epp_errors << x.errors[:epp_errors]
|
||||
# end
|
||||
# end
|
||||
|
||||
# epp_errors << collect_parent_errors(values)
|
||||
# end
|
||||
|
||||
# errors[:epp_errors] = epp_errors
|
||||
# errors[:epp_errors].flatten!
|
||||
end
|
||||
|
||||
def construct_epp_errors
|
||||
epp_errors = []
|
||||
errors.messages.each do |key, values|
|
||||
|
|
|
@ -1,3 +1,23 @@
|
|||
class DelegationSigner < ActiveRecord::Base
|
||||
include EppErrors
|
||||
has_many :dnskeys
|
||||
|
||||
validate :validate_dnskeys_uniqueness
|
||||
|
||||
def epp_code_map
|
||||
{}
|
||||
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
|
||||
|
|
|
@ -9,6 +9,8 @@ class Dnskey < ActiveRecord::Base
|
|||
validate :validate_protocol
|
||||
validate :validate_flags
|
||||
|
||||
# after_validation :generate_epp_errors
|
||||
|
||||
ALGORITHMS = %w(3 5 6 7 8 252 253 254 255)
|
||||
PROTOCOLS = %w(3)
|
||||
FLAGS = %w(0 256 257)
|
||||
|
|
|
@ -54,7 +54,6 @@ 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
|
||||
|
@ -159,19 +158,6 @@ class Domain < ActiveRecord::Base
|
|||
end
|
||||
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
|
||||
|
||||
def validate_period
|
||||
return unless period.present?
|
||||
if period_unit == 'd'
|
||||
|
|
|
@ -8,6 +8,8 @@ class Nameserver < ActiveRecord::Base
|
|||
validates :ipv4, format: { with: /\A(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\z/, allow_blank: true }
|
||||
validates :ipv6, format: { with: /(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]).){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]).){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))/, allow_blank: true }
|
||||
|
||||
|
||||
|
||||
# archiving
|
||||
has_paper_trail class_name: 'NameserverVersion'
|
||||
|
||||
|
|
|
@ -203,8 +203,12 @@ describe 'EPP Domain', epp: true do
|
|||
expect(d.nameservers.count).to eq(2)
|
||||
expect(d.auth_info).not_to be_empty
|
||||
|
||||
expect(d.dnskeys.count).to eq(1)
|
||||
key = d.dnskeys.first
|
||||
expect(d.delegation_signers.count).to eq(1)
|
||||
ds = d.delegation_signers.first
|
||||
|
||||
expect(ds.dnskeys.count).to eq(1)
|
||||
|
||||
key = ds.dnskeys.first
|
||||
|
||||
expect(key.flags).to eq(257)
|
||||
expect(key.protocol).to eq(3)
|
||||
|
@ -221,7 +225,7 @@ describe 'EPP Domain', epp: true do
|
|||
})
|
||||
|
||||
response = epp_request(xml, :xml)
|
||||
|
||||
po response
|
||||
expect(response[:result_code]).to eq('2306')
|
||||
expect(response[:msg]).to eq('IPv4 is missing')
|
||||
end
|
||||
|
@ -373,10 +377,10 @@ describe 'EPP Domain', epp: true do
|
|||
end
|
||||
|
||||
it 'does not create a domain when dnskeys are invalid' do
|
||||
xml = domain_create_xml({
|
||||
dnssec: [
|
||||
{
|
||||
dnskey: {
|
||||
|
||||
xml = domain_create_xml({}, {
|
||||
_other: [
|
||||
{ keyData: {
|
||||
flags: { value: '250' },
|
||||
protocol: { value: '4' },
|
||||
alg: { value: '9' },
|
||||
|
@ -384,7 +388,7 @@ describe 'EPP Domain', epp: true do
|
|||
}
|
||||
},
|
||||
{
|
||||
dnskey: {
|
||||
keyData: {
|
||||
flags: { value: '1' },
|
||||
protocol: { value: '3' },
|
||||
alg: { value: '10' },
|
||||
|
@ -392,7 +396,7 @@ describe 'EPP Domain', epp: true do
|
|||
}
|
||||
},
|
||||
{
|
||||
dnskey: {
|
||||
keyData: {
|
||||
flags: { value: '256' },
|
||||
protocol: { value: '5' },
|
||||
alg: { value: '254' },
|
||||
|
@ -426,10 +430,9 @@ describe 'EPP Domain', epp: true do
|
|||
end
|
||||
|
||||
it 'does not create a domain with two identical dnskeys' do
|
||||
xml = domain_create_xml({
|
||||
dnssec: [
|
||||
{
|
||||
dnskey: {
|
||||
xml = domain_create_xml({}, {
|
||||
_other: [
|
||||
{ keyData: {
|
||||
flags: { value: '257' },
|
||||
protocol: { value: '3' },
|
||||
alg: { value: '3' },
|
||||
|
@ -437,15 +440,14 @@ describe 'EPP Domain', epp: true do
|
|||
}
|
||||
},
|
||||
{
|
||||
dnskey: {
|
||||
keyData: {
|
||||
flags: { value: '0' },
|
||||
protocol: { value: '3' },
|
||||
alg: { value: '5' },
|
||||
pubKey: { value: '700b97b591ed27ec2590d19f06f88bba700b97b591ed27ec2590d19f' }
|
||||
}
|
||||
}
|
||||
]
|
||||
})
|
||||
}]
|
||||
})
|
||||
|
||||
response = epp_request(xml, :xml)
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue