From e9bffe930ed5d12a3922e19c659bb3b6e26dc782 Mon Sep 17 00:00:00 2001 From: Martin Lensment Date: Fri, 10 Jul 2015 18:23:30 +0300 Subject: [PATCH] Update error messages for invalid attributes #2746 --- app/controllers/epp_controller.rb | 27 +++++++++++++++++++++------ config/locales/en.yml | 1 + doc/application_build_doc.md | 1 + spec/epp/domain_spec.rb | 4 ++-- spec/epp/poll_spec.rb | 3 ++- 5 files changed, 27 insertions(+), 9 deletions(-) diff --git a/app/controllers/epp_controller.rb b/app/controllers/epp_controller.rb index 6a982d9be..6ec5758e5 100644 --- a/app/controllers/epp_controller.rb +++ b/app/controllers/epp_controller.rb @@ -138,7 +138,7 @@ class EppController < ApplicationController # validate legal document's type here because it may be in most of the requests @prefix = nil if element_count('extdata > legalDocument') > 0 - requires_attribute('extdata > legalDocument', 'type', values: LegalDocument::TYPES) + requires_attribute('extdata > legalDocument', 'type', values: LegalDocument::TYPES, policy: true) end handle_errors and return if epp_errors.any? @@ -188,12 +188,27 @@ class EppController < ApplicationController attribute = element[attribute_selector] - return if attribute && options[:values].include?(attribute) + unless attribute + epp_errors << { + code: '2003', + msg: I18n.t('errors.messages.required_parameter_missing', key: attribute_selector) + } + return + end - epp_errors << { - code: '2306', - msg: I18n.t('attribute_is_invalid', attribute: attribute_selector) - } + return if options[:values].include?(attribute) + + if options[:policy] + epp_errors << { + code: '2306', + msg: I18n.t('attribute_is_invalid', attribute: attribute_selector) + } + else + epp_errors << { + code: '2004', + msg: I18n.t('parameter_value_range_error', key: attribute_selector) + } + end end def optional_attribute(element_selector, attribute_selector, options) diff --git a/config/locales/en.yml b/config/locales/en.yml index 5c2bcd344..da31282ad 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -867,3 +867,4 @@ en: invalid_yaml: 'Invalid YAML' reserved_pw: 'Reserved pw' no_transfers_found: 'No transfers found' + parameter_value_range_error: 'Parameter value range error: %{key}' diff --git a/doc/application_build_doc.md b/doc/application_build_doc.md index 156d4c542..3056b1992 100644 --- a/doc/application_build_doc.md +++ b/doc/application_build_doc.md @@ -16,6 +16,7 @@ Application build and update For production you probably would like to create databases to your locale, example: create database registry_production owner registry encoding 'UTF-8' LC_COLLATE 'et_EE.utf8' LC_CTYPE 'et_EE.utf8' template template0; + create extension hstore; Deploy overview: (database schema should be loaded and seeds should be present) diff --git a/spec/epp/domain_spec.rb b/spec/epp/domain_spec.rb index c19c9cbff..2885b1a16 100644 --- a/spec/epp/domain_spec.rb +++ b/spec/epp/domain_spec.rb @@ -1437,8 +1437,8 @@ describe 'EPP Domain', epp: true do it 'returns an error for incorrect op attribute' do response = epp_plain_request(domain_transfer_xml({}, 'bla'), validate_input: false) - response[:result_code].should == '2306' - response[:msg].should == 'Attribute is invalid: op' + response[:msg].should == 'Parameter value range error: op' + response[:result_code].should == '2004' end it 'creates new pw after successful transfer' do diff --git a/spec/epp/poll_spec.rb b/spec/epp/poll_spec.rb index 7442ff21f..aceb22c3b 100644 --- a/spec/epp/poll_spec.rb +++ b/spec/epp/poll_spec.rb @@ -87,7 +87,8 @@ describe 'EPP Poll', epp: true do }) response = epp_plain_request(xml, validate_input: false) - response[:msg].should == 'Attribute is invalid: op' + response[:msg].should == 'Parameter value range error: op' + response[:result_code].should == '2004' end it 'dequeues multiple messages' do