diff --git a/app/models/legal_document.rb b/app/models/legal_document.rb index 377a9fdde..07c50c5dc 100644 --- a/app/models/legal_document.rb +++ b/app/models/legal_document.rb @@ -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 diff --git a/config/locales/en.yml b/config/locales/en.yml index 1d5a469a2..ac31d19e9 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -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: diff --git a/test/integration/epp/domain/create/base_test.rb b/test/integration/epp/domain/create/base_test.rb index 35ef38179..59a8ddf77 100644 --- a/test/integration/epp/domain/create/base_test.rb +++ b/test/integration/epp/domain/create/base_test.rb @@ -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 + + + + + + #{name} + #{registrant.code} + + + + + #{'test' * 2} + + + + + 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 + + + + + + #{name} + #{registrant.code} + + + + + #{bignum_legaldoc} + + + + + 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 + + + + + + #{name} + #{registrant.code} + + + + + #{bignum_legaldoc} + + + + + 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')