Skip to content

Commit

Permalink
Merge pull request #1952 from internetee/html-error-returned-for-inva…
Browse files Browse the repository at this point in the history
…lid-epp-xml-request

added errors handler
  • Loading branch information
vohmar authored May 3, 2021
2 parents 9dbc039 + e76f8da commit e3edf78
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 3 deletions.
5 changes: 3 additions & 2 deletions app/controllers/epp/base_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ class AuthorizationError < StandardError; end
rescue_from ActiveRecord::RecordNotFound, with: :respond_with_object_does_not_exist_error
before_action :set_paper_trail_whodunnit

skip_before_action :validate_against_schema

protected

def respond_with_command_failed_error(exception)
Expand Down Expand Up @@ -103,7 +105,7 @@ def handle_errors(obj = nil)
@errors += obj.errors[:epp_errors]
end

if params[:parsed_frame].at_css('update')
if params[:parsed_frame]&.at_css('update')
@errors.each_with_index do |errors, index|
if errors[:code] == '2304' &&
errors[:value].present? &&
Expand All @@ -113,7 +115,6 @@ def handle_errors(obj = nil)
end
end
end

@errors.uniq!

render_epp_response '/epp/error'
Expand Down
5 changes: 5 additions & 0 deletions app/controllers/epp/errors_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,10 @@ def error
epp_errors << { code: params[:code], msg: params[:msg] }
render_epp_response '/epp/error'
end

def command_handler
epp_errors << { code: '2000', msg: 'Unknown command' }
render_epp_response '/epp/error'
end
end
end
1 change: 1 addition & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@

post 'command/poll', to: 'polls#poll', as: 'poll', constraints: EppConstraint.new(:poll)
get 'error/:command', to: 'errors#error'
get 'error', to: 'errors#command_handler'
end

namespace :repp do
Expand Down
22 changes: 21 additions & 1 deletion test/integration/epp/base_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,26 @@ def test_internal_error
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
invalid_xml = <<-XML
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
Expand All @@ -43,7 +63,7 @@ def test_validates_request_xml
post valid_command_path, params: { frame: invalid_xml },
headers: { 'HTTP_COOKIE' => 'session=api_bestnames' }

assert_epp_response :syntax_error
assert_epp_response :required_parameter_missing
end

def test_anonymous_user
Expand Down

0 comments on commit e3edf78

Please sign in to comment.