From a7e303bba2d596cdeea5109d68d4288ed48a3a0f Mon Sep 17 00:00:00 2001 From: Oleg Hasjanov Date: Wed, 27 Jan 2021 13:42:10 +0200 Subject: [PATCH 1/4] added test for domain tech contacts bulk change if domain has server update prohibited --- test/integration/api/domain_contacts_test.rb | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/test/integration/api/domain_contacts_test.rb b/test/integration/api/domain_contacts_test.rb index 6704739d1..efd7032b4 100644 --- a/test/integration/api/domain_contacts_test.rb +++ b/test/integration/api/domain_contacts_test.rb @@ -107,6 +107,24 @@ class APIDomainContactsTest < ApplicationIntegrationTest JSON.parse(response.body, symbolize_names: true) end + def test_tech_bulk_changed_when_domain_update_prohibited + domains(:shop).update!(statuses: [DomainStatus::SERVER_UPDATE_PROHIBITED]) + + shop_tech_contact = Contact.find_by(code: 'william-001') + assert domains(:shop).tech_contacts.include?(shop_tech_contact) + + patch '/repp/v1/domains/contacts', params: { current_contact_id: 'william-001', + new_contact_id: 'john-001' }, + headers: { 'HTTP_AUTHORIZATION' => http_auth_key } + + assert_response :ok + assert_equal ({ code: 1000, + message: 'Command completed successfully', + data: { affected_domains: ["airport.test"], + skipped_domains: ["shop.test"] }}), + JSON.parse(response.body, symbolize_names: true) + end + private def http_auth_key From 218bc436e6b7b744179b06c0fd380a45f5e44696 Mon Sep 17 00:00:00 2001 From: Oleg Hasjanov Date: Tue, 2 Feb 2021 15:07:31 +0200 Subject: [PATCH 2/4] Added test for bulk transfer and bulk nameservers --- test/integration/api/domain_transfers_test.rb | 14 ++++++++++++++ test/integration/api/nameservers/put_test.rb | 16 ++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/test/integration/api/domain_transfers_test.rb b/test/integration/api/domain_transfers_test.rb index 3e9c10100..2cf12130b 100644 --- a/test/integration/api/domain_transfers_test.rb +++ b/test/integration/api/domain_transfers_test.rb @@ -63,6 +63,20 @@ class APIDomainTransfersTest < ApplicationIntegrationTest assert_equal 1, @new_registrar.contacts.where(name: 'William').size end + def test_bulk_transfer_if_domain_has_update_prohibited_status + domains(:shop).update!(statuses: [DomainStatus::SERVER_UPDATE_PROHIBITED]) + + post '/repp/v1/domains/transfer', params: request_params, as: :json, + headers: { 'HTTP_AUTHORIZATION' => http_auth_key } + + assert_response :ok + assert_equal ({ code: 1000, + message: 'Command completed successfully', + data: { success: [], + failed: [{ type: "domain_transfer", domain_name: "shop.test" }] }}), + JSON.parse(response.body, symbolize_names: true) + end + private def request_params diff --git a/test/integration/api/nameservers/put_test.rb b/test/integration/api/nameservers/put_test.rb index 77b01a9b1..f1a478da6 100644 --- a/test/integration/api/nameservers/put_test.rb +++ b/test/integration/api/nameservers/put_test.rb @@ -104,6 +104,22 @@ class APINameserversPutTest < ApplicationIntegrationTest JSON.parse(response.body, symbolize_names: true) end + def test_bulk_namesaervers_if_domain_update_prohibited + domains(:shop).update!(statuses: [DomainStatus::SERVER_UPDATE_PROHIBITED]) + + params = { data: { type: 'nameserver', id: domains(:shop).nameservers.hostnames[0], + attributes: { hostname: 'ns55.bestnames.test' } } } + put '/repp/v1/registrar/nameservers', params: params, as: :json, + headers: { 'HTTP_AUTHORIZATION' => http_auth_key } + + assert_response :ok + assert_equal ({ code: 1000, + message: 'Command completed successfully', + data: { affected_domains: ["airport.test"], + skipped_domains: ["shop.test"] }}), + JSON.parse(response.body, symbolize_names: true) + end + def test_unauthenticated put '/repp/v1/registrar/nameservers' assert_response 401 From d3525acffef6c147e3378a5340d042c9e88dccef Mon Sep 17 00:00:00 2001 From: Alex Sherman Date: Thu, 11 Feb 2021 14:52:02 +0500 Subject: [PATCH 3/4] Add check if UpdateProhibited to nameserver bulk update --- app/models/registrar.rb | 6 ++++- .../repp/v1/registrar/nameservers_test.rb | 27 +++++++++++++++++++ 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/app/models/registrar.rb b/app/models/registrar.rb index 168dfdca7..652864fe5 100644 --- a/app/models/registrar.rb +++ b/app/models/registrar.rb @@ -153,7 +153,7 @@ class Registrar < ApplicationRecord puny = origin.domain.name_puny next unless domains.include?(idn) || domains.include?(puny) || domains.empty? - if origin.domain.nameservers.where(hostname: new_attributes[:hostname]).any? + if domain_not_updatable?(hostname: new_attributes[:hostname], domain: origin.domain) failed_list << idn next end @@ -202,6 +202,10 @@ class Registrar < ApplicationRecord private + def domain_not_updatable?(hostname:, domain:) + domain.nameservers.where(hostname: hostname).any? || domain.bulk_update_prohibited? + end + def set_defaults self.language = Setting.default_language unless language end diff --git a/test/integration/repp/v1/registrar/nameservers_test.rb b/test/integration/repp/v1/registrar/nameservers_test.rb index f01769dfb..e2c6f890b 100644 --- a/test/integration/repp/v1/registrar/nameservers_test.rb +++ b/test/integration/repp/v1/registrar/nameservers_test.rb @@ -34,6 +34,33 @@ class ReppV1RegistrarNameserversTest < ActionDispatch::IntegrationTest assert json[:data][:affected_domains].include? 'shop.test' end + def test_fails_to_update_if_prohibited + domain = domains(:shop) + domain.update(statuses: [DomainStatus::CLIENT_UPDATE_PROHIBITED]) + nameserver = nameservers(:shop_ns1) + payload = { + "data": { + "id": nameserver.hostname, + "type": "nameserver", + "attributes": { + "hostname": "#{nameserver.hostname}.test", + "ipv4": ["1.1.1.1"] + } + } + } + + put '/repp/v1/registrar/nameservers', headers: @auth_headers, params: payload + json = JSON.parse(response.body, symbolize_names: true) + + assert_response :ok + assert_equal 1000, json[:code] + assert_equal 'Command completed successfully', json[:message] + assert_equal({ hostname: "#{nameserver.hostname}.test", ipv4: ["1.1.1.1"] }, json[:data][:attributes]) + assert_equal({ hostname: "#{nameserver.hostname}.test", ipv4: ["1.1.1.1"] }, json[:data][:attributes]) + assert json[:data][:affected_domains].include? 'airport.test' + assert json[:data][:skipped_domains].include? 'shop.test' + end + def test_nameserver_with_hostname_must_exist payload = { "data": { From 44add87fe24fa96b527f64a9c119437bf4bd6d77 Mon Sep 17 00:00:00 2001 From: Alex Sherman Date: Mon, 22 Feb 2021 13:54:41 +0500 Subject: [PATCH 4/4] Add tests on domain transfer --- app/models/concerns/domain/transferable.rb | 4 +++- test/integration/api/domain_transfers_test.rb | 7 +++++-- test/integration/api/nameservers/put_test.rb | 11 +++++++---- 3 files changed, 15 insertions(+), 7 deletions(-) diff --git a/app/models/concerns/domain/transferable.rb b/app/models/concerns/domain/transferable.rb index 5400e9409..649600217 100644 --- a/app/models/concerns/domain/transferable.rb +++ b/app/models/concerns/domain/transferable.rb @@ -31,7 +31,9 @@ module Concerns::Domain::Transferable DomainStatus::PENDING_TRANSFER, DomainStatus::FORCE_DELETE, DomainStatus::SERVER_TRANSFER_PROHIBITED, - DomainStatus::CLIENT_TRANSFER_PROHIBITED + DomainStatus::CLIENT_TRANSFER_PROHIBITED, + DomainStatus::SERVER_UPDATE_PROHIBITED, + DomainStatus::CLIENT_UPDATE_PROHIBITED, ]).empty? end diff --git a/test/integration/api/domain_transfers_test.rb b/test/integration/api/domain_transfers_test.rb index 2cf12130b..3ed5b0fc6 100644 --- a/test/integration/api/domain_transfers_test.rb +++ b/test/integration/api/domain_transfers_test.rb @@ -68,12 +68,15 @@ class APIDomainTransfersTest < ApplicationIntegrationTest post '/repp/v1/domains/transfer', params: request_params, as: :json, headers: { 'HTTP_AUTHORIZATION' => http_auth_key } - + assert_response :ok assert_equal ({ code: 1000, message: 'Command completed successfully', data: { success: [], - failed: [{ type: "domain_transfer", domain_name: "shop.test" }] }}), + failed: [{ type: "domain_transfer", + domain_name: "shop.test", + errors: [{:code=>"2304", :msg=>"Object status prohibits operation"}] }], + }}), JSON.parse(response.body, symbolize_names: true) end diff --git a/test/integration/api/nameservers/put_test.rb b/test/integration/api/nameservers/put_test.rb index f1a478da6..a55014709 100644 --- a/test/integration/api/nameservers/put_test.rb +++ b/test/integration/api/nameservers/put_test.rb @@ -108,15 +108,18 @@ class APINameserversPutTest < ApplicationIntegrationTest domains(:shop).update!(statuses: [DomainStatus::SERVER_UPDATE_PROHIBITED]) params = { data: { type: 'nameserver', id: domains(:shop).nameservers.hostnames[0], - attributes: { hostname: 'ns55.bestnames.test' } } } + attributes: { hostname: 'ns55.bestnames.test' } } } put '/repp/v1/registrar/nameservers', params: params, as: :json, headers: { 'HTTP_AUTHORIZATION' => http_auth_key } - + assert_response :ok assert_equal ({ code: 1000, message: 'Command completed successfully', - data: { affected_domains: ["airport.test"], - skipped_domains: ["shop.test"] }}), + data: { type: "nameserver", + id: "ns55.bestnames.test", + attributes: {hostname: "ns55.bestnames.test"}, + affected_domains: ["airport.test"], + skipped_domains: ["shop.test"]}}), JSON.parse(response.body, symbolize_names: true) end