Merge pull request #1881 from internetee/1880-returns-command-failed-for-transfer-request-with-invalid-legaldoc

Fix error message on too big LegalDoc size in epp
This commit is contained in:
Timo Võhmar 2021-04-30 18:15:19 +03:00 committed by GitHub
commit 51e5439fa0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 114 additions and 5 deletions

View file

@ -1,6 +1,7 @@
class LegalDocument < ApplicationRecord
include EppErrors
MIN_BODY_SIZE = (1.37 * 3.kilobytes).ceil
MAX_BODY_SIZE = 8.megabytes
if ENV['legal_document_types'].present?
TYPES = ENV['legal_document_types'].split(',').map(&:strip)
@ -20,14 +21,19 @@ class LegalDocument < ApplicationRecord
def epp_code_map
{
'2306' => [
[:body, :length]
'2308' => [
%i[body length_more_than],
%i[body length_less_than],
]
}
end
def val_body_length
errors.add(:body, :length) if body.nil? || body.size < MIN_BODY_SIZE
if body.nil? || body.size < MIN_BODY_SIZE
errors.add(:body, :length_more_than)
elsif body.size > MAX_BODY_SIZE
errors.add(:body, :length_less_than)
end
end
def save_to_filesystem

View file

@ -138,7 +138,8 @@ en:
legal_document:
attributes:
body:
length: 'Parameter value policy error: legalDocument size should be more than 3kB'
length_more_than: 'Parameter value policy error: Legaldoc size is less than minimum allowed size of 3kB'
length_less_than: 'Parameter value policy error: Legaldoc size exceeds maximum allowed size of 8mB'
attributes:

View file

@ -46,6 +46,108 @@ class EppDomainCreateBaseTest < EppTestCase
assert_epp_response :parameter_value_syntax_error
end
def test_too_small_legal_document
name = "new.#{dns_zones(:one).origin}"
contact = contacts(:john)
registrant = contact.becomes(Registrant)
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>
<create>
<domain:create xmlns:domain="https://epp.tld.ee/schema/domain-eis-1.0.xsd">
<domain:name>#{name}</domain:name>
<domain:registrant>#{registrant.code}</domain:registrant>
</domain:create>
</create>
<extension>
<eis:extdata xmlns:eis="https://epp.tld.ee/schema/eis-1.0.xsd">
<eis:legalDocument type="pdf">#{'test' * 2}</eis:legalDocument>
</eis:extdata>
</extension>
</command>
</epp>
XML
assert_no_difference 'Domain.count' do
post epp_create_path, params: { frame: request_xml },
headers: { 'HTTP_COOKIE' => 'session=api_bestnames' }
end
assert_epp_response :data_management_policy_violation
end
def test_too_big_legal_document
name = "new.#{dns_zones(:one).origin}"
contact = contacts(:john)
registrant = contact.becomes(Registrant)
bignum_legaldoc = Base64.encode64('t' * (LegalDocument::MAX_BODY_SIZE + 1)).gsub(/\n/,"")
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>
<create>
<domain:create xmlns:domain="https://epp.tld.ee/schema/domain-eis-1.0.xsd">
<domain:name>#{name}</domain:name>
<domain:registrant>#{registrant.code}</domain:registrant>
</domain:create>
</create>
<extension>
<eis:extdata xmlns:eis="https://epp.tld.ee/schema/eis-1.0.xsd">
<eis:legalDocument type="pdf">#{bignum_legaldoc}</eis:legalDocument>
</eis:extdata>
</extension>
</command>
</epp>
XML
assert_no_difference 'Domain.count' do
post epp_create_path, params: { frame: request_xml },
headers: { 'HTTP_COOKIE' => 'session=api_bestnames' }
end
assert_epp_response :data_management_policy_violation
error_description = 'Legaldoc size exceeds maximum allowed size of 8mB'
assert response.body.include? error_description
end
def test_upper_limit_of_value_legal_document
name = "new.#{dns_zones(:one).origin}"
contact = contacts(:john)
registrant = contact.becomes(Registrant)
bignum_legaldoc = 't' * LegalDocument::MAX_BODY_SIZE
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>
<create>
<domain:create xmlns:domain="https://epp.tld.ee/schema/domain-eis-1.0.xsd">
<domain:name>#{name}</domain:name>
<domain:registrant>#{registrant.code}</domain:registrant>
</domain:create>
</create>
<extension>
<eis:extdata xmlns:eis="https://epp.tld.ee/schema/eis-1.0.xsd">
<eis:legalDocument type="pdf">#{bignum_legaldoc}</eis:legalDocument>
</eis:extdata>
</extension>
</command>
</epp>
XML
assert_difference 'Domain.count' do
post epp_create_path, params: { frame: request_xml },
headers: { 'HTTP_COOKIE' => 'session=api_bestnames' }
end
assert_epp_response :completed_successfully
end
def test_not_registers_domain_without_legaldoc
now = Time.zone.parse('2010-07-05')