From 79d2b6980936b4f29da14869859ba59fc56db714 Mon Sep 17 00:00:00 2001 From: Martin Lensment Date: Mon, 13 Oct 2014 10:33:36 +0300 Subject: [PATCH] Tests working with dnssec --- app/controllers/concerns/epp/common.rb | 2 +- app/helpers/epp/domains_helper.rb | 1 + app/models/concerns/epp_errors.rb | 35 -------------------------- app/models/epp/epp_domain.rb | 21 ++++++++++++++++ spec/epp/domain_spec.rb | 21 ++++------------ 5 files changed, 28 insertions(+), 52 deletions(-) diff --git a/app/controllers/concerns/epp/common.rb b/app/controllers/concerns/epp/common.rb index 201fd7abe..c18ed2ea0 100644 --- a/app/controllers/concerns/epp/common.rb +++ b/app/controllers/concerns/epp/common.rb @@ -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 diff --git a/app/helpers/epp/domains_helper.rb b/app/helpers/epp/domains_helper.rb index 1f6b68b4f..b1c15dd69 100644 --- a/app/helpers/epp/domains_helper.rb +++ b/app/helpers/epp/domains_helper.rb @@ -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? diff --git a/app/models/concerns/epp_errors.rb b/app/models/concerns/epp_errors.rb index fcc31a7dd..8e637fd74 100644 --- a/app/models/concerns/epp_errors.rb +++ b/app/models/concerns/epp_errors.rb @@ -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| diff --git a/app/models/epp/epp_domain.rb b/app/models/epp/epp_domain.rb index 527f5dca2..a1bc50242 100644 --- a/app/models/epp/epp_domain.rb +++ b/app/models/epp/epp_domain.rb @@ -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 diff --git a/spec/epp/domain_spec.rb b/spec/epp/domain_spec.rb index 05838c283..b7f20e983 100644 --- a/spec/epp/domain_spec.rb +++ b/spec/epp/domain_spec.rb @@ -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')