Improve EPP error handling

Fixes #539
This commit is contained in:
Artur Beljajev 2019-09-11 18:42:13 +03:00
parent 0a1405ae52
commit 77678681a6
18 changed files with 263 additions and 272 deletions

View file

@ -0,0 +1,90 @@
require 'test_helper'
class DummyEppController < Epp::BaseController
def internal_error
raise StandardError
end
end
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)
end
any_valid_epp_request_xml = <<-XML
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<epp xmlns="https://epp.tld.ee/schema/epp-ee-1.0.xsd">
<hello/>
</epp>
XML
begin
assert_difference 'ApiLog::EppLog.count' do
post '/epp/command/internal_error', { frame: any_valid_epp_request_xml },
'HTTP_COOKIE' => 'session=api_bestnames'
end
assert_epp_response :command_failed
rescue
raise
ensure
Rails.application.reload_routes!
end
end
def test_invalid_request
invalid_xml = <<-XML
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<epp xmlns="https://epp.tld.ee/schema/epp-ee-1.0.xsd">
</epp>
XML
post '/epp/command/internal_error', { frame: invalid_xml },
'HTTP_COOKIE' => 'session=api_bestnames'
assert_epp_response :syntax_error
end
def test_anonymous_user
xml_of_epp_command_that_requires_authentication = <<-XML
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<epp xmlns="https://epp.tld.ee/schema/epp-ee-1.0.xsd">
<command>
<info>
<domain:info xmlns:domain="https://epp.tld.ee/schema/domain-eis-1.0.xsd">
<domain:name>#{domains(:shop).name}</domain:name>
</domain:info>
</info>
</command>
</epp>
XML
post '/epp/command/info', { frame: xml_of_epp_command_that_requires_authentication },
'HTTP_COOKIE' => 'session=non-existent'
assert_epp_response :authorization_error
end
def test_non_authorized_user
session = epp_sessions(:api_bestnames)
user = session.user
user.update!(roles: [ApiUser::BILLING])
assert user.cannot?(:info, Domain)
xml_of_epp_command_that_requires_authorization = <<-XML
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<epp xmlns="https://epp.tld.ee/schema/epp-ee-1.0.xsd">
<command>
<info>
<domain:info xmlns:domain="https://epp.tld.ee/schema/domain-eis-1.0.xsd">
<domain:name>#{domains(:shop).name}</domain:name>
</domain:info>
</info>
</command>
</epp>
XML
post '/epp/command/info', { frame: xml_of_epp_command_that_requires_authorization },
'HTTP_COOKIE' => "session=#{session.session_id}"
assert_epp_response :authorization_error
end
end

View file

@ -0,0 +1,21 @@
require 'test_helper'
class EppContactBaseTest < EppTestCase
def test_non_existent_contact
request_xml = <<-XML
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<epp xmlns="https://epp.tld.ee/schema/epp-ee-1.0.xsd">
<command>
<info>
<contact:info xmlns:contact="https://epp.tld.ee/schema/contact-ee-1.1.xsd">
<contact:id>non-existent</contact:id>
</contact:info>
</info>
</command>
</epp>
XML
post '/epp/command/info', { frame: request_xml }, 'HTTP_COOKIE' => 'session=api_bestnames'
assert_epp_response :object_does_not_exist
end
end

View file

@ -43,27 +43,6 @@ class EppContactInfoBaseTest < EppTestCase
contact: xml_schema).text
end
def test_contact_not_found
assert_nil Contact.find_by(code: 'non-existing')
request_xml = <<-XML
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<epp xmlns="https://epp.tld.ee/schema/epp-ee-1.0.xsd">
<command>
<info>
<contact:info xmlns:contact="https://epp.tld.ee/schema/contact-ee-1.1.xsd">
<contact:id>non-existing</contact:id>
</contact:info>
</info>
</command>
</epp>
XML
post '/epp/command/info', { frame: request_xml }, 'HTTP_COOKIE' => 'session=api_bestnames'
assert_epp_response :object_does_not_exist
end
private
def xml_schema

View file

