From 58d2bdb7754db122ed63f232a72efe27915d499b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karl=20Erik=20=C3=95unapuu?= Date: Thu, 14 Jan 2021 11:15:07 +0200 Subject: [PATCH 1/3] Accept puny-coded domain for polling Transfer Info --- app/controllers/repp/v1/domains_controller.rb | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/app/controllers/repp/v1/domains_controller.rb b/app/controllers/repp/v1/domains_controller.rb index ba90f23f2..3715e78ed 100644 --- a/app/controllers/repp/v1/domains_controller.rb +++ b/app/controllers/repp/v1/domains_controller.rb @@ -68,9 +68,7 @@ module Repp def set_authorized_domain @epp_errors ||= [] - h = {} - h[transfer_info_params[:id].match?(/\A[0-9]+\z/) ? :id : :name] = transfer_info_params[:id] - @domain = Domain.find_by!(h) + @domain = domain_from_url_hash return if @domain.transfer_code.eql?(request.headers['Auth-Code']) @@ -78,6 +76,13 @@ module Repp handle_errors end + def domain_from_url_hash + entry = transfer_info_params[:id] + return Domain.find(entry) if entry.match?(/\A[0-9]+\z/) + + Domain.find_by!('name = ? OR name_puny = ?', entry, entry) + end + def limit index_params[:limit] || 200 end From 887283fd72595f808a230a7e1bed61b408c9cc2f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karl=20Erik=20=C3=95unapuu?= Date: Thu, 14 Jan 2021 11:15:39 +0200 Subject: [PATCH 2/3] Use around_action instead of after_action for REPP logging --- app/controllers/repp/v1/base_controller.rb | 29 +++++++++++++--------- 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/app/controllers/repp/v1/base_controller.rb b/app/controllers/repp/v1/base_controller.rb index 2814ce2da..a194caf1a 100644 --- a/app/controllers/repp/v1/base_controller.rb +++ b/app/controllers/repp/v1/base_controller.rb @@ -1,7 +1,7 @@ module Repp module V1 class BaseController < ActionController::API - rescue_from ActiveRecord::RecordNotFound, with: :not_found_error + around_action :log_request before_action :authenticate_user before_action :validate_webclient_ca before_action :check_ip_restriction @@ -9,21 +9,31 @@ module Repp before_action :set_paper_trail_whodunnit - rescue_from ActionController::ParameterMissing do |exception| - render json: { code: 2003, message: exception }, status: :bad_request + private + + def log_request + yield + rescue ActiveRecord::RecordNotFound + @response = { code: 2303, message: 'Object does not exist' } + render(json: @response, status: :not_found) + rescue ActionController::ParameterMissing => e + @response = { code: 2003, message: e } + render(json: @response, status: :bad_request) + ensure + create_repp_log end - after_action do + # rubocop:disable Metrics/AbcSize + def create_repp_log ApiLog::ReppLog.create( request_path: request.path, request_method: request.request_method, request_params: request.params.except('route_info').to_json, uuid: request.try(:uuid), - response: @response.to_json, response_code: status, ip: request.ip, + response: @response.to_json, response_code: response.status, ip: request.ip, api_user_name: current_user.try(:username), api_user_registrar: current_user.try(:registrar).try(:to_s) ) end - - private + # rubocop:enable Metrics/AbcSize def set_paper_trail_whodunnit ::PaperTrail.request.whodunnit = current_user @@ -120,11 +130,6 @@ module Repp render(json: @response, status: :unauthorized) end - - def not_found_error - @response = { code: 2303, message: 'Object does not exist' } - render(json: @response, status: :not_found) - end end end end From 97abe3fb9edf7f21c714c28b73406c18a79c535a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karl=20Erik=20=C3=95unapuu?= Date: Thu, 14 Jan 2021 12:15:48 +0200 Subject: [PATCH 3/3] Test puny domain for transfer info --- .../repp/v1/domains/transfer_info_test.rb | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/test/integration/repp/v1/domains/transfer_info_test.rb b/test/integration/repp/v1/domains/transfer_info_test.rb index f57675b06..df6bc4f12 100644 --- a/test/integration/repp/v1/domains/transfer_info_test.rb +++ b/test/integration/repp/v1/domains/transfer_info_test.rb @@ -37,4 +37,17 @@ class ReppV1DomainsTransferInfoTest < ActionDispatch::IntegrationTest assert_equal 'Authorization error', json[:message] assert_empty json[:data] end + + def test_processes_puny_domains + @domain.update(name_puny: 'xn--prototp-s2aa.ee') + + headers = @auth_headers + headers['Auth-Code'] = @domain.transfer_code + + get "/repp/v1/domains/xn--prototp-s2aa.ee/transfer_info", headers: headers + json = JSON.parse(response.body, symbolize_names: true) + + assert_response :ok + assert_equal 1000, json[:code] + end end