added response for wrong epp path

This commit is contained in:
Oleg Hasjanov 2021-06-10 14:16:48 +03:00
parent 5b8b18f584
commit 4cf7a103c8
9 changed files with 91 additions and 28 deletions

View file

@ -11,5 +11,10 @@ module Epp
epp_errors.add(:epp_errors, code: '2000', msg: 'Unknown command')
render_epp_response '/epp/error'
end
def wrong_schema
epp_errors.add(:epp_errors, code: '2100', msg: 'Wrong path')
render_epp_response '/epp/error'
end
end
end

View file

@ -17,6 +17,7 @@ module Epp
required_parameter_missing: 2003,
parameter_value_range_error: 2004,
parameter_value_syntax_error: 2005,
wrong_schema: 2100,
unimplemented: 2101,
billing_failure: 2104,
object_is_not_eligible_for_renewal: 2105,
@ -47,6 +48,7 @@ module Epp
2003 => 'Required parameter missing',
2004 => 'Parameter value range error',
2005 => 'Parameter value syntax error',
2100 => 'Wrong schema',
2101 => 'Unimplemented command',
2104 => 'Billing failure',
2105 => 'Object is not eligible for renewal',
@ -79,6 +81,7 @@ module Epp
def initialize(value)
value = value.to_i
raise ArgumentError, "Invalid value: #{value}" unless KEY_TO_VALUE.value?(value)
@value = value
end

View file

@ -34,6 +34,18 @@ Rails.application.routes.draw do
end
end
constraints(EppConstraint.new(:error)) do
controller('errors') do
post 'command/create', to: 'errors#wrong_schema'
post 'command/update', to: 'errors#wrong_schema'
post 'command/info', to: 'errors#wrong_schema'
post 'command/check', to: 'errors#wrong_schema'
post 'command/transfer', to: 'errors#wrong_schema'
post 'command/renew', to: 'errors#wrong_schema'
post 'command/delete', to: 'errors#wrong_schema'
end
end
post 'command/poll', to: 'polls#poll', as: 'poll', constraints: EppConstraint.new(:poll)
get 'error/:command', to: 'errors#error'
get 'error', to: 'errors#command_handler'

View file

@ -11,6 +11,8 @@ class EppConstraint
# creates parsed_frame, detects epp request object
def matches?(request)
# TODO: Maybe move this to controller to keep params clean
return redirect_to_error_controller(request) if request.params[:action] == 'wrong_schema'
request.params[:raw_frame] = request.params[:raw_frame].gsub!(/(?<=>)(.*?)(?=<)/) { |s| s.strip} if request.params[:raw_frame]
request.params[:nokogiri_frame] ||= Nokogiri::XML(request.params[:raw_frame] || request.params[:frame])
request.params[:parsed_frame] ||= request.params[:nokogiri_frame].dup.remove_namespaces!
@ -23,4 +25,9 @@ class EppConstraint
request.params[:epp_object_type] = @type
true
end
def redirect_to_error_controller(request)
request.params[:epp_object_type] = @error
true
end
end

View file

@ -18,25 +18,44 @@ class EppBaseTest < EppTestCase
def test_internal_error
Rails.application.routes.draw do
post 'epp/command/internal_error', to: 'dummy_epp#internal_error',
constraints: EppConstraint.new(:poll)
constraints: EppConstraint.new(:poll)
end
begin
assert_difference 'ApiLog::EppLog.count' do
post '/epp/command/internal_error', params: { frame: valid_request_xml },
headers: { 'HTTP_COOKIE' => 'session=api_bestnames' }
headers: { 'HTTP_COOKIE' => 'session=api_bestnames' }
end
assert_epp_response :command_failed
rescue
rescue StandardError
raise
ensure
Rails.application.reload_routes!
end
end
def test_wrong_path_xml
wrong_path_xml = <<-XML
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<epp xmlns="#{Xsd::Schema.filename(for_prefix: 'epp-ee')}">
<command>
<info>
<domain:info xmlns:domain="https://dsfs.sdf.sdf">
<domain:name>#{domains(:shop).name}</domain:name>
</domain:info>
</info>
</command>
</epp>
XML
post epp_info_path, params: { frame: wrong_path_xml },
headers: { 'HTTP_COOKIE' => 'session=api_bestnames' }
assert_epp_response :wrong_schema
end
def test_additional_error
get '/epp/error', params: { frame: valid_request_xml },
headers: { 'HTTP_COOKIE' => 'session=api_bestnames' }
headers: { 'HTTP_COOKIE' => 'session=api_bestnames' }
assert_epp_response :unknown_command
end
@ -49,7 +68,7 @@ class EppBaseTest < EppTestCase
XML
get '/epp/error', params: { frame: invalid_xml },
headers: { 'HTTP_COOKIE' => 'session=api_bestnames' }
headers: { 'HTTP_COOKIE' => 'session=api_bestnames' }
assert_epp_response :unknown_command
end
@ -61,7 +80,7 @@ class EppBaseTest < EppTestCase
</epp>
XML
post valid_command_path, params: { frame: invalid_xml },
headers: { 'HTTP_COOKIE' => 'session=api_bestnames' }
headers: { 'HTTP_COOKIE' => 'session=api_bestnames' }
assert_epp_response :required_parameter_missing
end
@ -80,7 +99,7 @@ class EppBaseTest < EppTestCase
</epp>
XML
post epp_info_path, params: { frame: xml_of_epp_command_that_requires_authentication },
headers: { 'HTTP_COOKIE' => 'session=non-existent' }
headers: { 'HTTP_COOKIE' => 'session=non-existent' }
assert_epp_response :authorization_error
end
@ -104,7 +123,7 @@ class EppBaseTest < EppTestCase
</epp>
XML
post epp_info_path, params: { frame: xml_of_epp_command_that_requires_authorization },
headers: { 'HTTP_COOKIE' => "session=#{session.session_id}" }
headers: { 'HTTP_COOKIE' => "session=#{session.session_id}" }
assert_epp_response :authorization_error
end
@ -130,7 +149,7 @@ class EppBaseTest < EppTestCase
</epp>
XML
post '/epp/command/info', params: { frame: authentication_enabled_epp_request_xml },
headers: { 'HTTP_COOKIE' => "session=#{session.session_id}" }
headers: { 'HTTP_COOKIE' => "session=#{session.session_id}" }
assert_epp_response :authorization_error
assert_nil EppSession.find_by(session_id: session.session_id)
@ -158,7 +177,7 @@ class EppBaseTest < EppTestCase
XML
post '/epp/command/info', params: { frame: authentication_enabled_epp_request_xml },
headers: { 'HTTP_COOKIE' => "session=#{session.session_id}" }
headers: { 'HTTP_COOKIE' => "session=#{session.session_id}" }
session.reload

