mirror of
https://github.com/internetee/registry.git
synced 2025-07-03 01:33:36 +02:00
Validate keyrelay relative and absolute in controller
This commit is contained in:
parent
51978ef38a
commit
938bd75dfa
5 changed files with 28 additions and 4 deletions
|
@ -14,7 +14,14 @@ class Epp::KeyrelaysController < EppController
|
|||
private
|
||||
|
||||
def validate_keyrelay
|
||||
epp_request_valid?('pubKey', 'flags', 'protocol', 'alg', 'name', 'pw')
|
||||
@prefix = 'keyrelay >'
|
||||
epp_request_valid?(
|
||||
'name',
|
||||
'keyData', 'keyData > pubKey', 'keyData > flags', 'keyData > protocol', 'keyData > alg',
|
||||
'authInfo', 'authInfo > pw'
|
||||
)
|
||||
|
||||
exactly_one_of 'expiry > relative', 'expiry > absolute'
|
||||
|
||||
begin
|
||||
abs_datetime = params[:parsed_frame].css('absolute').text
|
||||
|
@ -26,8 +33,6 @@ class Epp::KeyrelaysController < EppController
|
|||
value: { obj: 'expiry_absolute', val: abs_datetime }
|
||||
}
|
||||
end
|
||||
|
||||
epp_errors.empty?
|
||||
end
|
||||
# rubocop: enable Metrics/PerceivedComplexity
|
||||
# rubocop: enable Metrics/CyclomaticComplexity
|
||||
|
|
|
@ -75,6 +75,23 @@ class EppController < ApplicationController
|
|||
epp_errors.empty?
|
||||
end
|
||||
|
||||
# let's follow grape's validations: https://github.com/intridea/grape/#parameter-validation-and-coercion
|
||||
def exactly_one_of(*selectors)
|
||||
present_count = 0
|
||||
selectors.each do |selector|
|
||||
full_selector = [@prefix, selector].join(' ')
|
||||
el = params[:parsed_frame].css(full_selector).first
|
||||
present_count += 1 if el && el.text.present?
|
||||
end
|
||||
|
||||
return if present_count == 1
|
||||
|
||||
epp_errors << {
|
||||
code: '2003',
|
||||
msg: I18n.t(:exactly_one_parameter_required, params: selectors.join(' or '))
|
||||
}
|
||||
end
|
||||
|
||||
def xml_attrs_present?(ph, attributes) # TODO: THIS IS DEPRECATED AND WILL BE REMOVED IN FUTURE
|
||||
attributes.each do |x|
|
||||
epp_errors << {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue