mirror of
https://github.com/internetee/registry.git
synced 2025-06-06 20:55:44 +02:00
Merge pull request #1802 from internetee/repp-transfer-info-puny
REPP: Resolve puny domain for transfer info / Improve REPP logging
This commit is contained in:
commit
9515601549
3 changed files with 38 additions and 15 deletions
|
@ -1,7 +1,7 @@
|
||||||
module Repp
|
module Repp
|
||||||
module V1
|
module V1
|
||||||
class BaseController < ActionController::API
|
class BaseController < ActionController::API
|
||||||
rescue_from ActiveRecord::RecordNotFound, with: :not_found_error
|
around_action :log_request
|
||||||
before_action :authenticate_user
|
before_action :authenticate_user
|
||||||
before_action :validate_webclient_ca
|
before_action :validate_webclient_ca
|
||||||
before_action :check_ip_restriction
|
before_action :check_ip_restriction
|
||||||
|
@ -9,21 +9,31 @@ module Repp
|
||||||
|
|
||||||
before_action :set_paper_trail_whodunnit
|
before_action :set_paper_trail_whodunnit
|
||||||
|
|
||||||
rescue_from ActionController::ParameterMissing do |exception|
|
private
|
||||||
render json: { code: 2003, message: exception }, status: :bad_request
|
|
||||||
|
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
|
end
|
||||||
|
|
||||||
after_action do
|
# rubocop:disable Metrics/AbcSize
|
||||||
|
def create_repp_log
|
||||||
ApiLog::ReppLog.create(
|
ApiLog::ReppLog.create(
|
||||||
request_path: request.path, request_method: request.request_method,
|
request_path: request.path, request_method: request.request_method,
|
||||||
request_params: request.params.except('route_info').to_json, uuid: request.try(:uuid),
|
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_name: current_user.try(:username),
|
||||||
api_user_registrar: current_user.try(:registrar).try(:to_s)
|
api_user_registrar: current_user.try(:registrar).try(:to_s)
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
# rubocop:enable Metrics/AbcSize
|
||||||
private
|
|
||||||
|
|
||||||
def set_paper_trail_whodunnit
|
def set_paper_trail_whodunnit
|
||||||
::PaperTrail.request.whodunnit = current_user
|
::PaperTrail.request.whodunnit = current_user
|
||||||
|
@ -120,11 +130,6 @@ module Repp
|
||||||
|
|
||||||
render(json: @response, status: :unauthorized)
|
render(json: @response, status: :unauthorized)
|
||||||
end
|
end
|
||||||
|
|
||||||
def not_found_error
|
|
||||||
@response = { code: 2303, message: 'Object does not exist' }
|
|
||||||
render(json: @response, status: :not_found)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -68,9 +68,7 @@ module Repp
|
||||||
|
|
||||||
def set_authorized_domain
|
def set_authorized_domain
|
||||||
@epp_errors ||= []
|
@epp_errors ||= []
|
||||||
h = {}
|
@domain = domain_from_url_hash
|
||||||
h[transfer_info_params[:id].match?(/\A[0-9]+\z/) ? :id : :name] = transfer_info_params[:id]
|
|
||||||
@domain = Domain.find_by!(h)
|
|
||||||
|
|
||||||
return if @domain.transfer_code.eql?(request.headers['Auth-Code'])
|
return if @domain.transfer_code.eql?(request.headers['Auth-Code'])
|
||||||
|
|
||||||
|
@ -78,6 +76,13 @@ module Repp
|
||||||
handle_errors
|
handle_errors
|
||||||
end
|
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
|
def limit
|
||||||
index_params[:limit] || 200
|
index_params[:limit] || 200
|
||||||
end
|
end
|
||||||
|
|
|
@ -37,4 +37,17 @@ class ReppV1DomainsTransferInfoTest < ActionDispatch::IntegrationTest
|
||||||
assert_equal 'Authorization error', json[:message]
|
assert_equal 'Authorization error', json[:message]
|
||||||
assert_empty json[:data]
|
assert_empty json[:data]
|
||||||
end
|
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
|
end
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue