diff --git a/app/controllers/epp/base_controller.rb b/app/controllers/epp/base_controller.rb index 205b7f844..99c0ead35 100644 --- a/app/controllers/epp/base_controller.rb +++ b/app/controllers/epp/base_controller.rb @@ -62,17 +62,13 @@ module Epp return if %w[hello error].include?(params[:action]) schema.validate(params[:nokogiri_frame]).each do |error| epp_errors << { - code: error_code(error), + code: 2001, msg: error } end handle_errors and return if epp_errors.any? end - def error_code(error) - error.str1.present? && error.str1.size > LegalDocument::MAX_BODY_SIZE ? 2306 : 2001 - end - def schema EPP_ALL_SCHEMA end diff --git a/app/models/legal_document.rb b/app/models/legal_document.rb index 24b965996..eba250991 100644 --- a/app/models/legal_document.rb +++ b/app/models/legal_document.rb @@ -21,14 +21,19 @@ class LegalDocument < ApplicationRecord def epp_code_map { - '2306' => [ - [:body, :length] - ] + '2306' => [ + %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 97c968996..f5800127e 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: legalDocument size should be more than 3kB' + length_less_than: 'Parameter value policy error: legalDocument size should be less than 8mB' attributes: diff --git a/test/integration/epp/domain/create/base_test.rb b/test/integration/epp/domain/create/base_test.rb index 5308de519..5069ddf41 100644 --- a/test/integration/epp/domain/create/base_test.rb +++ b/test/integration/epp/domain/create/base_test.rb @@ -82,7 +82,7 @@ class EppDomainCreateBaseTest < EppTestCase contact = contacts(:john) registrant = contact.becomes(Registrant) - bignum_legaldoc = 't' * (LegalDocument::MAX_BODY_SIZE + 1) + bignum_legaldoc = Base64.encode64('t' * (LegalDocument::MAX_BODY_SIZE + 1)).gsub(/\n/,"") request_xml = <<-XML @@ -109,6 +109,8 @@ class EppDomainCreateBaseTest < EppTestCase end assert_epp_response :parameter_value_policy_error + error_description = 'legalDocument size should be less than 8mB' + assert response.body.include? error_description end def test_upper_limit_of_value_legal_document