diff --git a/app/controllers/epp/errors_controller.rb b/app/controllers/epp/errors_controller.rb index ab2e00b75..da1e27a9e 100644 --- a/app/controllers/epp/errors_controller.rb +++ b/app/controllers/epp/errors_controller.rb @@ -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 diff --git a/app/models/epp/response/result/code.rb b/app/models/epp/response/result/code.rb index 10edf0a35..f2b1ccd3b 100644 --- a/app/models/epp/response/result/code.rb +++ b/app/models/epp/response/result/code.rb @@ -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 diff --git a/config/routes.rb b/config/routes.rb index 43cced0a0..0db226cf1 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -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' diff --git a/lib/epp_constraint.rb b/lib/epp_constraint.rb index f288abc35..a0ad72719 100644 --- a/lib/epp_constraint.rb +++ b/lib/epp_constraint.rb @@ -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 diff --git a/test/integration/epp/base_test.rb b/test/integration/epp/base_test.rb index c29d8cfb4..56ea3f2e8 100644 --- a/test/integration/epp/base_test.rb +++ b/test/integration/epp/base_test.rb @@ -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 + + + + + + #{domains(:shop).name} + + + + + 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 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 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 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 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 diff --git a/test/integration/epp/domain/base_test.rb b/test/integration/epp/domain/base_test.rb index f19fc61ba..e8c905062 100644 --- a/test/integration/epp/domain/base_test.rb +++ b/test/integration/epp/domain/base_test.rb @@ -15,8 +15,27 @@ class EppDomainBaseTest < EppTestCase 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 + + + + + + non-existent.test + + + + + XML + post epp_info_path, params: { frame: request_xml }, + headers: { 'HTTP_COOKIE' => 'session=api_bestnames' } + + assert_epp_response :wrong_schema + end end diff --git a/test/integration/registrar_area/xml_consoles_test.rb b/test/integration/registrar_area/xml_consoles_test.rb index 3d3a617f9..442e6f2c0 100644 --- a/test/integration/registrar_area/xml_consoles_test.rb +++ b/test/integration/registrar_area/xml_consoles_test.rb @@ -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 diff --git a/test/models/epp/response/result/code_test.rb b/test/models/epp/response/result/code_test.rb index 184a18438..a78c92d3a 100644 --- a/test/models/epp/response/result/code_test.rb +++ b/test/models/epp/response/result/code_test.rb @@ -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 diff --git a/test/system/registrar_area/xml_consoles_test.rb b/test/system/registrar_area/xml_consoles_test.rb index 836498e46..6fe855a5b 100644 --- a/test/system/registrar_area/xml_consoles_test.rb +++ b/test/system/registrar_area/xml_consoles_test.rb @@ -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 - + - + auction.test @@ -33,5 +30,4 @@ class RegistrarAreaXmlConsolesTest < ApplicationSystemTestCase XML end - -end \ No newline at end of file +end