From 1db594fc1c61fd47a2c4284a61c20d231311fb60 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karl=20Erik=20=C3=95unapuu?= Date: Wed, 18 Nov 2020 16:29:18 +0200 Subject: [PATCH] NS bulk change: Add tests, don't use name_puny format --- app/models/registrar.rb | 2 +- .../valid_domains_for_ns_replacement.csv | 2 ++ .../registrar/replace_nameservers_test.rb | 16 +++++++++ .../bulk_change/nameserver_test.rb | 33 +++++++++++++++++++ 4 files changed, 52 insertions(+), 1 deletion(-) create mode 100644 test/fixtures/files/valid_domains_for_ns_replacement.csv diff --git a/app/models/registrar.rb b/app/models/registrar.rb index 040c7886b..e79cd87f2 100644 --- a/app/models/registrar.rb +++ b/app/models/registrar.rb @@ -146,7 +146,7 @@ class Registrar < ApplicationRecord domain_list = [] nameservers.where(hostname: hostname).find_each do |original_nameserver| - next unless domains.include?(original_nameserver.domain.name_puny) || domains.empty? + next unless domains.include?(original_nameserver.domain.name) || domains.empty? new_nameserver = Nameserver.new new_nameserver.domain = original_nameserver.domain diff --git a/test/fixtures/files/valid_domains_for_ns_replacement.csv b/test/fixtures/files/valid_domains_for_ns_replacement.csv new file mode 100644 index 000000000..122301ca8 --- /dev/null +++ b/test/fixtures/files/valid_domains_for_ns_replacement.csv @@ -0,0 +1,2 @@ +domain_name +shop.test diff --git a/test/models/registrar/replace_nameservers_test.rb b/test/models/registrar/replace_nameservers_test.rb index 5bcbb83d1..36071e3fa 100644 --- a/test/models/registrar/replace_nameservers_test.rb +++ b/test/models/registrar/replace_nameservers_test.rb @@ -20,4 +20,20 @@ class ReplaceNameserversTest < ActiveSupport::TestCase assert_equal([], result) end + + def test_replace_nameserver_in_bulk_respects_domain_limit_scope + eligible_domain = domains(:shop) + unscoped_domain = domains(:airport) + + new_attributes = { hostname: 'ns-updated1.bestnames.test', ipv4: '192.0.3.1', + ipv6: '2001:db8::2' } + + result = @registrar.replace_nameservers('ns1.bestnames.test', new_attributes, domains: ['shop.test']) + assert_equal(["shop.test"], result) + + unscoped_domain.reload + eligible_domain.reload + assert eligible_domain.nameservers.where(hostname: 'ns1.bestnames.test').empty? + assert unscoped_domain.nameservers.where(hostname: 'ns1.bestnames.test').any? + end end diff --git a/test/system/registrar_area/bulk_change/nameserver_test.rb b/test/system/registrar_area/bulk_change/nameserver_test.rb index 3d4b4dc70..38c2cb9e6 100644 --- a/test/system/registrar_area/bulk_change/nameserver_test.rb +++ b/test/system/registrar_area/bulk_change/nameserver_test.rb @@ -57,4 +57,37 @@ class RegistrarAreaNameserverBulkChangeTest < ApplicationSystemTestCase assert_field 'ipv4', with: 'ipv4' assert_field 'ipv6', with: 'ipv6' end + + def test_replaces_nameservers_only_for_scoped_domains + request_body = { data: { type: 'nameserver', + id: 'ns1.bestnames.test', + domains: ['shop.test'], + attributes: { hostname: 'new-ns.bestnames.test', + ipv4: %w[192.0.2.55 192.0.2.56], + ipv6: %w[2001:db8::55 2001:db8::56] } } } + request_stub = stub_request(:put, /registrar\/nameservers/).with(body: request_body, + headers: { 'Content-type' => Mime[:json] }, + basic_auth: ['test_goodnames', 'testtest']) + .to_return(body: { data: [{ + type: 'nameserver', + id: 'new-ns.bestnames.test'}], + affected_domains: ["shop.test"]}.to_json, status: 200) + + visit registrar_domains_url + click_link 'Bulk change' + click_link 'Nameserver' + + fill_in 'Old hostname', with: 'ns1.bestnames.test' + fill_in 'New hostname', with: 'new-ns.bestnames.test' + fill_in 'ipv4', with: "192.0.2.55\n192.0.2.56" + fill_in 'ipv6', with: "2001:db8::55\n2001:db8::56" + attach_file :puny_file, Rails.root.join('test', 'fixtures', 'files', 'valid_domains_for_ns_replacement.csv').to_s + + click_on 'Replace nameserver' + + assert_requested request_stub + assert_current_path registrar_domains_path + assert_text 'Nameserver have been successfully replaced' + assert_text 'Affected domains: shop.test' + end end