Validate protocol in dnskey

This commit is contained in:
Martin Lensment 2014-10-02 11:15:46 +03:00
parent f776078214
commit e7644ea69d
3 changed files with 22 additions and 8 deletions

View file

@ -4,11 +4,13 @@ class Dnskey < ActiveRecord::Base
belongs_to :domain
validate :validate_algorithm
validate :validate_protocol
def epp_code_map
{
'2005' => [
[:alg, :invalid, { value: { obj: 'alg', val: alg } }]
[:alg, :invalid, { value: { obj: 'alg', val: alg } }],
[:protocol, :invalid, { value: { obj: 'protocol', val: protocol } }],
],
'2306' => [
[:ipv4, :blank]
@ -16,10 +18,13 @@ class Dnskey < ActiveRecord::Base
}
end
def validate_algorithm
return if %w(3 5 6 7 8 252 253 254 255).include?(alg.to_s)
errors.add(:alg, :invalid)
# , format: {with: /3|5|6/, message: :alg_invalid}
end
def validate_protocol
return if %w(3).include?(protocol.to_s)
errors.add(:protocol, :invalid)
end
end

View file

@ -187,6 +187,8 @@ en:
attributes:
alg:
invalid: 'Algorithm is invalid'
protocol:
invalid: 'Protocol is invalid'
attributes:
epp_domain: &epp_domain_attributes

View file

@ -372,7 +372,7 @@ describe 'EPP Domain', epp: true do
{
dnskey: {
flags: { value: '257' },
protocol: { value: '3' },
protocol: { value: '4' },
alg: { value: '9' },
pubKey: { value: 'AwEAAddt2AkLfYGKgiEZB5SmIF8EvrjxNMH6HtxWEA4RJ9Ao6LCWheg8' }
}
@ -388,7 +388,7 @@ describe 'EPP Domain', epp: true do
{
dnskey: {
flags: { value: '256' },
protocol: { value: '3' },
protocol: { value: '5' },
alg: { value: '254' },
pubKey: { value: '841936717ae427ace63c28d04918569a841936717ae427ace63c28d0' }
}
@ -397,12 +397,19 @@ describe 'EPP Domain', epp: true do
})
response = epp_request(xml, :xml)
po response
expect(response[:results][0][:msg]).to eq('Algorithm is invalid')
expect(response[:results][0][:value]).to eq('9')
expect(response[:results][1][:msg]).to eq('Algorithm is invalid')
expect(response[:results][1][:value]).to eq('10')
po response
expect(response[:results][1][:msg]).to eq('Protocol is invalid')
expect(response[:results][1][:value]).to eq('4')
expect(response[:results][2][:msg]).to eq('Algorithm is invalid')
expect(response[:results][2][:value]).to eq('10')
expect(response[:results][3][:msg]).to eq('Protocol is invalid')
expect(response[:results][3][:value]).to eq('5')
end
end