From ad7a9bf92134998fb9b07edeead1547b2e1a5f83 Mon Sep 17 00:00:00 2001 From: dinsmol Date: Mon, 4 Oct 2021 17:33:43 +0300 Subject: [PATCH 1/6] fixed dnssec update checking logic --- app/controllers/epp/domains_controller.rb | 29 +++++++++++------------ 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/app/controllers/epp/domains_controller.rb b/app/controllers/epp/domains_controller.rb index 39e0d7af59..adcad8f721 100644 --- a/app/controllers/epp/domains_controller.rb +++ b/app/controllers/epp/domains_controller.rb @@ -169,26 +169,26 @@ def validate_update def parsed_response_for_dnskey(value) doc = Nokogiri::Slop params[:parsed_frame].css(value).to_html - return true if doc.document.children.empty? - + store = [] - if value == 'add' - doc.document.add.children.each_with_index do |x, i| - store << doc.document.add.children[i].name + case value + when 'add' + doc.document.add.children.each_with_index do |_x, i| + store << doc.document.add.children[i].name end - elsif value == 'chg' - doc.document.chg.children.each_with_index do |x, i| - store << doc.document.chg.children[i].name + when 'chg' + doc.document.chg.children.each_with_index do |_x, i| + store << doc.document.chg.children[i].name end else - doc.document.rem.children.each_with_index do |x, i| - store << doc.document.rem.children[i].name + doc.document.rem.children.each_with_index do |_x, i| + store << doc.document.rem.children[i].name end end - return true if store.size == 1 and store[0] == "keyData" + return true if store.size.positive? && store.include?('keyData') store.empty? end @@ -209,10 +209,9 @@ def dnskey_update_enabled return if parsed_response_for_dnskey('rem') end - return epp_errors.add(:epp_errors, - code: '2304', - msg: "#{I18n.t(:object_status_prohibits_operation)} - :serverObjUpdateEnabled") + epp_errors.add(:epp_errors, + code: '2304', + msg: "#{I18n.t(:object_status_prohibits_operation)} :serverObjUpdateProhibited") end end From 2f349658ae74857c4330492930f26c751dd07755 Mon Sep 17 00:00:00 2001 From: dinsmol Date: Thu, 7 Oct 2021 14:53:52 +0300 Subject: [PATCH 2/6] added tests --- test/fixtures/dnskeys.yml | 10 +++ .../registrar_area/xml_consoles_test.rb | 90 +++++++++++++++++++ 2 files changed, 100 insertions(+) diff --git a/test/fixtures/dnskeys.yml b/test/fixtures/dnskeys.yml index b740a6ec0e..2b75b46034 100644 --- a/test/fixtures/dnskeys.yml +++ b/test/fixtures/dnskeys.yml @@ -18,3 +18,13 @@ with_whitespace: ds_alg: 13 ds_digest_type: 2 ds_digest: 39456058862EA09DD96992ED2BDAFAEDE8C7E949589E3DA903A46F4F9CD373EA +two: + domain: + flags: 257 + protocol: 3 + alg: 8 + public_key: AwEAAdas/oY6xQV2MYd+o5pcUHK0f/mtETRNyBhh/TSABqRM9JikXlSrwLFT9sAfOsTiRNbPnvEiCKdEdoN0f0Oel0WNXadLlVINmxtCue93bSX7zxrVvjhbkHffOVdpBL0CIDQoX1HPZmoBXXPdZtWLpDQ7nVfUtdC/McTFSRawUYaoCWOEAgC8YY+kh6C8TUZzHMl+JiVE6YFkTIFf+z4MxA920UxUnGpdcfRbcB0CYjCxe+PuiA+aZHFheEe5S5tlW7tO96hxK/k2l93N//T2mEM53TKomk62HoWvNVdPrs7jdZbGzeY2eBPDWMAIIpgOv9ApORi+kHSQm2POCwf/KYs= + ds_key_tag: 23527 + ds_alg: 8 + ds_digest_type: 2 + ds_digest: 5937141E8D3D91E15D94263A723C4E804513C71CB642AB86B41BDB65EF2FA4F4 diff --git a/test/system/registrar_area/xml_consoles_test.rb b/test/system/registrar_area/xml_consoles_test.rb index 51cc362eb8..7c4a074a98 100644 --- a/test/system/registrar_area/xml_consoles_test.rb +++ b/test/system/registrar_area/xml_consoles_test.rb @@ -14,8 +14,98 @@ def test_epp_server_does_not_response assert el.text.include? 'CONNECTION ERROR - Is the EPP server running?' end + def test_update_dnskey + @domain = domains(:shop) + visit registrar_xml_console_path + fill_in 'payload', with: schema_dnskey_add + click_on 'Send EPP Request' + + el = page.find('.CodeRay', visible: :all) + assert el.text.include? 'Command completed successfully' + + @domain.statuses << DomainStatus::SERVER_UPDATE_PROHIBITED + assert @domain.statuses.include? DomainStatus::SERVER_UPDATE_PROHIBITED + + ENV['obj_and_extensions_prohibited'] = 'true' + assert Feature.obj_and_extensions_statuses_enabled? + + visit registrar_xml_console_path + fill_in 'payload', with: schema_dnskey_update + click_on 'Send EPP Request' + + el = page.find('.CodeRay', visible: :all) + assert el.text.include? 'Command completed successfully' + end + private + def schema_dnskey_add + @dnskey = dnskeys(:one) + <<~XML + + + + + + shop.test + + + + + + + #{@dnskey.flags} + #{@dnskey.protocol} + #{@dnskey.alg} + #{@dnskey.public_key} + + + + + 0.04946500 1632965705 + + + XML + end + + def schema_dnskey_update + @dnskey = dnskeys(:one) + @dnskeynew = dnskeys(:two) + <<~XML + + + + + + shop.test + + + + + \n + + #{@dnskey.flags} + #{@dnskey.protocol} + #{@dnskey.alg} + #{@dnskey.public_key} + \n + + \n + + #{@dnskeynew.flags} + #{@dnskeynew.protocol} + #{@dnskeynew.alg} + #{@dnskeynew.public_key} + \n + + + + 0.04946500 1632965705 + + + XML + end + def schema_example <<~XML From 5545cf02a174f8abca7982431eff067d99cccd7a Mon Sep 17 00:00:00 2001 From: dinsmol Date: Thu, 7 Oct 2021 15:55:54 +0300 Subject: [PATCH 3/6] fixed test --- .../registrar_area/xml_consoles_test.rb | 37 ++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/test/system/registrar_area/xml_consoles_test.rb b/test/system/registrar_area/xml_consoles_test.rb index 7c4a074a98..a6555ce717 100644 --- a/test/system/registrar_area/xml_consoles_test.rb +++ b/test/system/registrar_area/xml_consoles_test.rb @@ -16,6 +16,14 @@ def test_epp_server_does_not_response def test_update_dnskey @domain = domains(:shop) + @dnskey = dnskeys(:one) + @dnskeynew = dnskeys(:two) + visit registrar_xml_console_path + fill_in 'payload', with: schema_dnskey_rem(@dnskey) + click_on 'Send EPP Request' + fill_in 'payload', with: schema_dnskey_rem(@dnskeynew) + click_on 'Send EPP Request' + visit registrar_xml_console_path fill_in 'payload', with: schema_dnskey_add click_on 'Send EPP Request' @@ -39,8 +47,35 @@ def test_update_dnskey private + def schema_dnskey_rem(key) + <<~XML + + + + + + shop.test + + + + + + + #{key.flags} + #{key.protocol} + #{key.alg} + #{key.public_key} + + + + + 0.04946500 1632965705 + + + XML + end + def schema_dnskey_add - @dnskey = dnskeys(:one) <<~XML From e9fc932777aa159c9e6ee7b0804bb086314d60eb Mon Sep 17 00:00:00 2001 From: dinsmol Date: Thu, 7 Oct 2021 17:47:35 +0300 Subject: [PATCH 4/6] fixed tests --- test/fixtures/dnskeys.yml | 10 -- .../epp/domain/update/replace_dns_test.rb | 140 ++++++++++++++++++ .../registrar_area/xml_consoles_test.rb | 125 ---------------- 3 files changed, 140 insertions(+), 135 deletions(-) create mode 100644 test/integration/epp/domain/update/replace_dns_test.rb diff --git a/test/fixtures/dnskeys.yml b/test/fixtures/dnskeys.yml index 2b75b46034..b740a6ec0e 100644 --- a/test/fixtures/dnskeys.yml +++ b/test/fixtures/dnskeys.yml @@ -18,13 +18,3 @@ with_whitespace: ds_alg: 13 ds_digest_type: 2 ds_digest: 39456058862EA09DD96992ED2BDAFAEDE8C7E949589E3DA903A46F4F9CD373EA -two: - domain: - flags: 257 - protocol: 3 - alg: 8 - public_key: AwEAAdas/oY6xQV2MYd+o5pcUHK0f/mtETRNyBhh/TSABqRM9JikXlSrwLFT9sAfOsTiRNbPnvEiCKdEdoN0f0Oel0WNXadLlVINmxtCue93bSX7zxrVvjhbkHffOVdpBL0CIDQoX1HPZmoBXXPdZtWLpDQ7nVfUtdC/McTFSRawUYaoCWOEAgC8YY+kh6C8TUZzHMl+JiVE6YFkTIFf+z4MxA920UxUnGpdcfRbcB0CYjCxe+PuiA+aZHFheEe5S5tlW7tO96hxK/k2l93N//T2mEM53TKomk62HoWvNVdPrs7jdZbGzeY2eBPDWMAIIpgOv9ApORi+kHSQm2POCwf/KYs= - ds_key_tag: 23527 - ds_alg: 8 - ds_digest_type: 2 - ds_digest: 5937141E8D3D91E15D94263A723C4E804513C71CB642AB86B41BDB65EF2FA4F4 diff --git a/test/integration/epp/domain/update/replace_dns_test.rb b/test/integration/epp/domain/update/replace_dns_test.rb new file mode 100644 index 0000000000..51f307dc73 --- /dev/null +++ b/test/integration/epp/domain/update/replace_dns_test.rb @@ -0,0 +1,140 @@ +require 'test_helper' + +class EppDomainUpdateReplaceDnsTest < 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 + + def test_replace_dnskey_with_spaces_in_request + doc = Nokogiri::XML::Document.parse(schema_new) + params = { parsed_frame: doc } + domain_controller = Epp::DomainsController.new + domain_controller.params = ActionController::Parameters.new(params) + + assert_equal(domain_controller.send(:parsed_response_for_dnskey, 'rem'), true) + assert_equal(domain_controller.send(:parsed_response_for_dnskey, 'add'), true) + end + + def schema_new + <<~XML + + + + + + shop.test + + + + + \n + + 257 + 3 + 8 + AwEAAbXae59P87nfCP1MpLJouUhtDlVFbgek392nxqJcIHwYAs5sd4O4BPAvd41VmqhWllTiArNYDBV8UAtPZ8eZtYDC4D7ITC1HsxzQzzMUOorrNwMQMFq/PHP9tKelfRh68dh7UX0nTKlIouTcZ3xbqxAeoAbgvFjj/ZDS8G4QE2NgdonaK2w9q/da189zrZUhyAgecZCiTXbqqXd/LNXGRwDjJgFBWBmXbEjkcSfHke7idAcGqmYK2E5FstsmEwDcupxZ8jxuN1m/wDrBeZE5UdT24LtLGDda+ATXvCuARhQtZzSAn0JOdfGN5xJ02g+OtsbVC/mSGR3rykjzJ+hUlPU=\n + + \n + + 257 + 3 + 8 + AwEAAdas/oY6xQV2MYd+o5pcUHK0f/mtETRNyBhh/TSABqRM9JikXlSrwLFT9sAfOsTiRNbPnvEiCKdEdoN0f0Oel0WNXadLlVINmxtCue93bSX7zxrVvjhbkHffOVdpBL0CIDQoX1HPZmoBXXPdZtWLpDQ7nVfUtdC/McTFSRawUYaoCWOEAgC8YY+kh6C8TUZzHMl+JiVE6YFkTIFf+z4MxA920UxUnGpdcfRbcB0CYjCxe+PuiA+aZHFheEe5S5tlW7tO96hxK/k2l93N//T2mEM53TKomk62HoWvNVdPrs7jdZbGzeY2eBPDWMAIIpgOv9ApORi+kHSQm2POCwf/KYs=\n + + + + 0.04946500 1632965705 + +\n + XML + end +end diff --git a/test/system/registrar_area/xml_consoles_test.rb b/test/system/registrar_area/xml_consoles_test.rb index a6555ce717..51cc362eb8 100644 --- a/test/system/registrar_area/xml_consoles_test.rb +++ b/test/system/registrar_area/xml_consoles_test.rb @@ -14,133 +14,8 @@ def test_epp_server_does_not_response assert el.text.include? 'CONNECTION ERROR - Is the EPP server running?' end - def test_update_dnskey - @domain = domains(:shop) - @dnskey = dnskeys(:one) - @dnskeynew = dnskeys(:two) - visit registrar_xml_console_path - fill_in 'payload', with: schema_dnskey_rem(@dnskey) - click_on 'Send EPP Request' - fill_in 'payload', with: schema_dnskey_rem(@dnskeynew) - click_on 'Send EPP Request' - - visit registrar_xml_console_path - fill_in 'payload', with: schema_dnskey_add - click_on 'Send EPP Request' - - el = page.find('.CodeRay', visible: :all) - assert el.text.include? 'Command completed successfully' - - @domain.statuses << DomainStatus::SERVER_UPDATE_PROHIBITED - assert @domain.statuses.include? DomainStatus::SERVER_UPDATE_PROHIBITED - - ENV['obj_and_extensions_prohibited'] = 'true' - assert Feature.obj_and_extensions_statuses_enabled? - - visit registrar_xml_console_path - fill_in 'payload', with: schema_dnskey_update - click_on 'Send EPP Request' - - el = page.find('.CodeRay', visible: :all) - assert el.text.include? 'Command completed successfully' - end - private - def schema_dnskey_rem(key) - <<~XML - - - - - - shop.test - - - - - - - #{key.flags} - #{key.protocol} - #{key.alg} - #{key.public_key} - - - - - 0.04946500 1632965705 - - - XML - end - - def schema_dnskey_add - <<~XML - - - - - - shop.test - - - - - - - #{@dnskey.flags} - #{@dnskey.protocol} - #{@dnskey.alg} - #{@dnskey.public_key} - - - - - 0.04946500 1632965705 - - - XML - end - - def schema_dnskey_update - @dnskey = dnskeys(:one) - @dnskeynew = dnskeys(:two) - <<~XML - - - - - - shop.test - - - - - \n - - #{@dnskey.flags} - #{@dnskey.protocol} - #{@dnskey.alg} - #{@dnskey.public_key} - \n - - \n - - #{@dnskeynew.flags} - #{@dnskeynew.protocol} - #{@dnskeynew.alg} - #{@dnskeynew.public_key} - \n - - - - 0.04946500 1632965705 - - - XML - end - def schema_example <<~XML From 81b26431af511f59a828021d1ce126b201e1d439 Mon Sep 17 00:00:00 2001 From: dinsmol Date: Thu, 7 Oct 2021 20:22:04 +0300 Subject: [PATCH 5/6] fix for capybara errors --- test/system/registrar_area/bulk_change/nameserver_test.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/test/system/registrar_area/bulk_change/nameserver_test.rb b/test/system/registrar_area/bulk_change/nameserver_test.rb index 8a053333f3..b6aa37e595 100644 --- a/test/system/registrar_area/bulk_change/nameserver_test.rb +++ b/test/system/registrar_area/bulk_change/nameserver_test.rb @@ -3,6 +3,7 @@ class RegistrarAreaNameserverBulkChangeTest < ApplicationSystemTestCase setup do sign_in users(:api_goodnames) + Capybara.default_max_wait_time = 5 end def test_replaces_current_registrar_nameservers From aafefe507e76e6542463da806a38368e2435f0c0 Mon Sep 17 00:00:00 2001 From: dinsmol Date: Fri, 8 Oct 2021 09:35:22 +0300 Subject: [PATCH 6/6] removed dublicate code --- .../epp/domain/update/replace_dns_test.rb | 99 +------------------ 1 file changed, 3 insertions(+), 96 deletions(-) diff --git a/test/integration/epp/domain/update/replace_dns_test.rb b/test/integration/epp/domain/update/replace_dns_test.rb index 51f307dc73..62dcbc299f 100644 --- a/test/integration/epp/domain/update/replace_dns_test.rb +++ b/test/integration/epp/domain/update/replace_dns_test.rb @@ -1,101 +1,8 @@ require 'test_helper' class EppDomainUpdateReplaceDnsTest < 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 - - def test_replace_dnskey_with_spaces_in_request - doc = Nokogiri::XML::Document.parse(schema_new) + def test_parsed_response_for_dnskey_with_spaces_in_request + doc = Nokogiri::XML::Document.parse(schema_update) params = { parsed_frame: doc } domain_controller = Epp::DomainsController.new domain_controller.params = ActionController::Parameters.new(params) @@ -104,7 +11,7 @@ def test_replace_dnskey_with_spaces_in_request assert_equal(domain_controller.send(:parsed_response_for_dnskey, 'add'), true) end - def schema_new + def schema_update <<~XML