Introduce 'optional' validator to epp controllers

This commit is contained in:
Martin Lensment 2015-01-23 13:08:35 +02:00
parent 3a529135ea
commit e6b36c409d
6 changed files with 96 additions and 16 deletions

View file

@ -21,18 +21,9 @@ class Epp::KeyrelaysController < EppController
'authInfo', 'authInfo > pw'
)
optional 'expiry > relative', duration_iso8601: true
optional 'expiry > absolute', date_time_iso8601: true
exactly_one_of 'expiry > relative', 'expiry > absolute'
begin
abs_datetime = params[:parsed_frame].css('absolute').text
abs_datetime = DateTime.parse(abs_datetime) if abs_datetime.present?
rescue => _e
epp_errors << {
code: '2005',
msg: I18n.t('unknown_expiry_absolute_pattern'),
value: { obj: 'expiry_absolute', val: abs_datetime }
}
end
end
# rubocop: enable Metrics/PerceivedComplexity
# rubocop: enable Metrics/CyclomaticComplexity

View file

@ -92,6 +92,19 @@ class EppController < ApplicationController
}
end
def optional(selector, *validations)
full_selector = [@prefix, selector].join(' ')
el = params[:parsed_frame].css(full_selector).first
return unless el && el.text.present?
value = el.text
validations.each do |x|
validator = "#{x.first[0]}_validator".camelize.constantize
err = validator.validate_epp(selector.split(' ').last, value)
epp_errors << err if err
end
end
def xml_attrs_present?(ph, attributes) # TODO: THIS IS DEPRECATED AND WILL BE REMOVED IN FUTURE
attributes.each do |x|
epp_errors << {