From c5317691517756a7e579e8b98a6e19140303970a Mon Sep 17 00:00:00 2001 From: Alex Sherman Date: Mon, 21 Jun 2021 16:01:17 +0500 Subject: [PATCH] Add support of bulk removing of dnskeys --- lib/deserializers/xml/dnssec.rb | 22 ++++- lib/deserializers/xml/domain_update.rb | 3 +- .../epp/domain/update/rem_dns_test.rb | 96 +++++++++++++++++++ 3 files changed, 117 insertions(+), 4 deletions(-) create mode 100644 test/integration/epp/domain/update/rem_dns_test.rb diff --git a/lib/deserializers/xml/dnssec.rb b/lib/deserializers/xml/dnssec.rb index 89e7934a8..562d05c7a 100644 --- a/lib/deserializers/xml/dnssec.rb +++ b/lib/deserializers/xml/dnssec.rb @@ -41,7 +41,7 @@ module Deserializers class DnssecKeys attr_reader :frame, :key_data, :ds_data - def initialize(frame) + def initialize(frame, domain_name = nil) @key_data = [] @ds_data = [] @@ -50,9 +50,25 @@ module Deserializers frame.css('dsData').each { |k| @ds_data << key_from_params(k, dsa: true) } end - return if frame.css('keyData').blank? + if frame.css('all')&.text == 'true' + keys_from_domain_name(domain_name) + elsif frame.css('keyData').present? + frame.css('keyData').each { |k| @key_data << key_from_params(k, dsa: false) } + end + end - frame.css('keyData').each { |k| @key_data << key_from_params(k, dsa: false) } + def keys_from_domain_name(domain_name) + domain = Epp::Domain.find_by(name: domain_name) + return unless domain + + domain.dnskeys.each do |key| + @key_data << { + flags: key.flags, + protocol: key.protocol, + alg: key.alg, + public_key: key.public_key, + } + end end def key_from_params(obj, dsa: false) diff --git a/lib/deserializers/xml/domain_update.rb b/lib/deserializers/xml/domain_update.rb index eb1b22296..7aca4e09a 100644 --- a/lib/deserializers/xml/domain_update.rb +++ b/lib/deserializers/xml/domain_update.rb @@ -60,7 +60,8 @@ module Deserializers def dns_keys added = ::Deserializers::Xml::DnssecKeys.new(frame.css('add')).call added.each { |k| k[:action] = 'add' } - removed = ::Deserializers::Xml::DnssecKeys.new(frame.css('rem')).call + removed = ::Deserializers::Xml::DnssecKeys.new(frame.css('rem'), + frame.css('name')&.text).call removed.each { |k| k[:action] = 'rem' } return if (added + removed).blank? diff --git a/test/integration/epp/domain/update/rem_dns_test.rb b/test/integration/epp/domain/update/rem_dns_test.rb new file mode 100644 index 000000000..537b9a708 --- /dev/null +++ b/test/integration/epp/domain/update/rem_dns_test.rb @@ -0,0 +1,96 @@ +require 'test_helper' + +class EppDomainUpdateRemDnsTest < EppTestCase + include ActionMailer::TestHelper + include ActiveJob::TestHelper + + setup do + @domain = domains(:shop) + @contact = contacts(:john) + @dnskey = dnskeys(:one) + @dnskey.update(domain: @domain) + @original_registrant_change_verification = + Setting.request_confirmation_on_registrant_change_enabled + ActionMailer::Base.deliveries.clear + end + + teardown do + Setting.request_confirmation_on_registrant_change_enabled = + @original_registrant_change_verification + end + + def test_remove_dnskey_if_explicitly_set + request_xml = <<-XML + + + + + + shop.test + + + f0ff7d17b0 + + + + + + + + + #{@dnskey.flags} + #{@dnskey.protocol} + #{@dnskey.alg} + #{@dnskey.public_key} + + + + + + + XML + + post epp_update_path, params: { frame: request_xml }, + headers: { 'HTTP_COOKIE' => 'session=api_bestnames' } + response_xml = Nokogiri::XML(response.body) + assert_correct_against_schema response_xml + @domain.reload + assert_equal 0, @domain.dnskeys.count + assert_epp_response :completed_successfully + end + + def test_remove_dnskey_if_remove_all + request_xml = <<-XML + + + + + + shop.test + + + f0ff7d17b0 + + + + + + + + true + + + + + + XML + + post epp_update_path, params: { frame: request_xml }, + headers: { 'HTTP_COOKIE' => 'session=api_bestnames' } + response_xml = Nokogiri::XML(response.body) + assert_correct_against_schema response_xml + @domain.reload + assert_equal 0, @domain.dnskeys.count + assert_epp_response :completed_successfully + end +end