View file

@ -15,8 +15,27 @@ class EppDomainBaseTest < EppTestCase
</epp>
XML
post epp_info_path, params: { frame: request_xml },
headers: { 'HTTP_COOKIE' => 'session=api_bestnames' }
headers: { 'HTTP_COOKIE' => 'session=api_bestnames' }
assert_epp_response :object_does_not_exist
end
def test_invalid_path
request_xml = <<-XML
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<epp xmlns="#{Xsd::Schema.filename(for_prefix: 'epp-ee')}">
<command>
<info>
<domain:info xmlns:domain="https://afdsfs.dfdf.df">
<domain:name>non-existent.test</domain:name>
</domain:info>
</info>
</command>
</epp>
XML
post epp_info_path, params: { frame: request_xml },
headers: { 'HTTP_COOKIE' => 'session=api_bestnames' }
assert_epp_response :wrong_schema
end
end

View file

@ -6,7 +6,7 @@ class RegistrarXmlConsolesIntegrationTest < ApplicationIntegrationTest
end
def test_check_schema_path
post registrar_xml_console_path, params: { payload: payload, frame: payload },
post registrar_xml_console_path, params: { frame: payload },
headers: { 'HTTP_COOKIE' => 'session=api_bestnames' }
assert_response :ok

View file

@ -15,7 +15,7 @@ class EppResponseResultCodeTest < ActiveSupport::TestCase
end
def test_invalid_code_value
invalid_code_value = 0000
invalid_code_value = 0o000
refute_includes Epp::Response::Result::Code.codes.values, invalid_code_value
e = assert_raises ArgumentError do
@ -38,6 +38,7 @@ class EppResponseResultCodeTest < ActiveSupport::TestCase
required_parameter_missing: 2003,
parameter_value_range_error: 2004,
parameter_value_syntax_error: 2005,
wrong_schema: 2100,
billing_failure: 2104,
unimplemented: 2101,
object_is_not_eligible_for_renewal: 2105,
@ -51,7 +52,7 @@ class EppResponseResultCodeTest < ActiveSupport::TestCase
data_management_policy_violation: 2308,
command_failed: 2400,
authentication_error_server_closing_connection: 2501,
session_limit_exceeded_server_closing_connection: 2502,
session_limit_exceeded_server_closing_connection: 2502
}
assert_equal codes, Epp::Response::Result::Code.codes
end
@ -70,6 +71,7 @@ class EppResponseResultCodeTest < ActiveSupport::TestCase
2003 => 'Required parameter missing',
2004 => 'Parameter value range error',
2005 => 'Parameter value syntax error',
2100 => 'Wrong schema',
2101 => 'Unimplemented command',
2104 => 'Billing failure',
2105 => 'Object is not eligible for renewal',
@ -83,7 +85,7 @@ class EppResponseResultCodeTest < ActiveSupport::TestCase
2308 => 'Data management policy violation',
2400 => 'Command failed',
2501 => 'Authentication error; server closing connection',
2502 => 'Session limit exceeded; server closing connection',
2502 => 'Session limit exceeded; server closing connection'
}
assert_equal descriptions, Epp::Response::Result::Code.default_descriptions
end

View file

@ -1,31 +1,28 @@
require 'application_system_test_case'
class RegistrarAreaXmlConsolesTest < ApplicationSystemTestCase
setup do
sign_in users(:api_bestnames)
end
# CodeRay
def test_epp_server_does_not_response
visit registrar_xml_console_path
fill_in 'payload', with: schema_example
click_on 'Send EPP Request'
visit registrar_xml_console_path
fill_in 'payload', with: schema_example
click_on 'Send EPP Request'
el = page.find('.CodeRay', visible: :all)
assert el.text.include? 'CONNECTION ERROR - Is the EPP server running?'
el = page.find('.CodeRay', visible: :all)
assert el.text.include? 'CONNECTION ERROR - Is the EPP server running?'
end
private
def schema_example
request_xml = <<~XML
<<~XML
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<epp xmlns="#{Xsd::Schema.filename(for_prefix: 'epp-ee')}">
<epp xmlns="https://epp.tld.ee/schema/epp-ee-1.0.xsd">
<command>
<check>
<domain:check xmlns:domain="#{Xsd::Schema.filename(for_prefix: 'domain-ee')}">
<domain:check xmlns:domain="https://epp.tld.ee/schema/domain-ee-1.1.xsd">
<domain:name>auction.test</domain:name>
</domain:check>
</check>
@ -33,5 +30,4 @@ class RegistrarAreaXmlConsolesTest < ApplicationSystemTestCase
</epp>
XML
end
end