From 678fd29c09d24dd81786951d4088c6df7989cf70 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andres=20Keskk=C3=BCla?= Date: Thu, 28 Aug 2014 12:53:37 +0300 Subject: [PATCH 1/4] PostalInfo type checking for contact create --- app/helpers/epp/contacts_helper.rb | 10 ++++------ app/models/address.rb | 17 +++++++++++++++++ config/locales/en.yml | 2 ++ spec/support/epp_contact_xml_builder.rb | 2 +- 4 files changed, 24 insertions(+), 7 deletions(-) diff --git a/app/helpers/epp/contacts_helper.rb b/app/helpers/epp/contacts_helper.rb index 481bd564e..955cb364c 100644 --- a/app/helpers/epp/contacts_helper.rb +++ b/app/helpers/epp/contacts_helper.rb @@ -48,14 +48,12 @@ module Epp ## CREATE def validate_contact_create_request @ph = params_hash['epp']['command']['create']['create'] - xml_attrs_present?(@ph, [%w(id), - %w(authInfo pw), - %w(postalInfo)]) + xml_attrs_present?(@ph, [%w(id), %w(authInfo pw), %w(postalInfo)]) + return epp_errors.empty? unless @ph['postalInfo'].is_a?(Hash) || @ph['postalInfo'].is_a?(Array) - xml_attrs_array_present?(@ph['postalInfo'], [%w(name), - %w(addr city), - %w(addr cc)]) + (epp_errors << Address.validate_postal_info_types(parsed_frame)).flatten! + xml_attrs_array_present?(@ph['postalInfo'], [%w(name), %w(addr city), %w(addr cc)]) end ## UPDATE diff --git a/app/models/address.rb b/app/models/address.rb index 6fe586900..bd80eea9a 100644 --- a/app/models/address.rb +++ b/app/models/address.rb @@ -14,6 +14,23 @@ class Address < ActiveRecord::Base # validates_inclusion_of :type, in: TYPES class << self + + def validate_postal_info_types(parsed_frame) + errors, used = [], [] + + parsed_frame.css('postalInfo').each do |pi| + attr = pi.attributes['type'].try(:value) + errors << { code: 2003, msg: I18n.t('errors.messages.attr_missing', key: 'type')} and next unless attr + if !TYPES.include?(attr) + errors << { code: 2005, msg: I18n.t('errors.messages.invalid_type'), value: { obj: 'type', val: attr }} + next + end + errors << { code: 2005, msg: I18n.t('errors.messages.repeating_postal_info') } and next if used.include?(attr) + used << attr + end + errors + end + def extract_attributes(ah) address_hash = {} [ah].flatten.each do |pi| diff --git a/config/locales/en.yml b/config/locales/en.yml index 69c8c1a21..9ffeab2c6 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -98,6 +98,8 @@ en: epp_exp_dates_do_not_match: 'Given and current expire dates do not match' epp_registrant_not_found: 'Registrant not found' required_parameter_missing: 'Required parameter missing: %{key}' + attr_missing: 'Required parameter missing: %{key}' + repeating_postal_info: 'Only one of each postal info types may be provided' setting_groups: codes: diff --git a/spec/support/epp_contact_xml_builder.rb b/spec/support/epp_contact_xml_builder.rb index ba5f656ef..6ee409612 100644 --- a/spec/support/epp_contact_xml_builder.rb +++ b/spec/support/epp_contact_xml_builder.rb @@ -36,7 +36,7 @@ module EppContactXmlBuilder xml.tag!('contact:create', 'xmlns:contact' => 'urn:ietf:params:xml:ns:contact-1.0') do xml.tag!('contact:id', xml_params[:id], 'sh8013') unless xml_params[:id] == false unless xml_params[:postalInfo] == [false] - xml.tag!('contact:postalInfo') do + xml.tag!('contact:postalInfo', type: 'int') do xml.tag!('contact:name', ( xml_params[:name] || 'Sillius Soddus')) unless xml_params[:name] == false xml.tag!('contact:org', ( xml_params[:org_name] || 'Example Inc.')) unless xml_params[:org_name] == false unless xml_params[:addr] == [false] From 1218288a85d5be08d913eea36392a47c6767098f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andres=20Keskk=C3=BCla?= Date: Thu, 28 Aug 2014 14:04:57 +0300 Subject: [PATCH 2/4] Tweaked rubocop and guard --- .rubocop.yml | 7 +++++++ Guardfile | 9 ++++----- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index 5557d7814..067c96f2a 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -2,8 +2,15 @@ AllCops: RunRailsCops: true Exclude: + - 'Guardfile' + # stuff generated by AR and rails - 'db/schema.rb' - 'db/migrate/*' + # spring generated stuff + - 'bin/*' + # epp support files until 'complexity issues' will be solved + - 'spec/support/epp.rb' + - 'spec/support/epp_contact_xml_builder.rb' Metrics/LineLength: Max: 120 diff --git a/Guardfile b/Guardfile index 065ffb602..7b9975def 100644 --- a/Guardfile +++ b/Guardfile @@ -24,9 +24,8 @@ group :red_green_refactor, halt_on_fail:true do watch(%r{^spec/acceptance/steps/(.+)_steps\.rb$}) { |m| Dir[File.join("**/#{m[1]}.feature")][0] || 'spec/acceptance' } end - # Disabled rubocop in guard until old offenses are removed to reduce visual clutter - # guard :rubocop do - # watch(%r{.+\.rb$}) - # watch(%r{(?:.+/)?\.rubocop\.yml$}) { |m| File.dirname(m[0]) } - # end + guard :rubocop do + watch(%r{.+\.rb$}) + watch(%r{(?:.+/)?\.rubocop\.yml$}) { |m| File.dirname(m[0]) } + end end From 57b500887246e87f93de8418864319477455d87f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andres=20Keskk=C3=BCla?= Date: Thu, 28 Aug 2014 14:39:31 +0300 Subject: [PATCH 3/4] Added missing translation --- config/locales/en.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/config/locales/en.yml b/config/locales/en.yml index 9ffeab2c6..6f229c2b2 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -100,6 +100,7 @@ en: required_parameter_missing: 'Required parameter missing: %{key}' attr_missing: 'Required parameter missing: %{key}' repeating_postal_info: 'Only one of each postal info types may be provided' + invalid_type: 'PostalInfo type is invalid' setting_groups: codes: From bb6b0610be2dff95ca01870a51fe2e01e5141cfc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andres=20Keskk=C3=BCla?= Date: Thu, 28 Aug 2014 15:12:25 +0300 Subject: [PATCH 4/4] Contact renew command returns appropriate error --- app/helpers/epp/contacts_helper.rb | 5 +++++ config/locales/en.yml | 1 + spec/epp/contact_spec.rb | 9 +++++++++ spec/epp/requests/contacts/renew.xml | 15 +++++++++++++++ 4 files changed, 30 insertions(+) create mode 100644 spec/epp/requests/contacts/renew.xml diff --git a/app/helpers/epp/contacts_helper.rb b/app/helpers/epp/contacts_helper.rb index 955cb364c..16ec4ad54 100644 --- a/app/helpers/epp/contacts_helper.rb +++ b/app/helpers/epp/contacts_helper.rb @@ -41,6 +41,11 @@ module Epp render 'epp/contacts/info' end + def renew_contact + epp_errors << { code: '2101', msg: t(:'errors.messages.unimplemented_command') } + handle_errors + end + ## HELPER METHODS private diff --git a/config/locales/en.yml b/config/locales/en.yml index 6f229c2b2..23b836474 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -101,6 +101,7 @@ en: attr_missing: 'Required parameter missing: %{key}' repeating_postal_info: 'Only one of each postal info types may be provided' invalid_type: 'PostalInfo type is invalid' + unimplemented_command: 'Unimplemented command' setting_groups: codes: diff --git a/spec/epp/contact_spec.rb b/spec/epp/contact_spec.rb index 206a4827f..2743d610a 100644 --- a/spec/epp/contact_spec.rb +++ b/spec/epp/contact_spec.rb @@ -236,5 +236,14 @@ describe 'EPP Contact', epp: true do expect(response[:msg]).to eq('Authorization error') end end + + context 'renew command' do + it 'returns 2101-unimplemented command' do + response = epp_request('contacts/renew.xml') + + expect(response[:result_code]).to eq('2101') + expect(response[:msg]).to eq('Unimplemented command') + end + end end end diff --git a/spec/epp/requests/contacts/renew.xml b/spec/epp/requests/contacts/renew.xml new file mode 100644 index 000000000..aeffaa569 --- /dev/null +++ b/spec/epp/requests/contacts/renew.xml @@ -0,0 +1,15 @@ + + + + + + info-4444 + + 2fooBAR + + + + ABC-12345 + +