@ -133,32 +133,6 @@ class EppContactUpdateBaseTest < EppTestCase
assert_no_emails
end
def test_non_existing_contact
assert_nil Contact.find_by(code: 'non-existing')
request_xml = <<-XML
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<epp xmlns="https://epp.tld.ee/schema/epp-ee-1.0.xsd">
<command>
<update>
<contact:update xmlns:contact="https://epp.tld.ee/schema/contact-ee-1.1.xsd">
<contact:id>non-existing</contact:id>
<contact:chg>
<contact:postalInfo>
<contact:name>any</contact:name>
</contact:postalInfo>
</contact:chg>
</contact:update>
</update>
</command>
</epp>
XML
post '/epp/command/update', { frame: request_xml }, 'HTTP_COOKIE' => 'session=api_bestnames'
assert_epp_response :object_does_not_exist
end
private
def make_contact_free_of_domains_where_it_acts_as_a_registrant(contact)

View file

@ -0,0 +1,21 @@
require 'test_helper'
class EppDomainBaseTest < EppTestCase
def test_non_existent_domain
request_xml = <<-XML
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<epp xmlns="https://epp.tld.ee/schema/epp-ee-1.0.xsd">
<command>
<info>
<domain:info xmlns:domain="https://epp.tld.ee/schema/domain-eis-1.0.xsd">
<domain:name>non-existent.test</domain:name>
</domain:info>
</info>
</command>
</epp>
XML
post '/epp/command/info', { frame: request_xml }, 'HTTP_COOKIE' => 'session=api_bestnames'
assert_epp_response :object_does_not_exist
end
end

View file

@ -207,30 +207,4 @@ class EppDomainDeleteBaseTest < EppTestCase
assert_epp_response :object_status_prohibits_operation
end
def test_domain_not_found
assert_nil Domain.find_by(name: 'non-existing.test')
request_xml = <<-XML
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<epp xmlns="https://epp.tld.ee/schema/epp-ee-1.0.xsd">
<command>
<delete>
<domain:delete xmlns:domain="https://epp.tld.ee/schema/domain-eis-1.0.xsd">
<domain:name>non-existing.test</domain:name>
</domain:delete>
</delete>
<extension>
<eis:extdata xmlns:eis="https://epp.tld.ee/schema/eis-1.0.xsd">
<eis:legalDocument type="pdf">dGVzdCBmYWlsCg==</eis:legalDocument>
</eis:extdata>
</extension>
</command>
</epp>
XML
post '/epp/command/delete', { frame: request_xml }, 'HTTP_COOKIE' => 'session=api_bestnames'
assert_epp_response :object_does_not_exist
end
end

View file

@ -105,25 +105,4 @@ class EppDomainInfoBaseTest < EppTestCase
assert_nil response_xml.at_xpath('//domain:authInfo/domain:pw',
'domain' => 'https://epp.tld.ee/schema/domain-eis-1.0.xsd')
end
def test_returns_not_found_error_when_domain_is_not_registered
assert DNS::DomainName.new('not-registered.test').not_registered?
request_xml = <<-XML
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<epp xmlns="https://epp.tld.ee/schema/epp-ee-1.0.xsd">
<command>
<info>
<domain:info xmlns:domain="https://epp.tld.ee/schema/domain-eis-1.0.xsd">
<domain:name>not-registered.test</domain:name>
</domain:info>
</info>
</command>
</epp>
XML
post '/epp/command/info', { frame: request_xml }, 'HTTP_COOKIE' => 'session=api_bestnames'
assert_epp_response :object_does_not_exist
end
end

View file

@ -1,25 +0,0 @@
require 'test_helper'
class EppDomainTransferBaseTest < EppTestCase
def test_non_existent_domain
request_xml = <<-XML
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<epp xmlns="https://epp.tld.ee/schema/epp-ee-1.0.xsd">
<command>
<transfer op="request">
<domain:transfer xmlns:domain="https://epp.tld.ee/schema/domain-eis-1.0.xsd">
<domain:name>non-existent.test</domain:name>
<domain:authInfo>
<domain:pw>any</domain:pw>
</domain:authInfo>
</domain:transfer>
</transfer>
</command>
</epp>
XML
post '/epp/command/transfer', { frame: request_xml }, { 'HTTP_COOKIE' => 'session=api_goodnames' }
assert_epp_response :object_does_not_exist
end
end