mirror of
https://github.com/internetee/registry.git
synced 2025-07-21 10:16:01 +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)
|
def handle_errors(obj = nil)
|
||||||
@errors ||= []
|
@errors ||= []
|
||||||
if obj
|
if obj
|
||||||
obj.construct_epp_errors
|
obj.generate_epp_errors
|
||||||
@errors += obj.errors[:epp_errors]
|
@errors += obj.errors[:epp_errors]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,36 @@
|
||||||
module EppErrors
|
module EppErrors
|
||||||
extend ActiveSupport::Concern
|
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
|
def construct_epp_errors
|
||||||
epp_errors = []
|
epp_errors = []
|
||||||
errors.messages.each do |key, values|
|
errors.messages.each do |key, values|
|
||||||
|
|
|
@ -1,3 +1,23 @@
|
||||||
class DelegationSigner < ActiveRecord::Base
|
class DelegationSigner < ActiveRecord::Base
|
||||||
|
include EppErrors
|
||||||
has_many :dnskeys
|
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
|
end
|
||||||
|
|
|
@ -9,6 +9,8 @@ class Dnskey < ActiveRecord::Base
|
||||||
validate :validate_protocol
|
validate :validate_protocol
|
||||||
validate :validate_flags
|
validate :validate_flags
|
||||||
|
|
||||||
|
# after_validation :generate_epp_errors
|
||||||
|
|
||||||
ALGORITHMS = %w(3 5 6 7 8 252 253 254 255)
|
ALGORITHMS = %w(3 5 6 7 8 252 253 254 255)
|
||||||
PROTOCOLS = %w(3)
|
PROTOCOLS = %w(3)
|
||||||
FLAGS = %w(0 256 257)
|
FLAGS = %w(0 256 257)
|
||||||
|
|
|
@ -54,7 +54,6 @@ class Domain < ActiveRecord::Base
|
||||||
validate :validate_tech_contacts_uniqueness
|
validate :validate_tech_contacts_uniqueness
|
||||||
validate :validate_admin_contacts_uniqueness
|
validate :validate_admin_contacts_uniqueness
|
||||||
validate :validate_domain_statuses_uniqueness
|
validate :validate_domain_statuses_uniqueness
|
||||||
#validate :validate_dnskeys_uniqueness
|
|
||||||
validate :validate_nameserver_ips
|
validate :validate_nameserver_ips
|
||||||
|
|
||||||
attr_accessor :owner_contact_typeahead
|
attr_accessor :owner_contact_typeahead
|
||||||
|
@ -159,19 +158,6 @@ class Domain < ActiveRecord::Base
|
||||||
end
|
end
|
||||||
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
|
def validate_period
|
||||||
return unless period.present?
|
return unless period.present?
|
||||||
if period_unit == 'd'
|
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 :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 }
|
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
|
# archiving
|
||||||
has_paper_trail class_name: 'NameserverVersion'
|
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.nameservers.count).to eq(2)
|
||||||
expect(d.auth_info).not_to be_empty
|
expect(d.auth_info).not_to be_empty
|
||||||
|
|
||||||
expect(d.dnskeys.count).to eq(1)
|
expect(d.delegation_signers.count).to eq(1)
|
||||||
key = d.dnskeys.first
|
ds = d.delegation_signers.first
|
||||||
|
|
||||||
|
expect(ds.dnskeys.count).to eq(1)
|
||||||
|
|
||||||
|
key = ds.dnskeys.first
|
||||||
|
|
||||||
expect(key.flags).to eq(257)
|
expect(key.flags).to eq(257)
|
||||||
expect(key.protocol).to eq(3)
|
expect(key.protocol).to eq(3)
|
||||||
|
@ -221,7 +225,7 @@ describe 'EPP Domain', epp: true do
|
||||||
})
|
})
|
||||||
|
|
||||||
response = epp_request(xml, :xml)
|
response = epp_request(xml, :xml)
|
||||||
|
po response
|
||||||
expect(response[:result_code]).to eq('2306')
|
expect(response[:result_code]).to eq('2306')
|
||||||
expect(response[:msg]).to eq('IPv4 is missing')
|
expect(response[:msg]).to eq('IPv4 is missing')
|
||||||
end
|
end
|
||||||
|
@ -373,10 +377,10 @@ describe 'EPP Domain', epp: true do
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'does not create a domain when dnskeys are invalid' do
|
it 'does not create a domain when dnskeys are invalid' do
|
||||||
xml = domain_create_xml({
|
|
||||||
dnssec: [
|
xml = domain_create_xml({}, {
|
||||||
{
|
_other: [
|
||||||
dnskey: {
|
{ keyData: {
|
||||||
flags: { value: '250' },
|
flags: { value: '250' },
|
||||||
protocol: { value: '4' },
|
protocol: { value: '4' },
|
||||||
alg: { value: '9' },
|
alg: { value: '9' },
|
||||||
|
@ -384,7 +388,7 @@ describe 'EPP Domain', epp: true do
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
dnskey: {
|
keyData: {
|
||||||
flags: { value: '1' },
|
flags: { value: '1' },
|
||||||
protocol: { value: '3' },
|
protocol: { value: '3' },
|
||||||
alg: { value: '10' },
|
alg: { value: '10' },
|
||||||
|
@ -392,7 +396,7 @@ describe 'EPP Domain', epp: true do
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
dnskey: {
|
keyData: {
|
||||||
flags: { value: '256' },
|
flags: { value: '256' },
|
||||||
protocol: { value: '5' },
|
protocol: { value: '5' },
|
||||||
alg: { value: '254' },
|
alg: { value: '254' },
|
||||||
|
@ -426,10 +430,9 @@ describe 'EPP Domain', epp: true do
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'does not create a domain with two identical dnskeys' do
|
it 'does not create a domain with two identical dnskeys' do
|
||||||
xml = domain_create_xml({
|
xml = domain_create_xml({}, {
|
||||||
dnssec: [
|
_other: [
|
||||||
{
|
{ keyData: {
|
||||||
dnskey: {
|
|
||||||
flags: { value: '257' },
|
flags: { value: '257' },
|
||||||
protocol: { value: '3' },
|
protocol: { value: '3' },
|
||||||
alg: { value: '3' },
|
alg: { value: '3' },
|
||||||
|
@ -437,15 +440,14 @@ describe 'EPP Domain', epp: true do
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
dnskey: {
|
keyData: {
|
||||||
flags: { value: '0' },
|
flags: { value: '0' },
|
||||||
protocol: { value: '3' },
|
protocol: { value: '3' },
|
||||||
alg: { value: '5' },
|
alg: { value: '5' },
|
||||||
pubKey: { value: '700b97b591ed27ec2590d19f06f88bba700b97b591ed27ec2590d19f' }
|
pubKey: { value: '700b97b591ed27ec2590d19f06f88bba700b97b591ed27ec2590d19f' }
|
||||||
}
|
}
|
||||||
}
|
}]
|
||||||
]
|
})
|
||||||
})
|
|
||||||
|
|
||||||
response = epp_request(xml, :xml)
|
response = epp_request(xml, :xml)
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue