Tests working with dnssec

This commit is contained in:
Martin Lensment 2014-10-13 10:33:36 +03:00
parent eaa553dc9d
commit 79d2b69809
5 changed files with 28 additions and 52 deletions

View file

@ -41,7 +41,7 @@ module Epp::Common
def handle_errors(obj = nil)
@errors ||= []
if obj
obj.generate_epp_errors
obj.construct_epp_errors
@errors += obj.errors[:epp_errors]
end

View file

@ -53,6 +53,7 @@ module Epp::DomainsHelper
@domain.parse_and_attach_domain_dependencies(parsed_frame.css('add'))
@domain.parse_and_attach_ds_data(parsed_frame.css('extension add'))
@domain.parse_and_detach_domain_dependencies(parsed_frame.css('rem'))
@domain.parse_and_detach_ds_data(parsed_frame.css('extension rem'))
@domain.parse_and_update_domain_dependencies(parsed_frame.css('chg'))
if @domain.errors.any?

View file

@ -1,41 +1,6 @@
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
macro = self.class.reflect_on_association(key).try(:macro)
multi = [:has_and_belongs_to_many, :has_many]
single = [:belongs_to, :has_one]
if macro && multi.include?(macro)
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|

View file

@ -66,6 +66,12 @@ class Epp::EppDomain < Domain
errors.empty?
end
def parse_and_detach_ds_data(parsed_frame)
detach_dnskeys(self.class.parse_dnskeys_from_frame(parsed_frame))
errors.empty?
end
def parse_and_update_domain_dependencies(parsed_frame)
owner_contact_code = parsed_frame.css('registrant').try(:text)
attach_owner_contact(owner_contact_code) if owner_contact_code.present?
@ -235,6 +241,21 @@ class Epp::EppDomain < Domain
end
end
if dnssec_data[:key_data].any? && !key_data_allowed
errors.add(:base, :key_data_not_allowed)
return
end
to_delete = []
dnssec_data[:key_data].each do |x|
ds = dnskeys.where(public_key: x[:public_key])
if ds.blank?
add_epp_error('2303', 'publicKey', x[:public_key], [:dnskeys, :not_found])
else
to_delete << ds
end
end
dnskeys.delete(to_delete)
end

View file

@ -716,10 +716,7 @@ describe 'EPP Domain', epp: true do
expect(d.domain_statuses.first.value).to eq('clientHold')
expect(d.domain_statuses.last.value).to eq('clientUpdateProhibited')
expect(d.delegation_signers.count).to eq(1)
ds = d.delegation_signers.first
expect(ds.dnskeys.count).to eq(2)
expect(d.dnskeys.count).to eq(2)
response = epp_request(xml, :xml)
expect(response[:results][0][:result_code]).to eq('2302')
@ -780,6 +777,8 @@ describe 'EPP Domain', epp: true do
})
epp_request(xml, :xml)
d = Domain.last
expect(d.dnskeys.count).to eq(2)
xml = domain_update_xml({
rem: [
@ -788,13 +787,6 @@ describe 'EPP Domain', epp: true do
{ hostObj: { value: 'ns1.example.com' } }
]
},
dnssec: [
{
dnskey: {
pubKey: { value: '700b97b591ed27ec2590d19f06f88bba700b97b591ed27ec2590d19f' }
}
}
],
_other: [
{ contact: { value: 'mak21', attrs: { type: 'tech' } } },
{ status: { value: '', attrs: { s: 'clientHold' } } }
@ -809,12 +801,9 @@ describe 'EPP Domain', epp: true do
]
})
d = Domain.last
expect(d.delegation_signers.count).to eq(1)
response = epp_request(xml, :xml)
ds = d.delegation_signers.first
expect(ds.dnskeys.count).to eq(1)
expect(d.dnskeys.count).to eq(1)
expect(d.domain_statuses.count).to eq(1)
expect(d.domain_statuses.first.value).to eq('clientUpdateProhibited')