Start refactoring params_hash out of domains

This commit is contained in:
Martin Lensment 2015-01-22 15:14:55 +02:00
parent fe883f4e2e
commit 64183c1dd8
3 changed files with 17 additions and 10 deletions

View file

@ -116,23 +116,25 @@ class Epp::DomainsController < EppController
private
def validate_info
@ph = params_hash['epp']['command']['info']['info']
xml_attrs_present?(@ph, [['name']])
@prefix = 'info > info >'
epp_request_valid?('name')
end
def validate_check
@prefix = 'check > check >'
epp_request_valid?('name')
end
def validate_create
# TODO: Verify contact presence if registrant is juridical
ret = epp_request_valid?('name', 'ns', 'registrant', 'extension > extdata > legalDocument', 'ns > hostAttr')
if params[:parsed_frame].css('dsData').count > 0 && params[:parsed_frame].css('create > keyData').count > 0
epp_errors << { code: '2306', msg: I18n.t('ds_data_and_key_data_must_not_exists_together') }
ret = false
end
ret
@prefix = 'create > create >'
epp_request_valid?('name', 'ns', 'registrant', 'ns > hostAttr')
@prefix = nil
epp_request_valid?('extension > extdata > legalDocument')
end
def validate_renew

View file

@ -58,12 +58,14 @@ class EppController < ApplicationController
def validate_request
validation_method = "validate_#{params[:action]}"
return unless respond_to?(validation_method, true)
handle_errors and return unless send(validation_method)
send(validation_method)
handle_errors and return if epp_errors.any?
end
def epp_request_valid?(*selectors)
selectors.each do |selector|
el = params[:parsed_frame].css(selector).first
full_selector = [@prefix, selector].join(' ')
el = params[:parsed_frame].css(full_selector).first
epp_errors << {
code: '2003',
msg: I18n.t('errors.messages.required_parameter_missing', key: el.try(:name) || selector)

View file

@ -80,7 +80,10 @@ describe 'EPP Domain', epp: true do
expect(response[:results][1][:msg]).to eq('Required parameter missing: registrant')
expect(response[:results][2][:result_code]).to eq('2003')
expect(response[:results][2][:msg]).to eq('Required parameter missing: extension > extdata > legalDocument')
expect(response[:results][2][:msg]).to eq('Required parameter missing: ns > hostAttr')
expect(response[:results][3][:result_code]).to eq('2003')
expect(response[:results][3][:msg]).to eq('Required parameter missing: extension > extdata > legalDocument')
end
context 'with citizen as an owner' do