Story #107192666 - bug fix fd4b2debb2, refactor, support secDNS:all

This commit is contained in:
Matt Farnsworth 2015-11-14 23:40:45 +02:00
parent 035111e130
commit 6fcf72a8e7

View file

@ -314,8 +314,31 @@ class Epp::Domain < Domain
# rubocop: disable Metrics/PerceivedComplexity # rubocop: disable Metrics/PerceivedComplexity
# rubocop: disable Metrics/CyclomaticComplexity # rubocop: disable Metrics/CyclomaticComplexity
def dnskeys_attrs(frame, action) def dnskeys_attrs(frame, action)
return [] if frame.empty? keys = []
keys = DnsSecKeys.new(self).values frame return keys if frame.blank?
if frame.xpath('dnsSec:all').present?
# support delete all or all of
else
inf_data = DnsSecKeys.new(frame)
if Setting.key_data_allowed
if inf_data.ds_data.present?
errors.add(:base, :ds_data_not_allowed)
return
else
keys = inf_data.key_data
end
end
if Setting.ds_data_allowed
if inf_data.key_data.present?
errors.add(:base, :key_data_not_allowed)
return
else
keys = inf_data.ds_data
end
end
end
if action == 'rem' if action == 'rem'
to_destroy = [] to_destroy = []
keys.each do |x| keys.each do |x|
@ -341,20 +364,22 @@ class Epp::Domain < Domain
# rubocop: enable Metrics/CyclomaticComplexity # rubocop: enable Metrics/CyclomaticComplexity
class DnsSecKeys class DnsSecKeys
def initialize(domain) def initialize(frame)
@domain = domain @key_data = []
@ds_data = []
if frame.css('dsData').present?
ds_data_from frame
end
frame.css('keyData').each do |key|
@key_data.append key_data_from(key)
end
end end
def values(frame) attr_reader :key_data
if Setting.key_data_allowed attr_reader :ds_data
@domain.errors.add(:base, :ds_data_not_allowed) if frame.css('dsData').present?
return key_data_from frame def error
end ds_data.present? && key_data.present?
if Setting.ds_data_allowed
@domain.errors.add(:base, :key_data_not_allowed) if frame.css('keyData').present?
return ds_data_from frame
end
[]
end end
private private
@ -369,15 +394,15 @@ class Epp::Domain < Domain
def xm_copy(frame, map) def xm_copy(frame, map)
result = {} result = {}
map.each do |key, value| map.each do |key, elem|
result[key] = frame.css(value).first.try(:text) # content validation might happen later in Dnskey, if we get that far; or not. TODO: check handling
result[key] = frame.css(elem).first.try(:text)
end end
result result
end end
# frame requires NodeSet with direct children of keyData def key_data_from(frame)
def key_data(frame) result = xm_copy frame, KEY_INTERFACE
result = xm_copy frame.css('keyData'), KEY_INTERFACE
# TODO: can these defaults go where they belong? # TODO: can these defaults go where they belong?
result.merge({ result.merge({
ds_alg: 3, ds_alg: 3,
@ -385,26 +410,14 @@ class Epp::Domain < Domain
}) })
end end
# get all top level dsData from NodeSet
def ds_data_from(frame) def ds_data_from(frame)
result = []
frame.css('dsData').each do |ds_data| frame.css('dsData').each do |ds_data|
key = ds_data.css('keyData') key = ds_data.css('keyData')
ds = xm_copy ds_data, DS_INTERFACE ds = xm_copy ds_data, DS_INTERFACE
ds.merge! (key_data key) if key.present? ds.merge! (key_data_from key) if key.present?
result << ds @ds_data << ds
end end
result
end end
def key_data_from(frame)
result = []
frame.css('keyData').each do |key|
result << key_data(key)
end
result
end
end end