From 459f626808cf7149b070ce6497e4b88a8ac662d7 Mon Sep 17 00:00:00 2001 From: Oleg Hasjanov Date: Fri, 30 Apr 2021 18:21:41 +0300 Subject: [PATCH] added condition to return if there no any domain_name header --- .../registrar/nameservers_controller.rb | 7 +++++- .../bulk_change/nameserver_test.rb | 22 +++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/app/controllers/registrar/nameservers_controller.rb b/app/controllers/registrar/nameservers_controller.rb index a45077a1c..300784626 100644 --- a/app/controllers/registrar/nameservers_controller.rb +++ b/app/controllers/registrar/nameservers_controller.rb @@ -7,6 +7,7 @@ class Registrar ipv6 = params[:ipv6].split("\r\n") domains = domain_list_from_csv + return csv_list_empty_guard if domains == [] uri = URI.parse("#{ENV['repp_url']}registrar/nameservers") @@ -53,7 +54,11 @@ class Registrar return if params[:puny_file].blank? domains = [] - CSV.read(params[:puny_file].path, headers: true).map { |b| domains << b['domain_name'] } + csv = CSV.read(params[:puny_file].path, headers: true) + + return if csv['domain_name'].blank? + csv.map { |b| domains << b['domain_name'] } + domains.compact rescue CSV::MalformedCSVError [] diff --git a/test/system/registrar_area/bulk_change/nameserver_test.rb b/test/system/registrar_area/bulk_change/nameserver_test.rb index e7afd4171..a21e0d059 100644 --- a/test/system/registrar_area/bulk_change/nameserver_test.rb +++ b/test/system/registrar_area/bulk_change/nameserver_test.rb @@ -96,6 +96,26 @@ class RegistrarAreaNameserverBulkChangeTest < ApplicationSystemTestCase end def test_replaces_nameservers_with_invalid_domains_list + 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: "{\"data\":{\"type\":\"nameserver\",\"id\":\"ns1.bestnames.test\",\"domains\":[],\"attributes\":{\"hostname\":\"new-ns.bestnames.test\",\"ipv4\":[\"192.0.2.55\",\"192.0.2.56\"],\"ipv6\":[\"2001:db8::55\",\"2001:db8::56\"]}}}", + headers: { + 'Accept'=>'*/*', + 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', + 'Authorization'=>'Basic dGVzdF9nb29kbmFtZXM6dGVzdHRlc3Q=', + 'Content-Type'=>'application/json', + 'Host'=>'epp:3000', + 'User-Agent'=>'Ruby' + }). + to_return(status: 200, body: "", headers: {}) + visit registrar_domains_url click_link 'Bulk change' click_link 'Nameserver' @@ -110,6 +130,8 @@ class RegistrarAreaNameserverBulkChangeTest < ApplicationSystemTestCase click_on 'Replace nameserver' end + assert_requested request_stub + assert_text 'CSV scoped domain list seems empty. Make sure that domains are added and ' \ '"domain_name" header is present.' end