mirror of
https://github.com/internetee/registry.git
synced 2025-07-21 10:16:01 +02:00
Merge pull request #1952 from internetee/html-error-returned-for-invalid-epp-xml-request
added errors handler
This commit is contained in:
commit
e3edf78aa3
4 changed files with 30 additions and 3 deletions
|
@ -23,6 +23,8 @@ module Epp
|
||||||
rescue_from ActiveRecord::RecordNotFound, with: :respond_with_object_does_not_exist_error
|
rescue_from ActiveRecord::RecordNotFound, with: :respond_with_object_does_not_exist_error
|
||||||
before_action :set_paper_trail_whodunnit
|
before_action :set_paper_trail_whodunnit
|
||||||
|
|
||||||
|
skip_before_action :validate_against_schema
|
||||||
|
|
||||||
protected
|
protected
|
||||||
|
|
||||||
def respond_with_command_failed_error(exception)
|
def respond_with_command_failed_error(exception)
|
||||||
|
@ -103,7 +105,7 @@ module Epp
|
||||||
@errors += obj.errors[:epp_errors]
|
@errors += obj.errors[:epp_errors]
|
||||||
end
|
end
|
||||||
|
|
||||||
if params[:parsed_frame].at_css('update')
|
if params[:parsed_frame]&.at_css('update')
|
||||||
@errors.each_with_index do |errors, index|
|
@errors.each_with_index do |errors, index|
|
||||||
if errors[:code] == '2304' &&
|
if errors[:code] == '2304' &&
|
||||||
errors[:value].present? &&
|
errors[:value].present? &&
|
||||||
|
@ -113,7 +115,6 @@ module Epp
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@errors.uniq!
|
@errors.uniq!
|
||||||
|
|
||||||
render_epp_response '/epp/error'
|
render_epp_response '/epp/error'
|
||||||
|
|
|
@ -6,5 +6,10 @@ module Epp
|
||||||
epp_errors << { code: params[:code], msg: params[:msg] }
|
epp_errors << { code: params[:code], msg: params[:msg] }
|
||||||
render_epp_response '/epp/error'
|
render_epp_response '/epp/error'
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def command_handler
|
||||||
|
epp_errors << { code: '2000', msg: 'Unknown command' }
|
||||||
|
render_epp_response '/epp/error'
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -36,6 +36,7 @@ Rails.application.routes.draw do
|
||||||
|
|
||||||
post 'command/poll', to: 'polls#poll', as: 'poll', constraints: EppConstraint.new(:poll)
|
post 'command/poll', to: 'polls#poll', as: 'poll', constraints: EppConstraint.new(:poll)
|
||||||
get 'error/:command', to: 'errors#error'
|
get 'error/:command', to: 'errors#error'
|
||||||
|
get 'error', to: 'errors#command_handler'
|
||||||
end
|
end
|
||||||
|
|
||||||
namespace :repp do
|
namespace :repp do
|
||||||
|
|
|
@ -34,6 +34,26 @@ class EppBaseTest < EppTestCase
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_additional_error
|
||||||
|
get '/epp/error', params: { frame: valid_request_xml },
|
||||||
|
headers: { 'HTTP_COOKIE' => 'session=api_bestnames' }
|
||||||
|
|
||||||
|
assert_epp_response :unknown_command
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_error_with_unknown_command
|
||||||
|
invalid_xml = <<-XML
|
||||||
|
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||||
|
<epsdp xmlns="https://epp.tld.ee/schema/epp-ee-1.0.xsd">
|
||||||
|
</epp>
|
||||||
|
XML
|
||||||
|
|
||||||
|
get '/epp/error', params: { frame: invalid_xml },
|
||||||
|
headers: { 'HTTP_COOKIE' => 'session=api_bestnames' }
|
||||||
|
|
||||||
|
assert_epp_response :unknown_command
|
||||||
|
end
|
||||||
|
|
||||||
def test_validates_request_xml
|
def test_validates_request_xml
|
||||||
invalid_xml = <<-XML
|
invalid_xml = <<-XML
|
||||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||||
|
@ -43,7 +63,7 @@ class EppBaseTest < EppTestCase
|
||||||
post valid_command_path, params: { frame: invalid_xml },
|
post valid_command_path, params: { frame: invalid_xml },
|
||||||
headers: { 'HTTP_COOKIE' => 'session=api_bestnames' }
|
headers: { 'HTTP_COOKIE' => 'session=api_bestnames' }
|
||||||
|
|
||||||
assert_epp_response :syntax_error
|
assert_epp_response :required_parameter_missing
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_anonymous_user
|
def test_anonymous_user
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue