From 1461d2a5664ad5fe0f74d7a034780b14a9a938f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karl=20Erik=20=C3=95unapuu?= Date: Tue, 2 Feb 2021 11:26:52 +0200 Subject: [PATCH] REPP: Domain registrant change test --- .../repp/v1/domains/contacts_controller.rb | 2 +- .../repp/v1/domains/dnssec_controller.rb | 2 +- .../repp/v1/domains/nameservers_controller.rb | 2 +- app/controllers/repp/v1/domains_controller.rb | 2 +- app/models/actions/domain_update.rb | 1 - .../repp/v1/domains/update_test.rb | 85 +++++++++++++++++++ 6 files changed, 89 insertions(+), 5 deletions(-) create mode 100644 test/integration/repp/v1/domains/update_test.rb diff --git a/app/controllers/repp/v1/domains/contacts_controller.rb b/app/controllers/repp/v1/domains/contacts_controller.rb index b84e4bd46..f2e5e4018 100644 --- a/app/controllers/repp/v1/domains/contacts_controller.rb +++ b/app/controllers/repp/v1/domains/contacts_controller.rb @@ -39,7 +39,7 @@ module Repp def cta(action = 'add') params[:contacts].each { |c| c[:action] = action } - action = Actions::DomainUpdate.new(@domain, contact_create_params, current_user) + action = Actions::DomainUpdate.new(@domain, contact_create_params, false) # rubocop:disable Style/AndOr handle_errors(@domain) and return unless action.call diff --git a/app/controllers/repp/v1/domains/dnssec_controller.rb b/app/controllers/repp/v1/domains/dnssec_controller.rb index 491ce0a98..fcfaa991a 100644 --- a/app/controllers/repp/v1/domains/dnssec_controller.rb +++ b/app/controllers/repp/v1/domains/dnssec_controller.rb @@ -38,7 +38,7 @@ module Repp def cta(action = 'add') params[:dns_keys].each { |n| n[:action] = action } - action = Actions::DomainUpdate.new(@domain, dnssec_params, current_user) + action = Actions::DomainUpdate.new(@domain, dnssec_params, false) # rubocop:disable Style/AndOr (handle_errors(@domain) and return) unless action.call diff --git a/app/controllers/repp/v1/domains/nameservers_controller.rb b/app/controllers/repp/v1/domains/nameservers_controller.rb index 0a907c04e..fe38de93c 100644 --- a/app/controllers/repp/v1/domains/nameservers_controller.rb +++ b/app/controllers/repp/v1/domains/nameservers_controller.rb @@ -28,7 +28,7 @@ module Repp desc 'Delete specific nameserver from domain' def destroy nameserver = { nameservers: [{ hostname: params[:id], action: 'rem' }] } - action = Actions::DomainUpdate.new(@domain, nameserver, current_user) + action = Actions::DomainUpdate.new(@domain, nameserver, false) unless action.call handle_errors(@domain) diff --git a/app/controllers/repp/v1/domains_controller.rb b/app/controllers/repp/v1/domains_controller.rb index e8fdb040f..3db71c23b 100644 --- a/app/controllers/repp/v1/domains_controller.rb +++ b/app/controllers/repp/v1/domains_controller.rb @@ -76,7 +76,7 @@ module Repp param :auth_info, String, required: false, desc: 'New authorization code' end def update - action = Actions::DomainUpdate.new(@domain, params[:domain], current_user) + action = Actions::DomainUpdate.new(@domain, params[:domain], false) unless action.call handle_errors(@domain) diff --git a/app/models/actions/domain_update.rb b/app/models/actions/domain_update.rb index 4131c4f51..d54bb99da 100644 --- a/app/models/actions/domain_update.rb +++ b/app/models/actions/domain_update.rb @@ -223,7 +223,6 @@ module Actions def ask_registrant_verification if verify_registrant_change? && !bypass_verify && Setting.request_confirmation_on_registrant_change_enabled - domain.registrant_verification_asked!(params, params[:registrar_id]) end end diff --git a/test/integration/repp/v1/domains/update_test.rb b/test/integration/repp/v1/domains/update_test.rb new file mode 100644 index 000000000..da79312d1 --- /dev/null +++ b/test/integration/repp/v1/domains/update_test.rb @@ -0,0 +1,85 @@ +require 'test_helper' + +class ReppV1DomainsCreateTest < ActionDispatch::IntegrationTest + def setup + @user = users(:api_bestnames) + @domain = domains(:shop) + token = Base64.encode64("#{@user.username}:#{@user.plain_text_password}") + token = "Basic #{token}" + + @auth_headers = { 'Authorization' => token } + end + + def test_updates_transfer_code_for_domain + @auth_headers['Content-Type'] = 'application/json' + new_auth_code = 'aisdcbkabcsdnc' + + payload = { + domain: { + auth_code: new_auth_code + } + } + + put "/repp/v1/domains/#{@domain.name}", headers: @auth_headers, params: payload.to_json + @domain.reload + json = JSON.parse(response.body, symbolize_names: true) + assert_response :ok + assert_equal 1000, json[:code] + assert_equal 'Command completed successfully', json[:message] + + assert new_auth_code, @domain.auth_info + end + + def test_domain_pending_update_on_registrant_change + Setting.request_confirmation_on_registrant_change_enabled = true + + @auth_headers['Content-Type'] = 'application/json' + new_registrant = contacts(:william) + refute @domain.registrant == new_registrant + + payload = { + domain: { + registrant: { + code: new_registrant.code + } + } + } + + put "/repp/v1/domains/#{@domain.name}", headers: @auth_headers, params: payload.to_json + @domain.reload + json = JSON.parse(response.body, symbolize_names: true) + assert_response :ok + assert_equal 1000, json[:code] + assert_equal 'Command completed successfully', json[:message] + + refute @domain.registrant.code == new_registrant.code + assert @domain.statuses.include? DomainStatus::PENDING_UPDATE + end + + def test_replaces_registrant_when_verified + Setting.request_confirmation_on_registrant_change_enabled = true + + @auth_headers['Content-Type'] = 'application/json' + new_registrant = contacts(:william) + refute @domain.registrant == new_registrant + + payload = { + domain: { + registrant: { + code: new_registrant.code, + verified: true + } + } + } + + put "/repp/v1/domains/#{@domain.name}", headers: @auth_headers, params: payload.to_json + @domain.reload + json = JSON.parse(response.body, symbolize_names: true) + assert_response :ok + assert_equal 1000, json[:code] + assert_equal 'Command completed successfully', json[:message] + + assert @domain.registrant.code == new_registrant.code + refute @domain.statuses.include? DomainStatus::PENDING_UPDATE + end +end