Algorithm validation for dnskey

This commit is contained in:
Martin Lensment 2014-10-02 10:58:46 +03:00
parent 17e1668794
commit f776078214
3 changed files with 67 additions and 1 deletions

View file

@ -1,3 +1,25 @@
class Dnskey < ActiveRecord::Base class Dnskey < ActiveRecord::Base
include EppErrors
belongs_to :domain belongs_to :domain
validate :validate_algorithm
def epp_code_map
{
'2005' => [
[:alg, :invalid, { value: { obj: 'alg', val: alg } }]
],
'2306' => [
[:ipv4, :blank]
]
}
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
end end

View file

@ -183,6 +183,11 @@ en:
registrar: registrar:
blank: 'Registrar is missing' blank: 'Registrar is missing'
dnskey:
attributes:
alg:
invalid: 'Algorithm is invalid'
attributes: attributes:
epp_domain: &epp_domain_attributes epp_domain: &epp_domain_attributes
name: 'Domain name' name: 'Domain name'

View file

@ -353,7 +353,7 @@ describe 'EPP Domain', epp: true do
] ]
}) })
response = epp_request(xml, :xml) epp_request(xml, :xml)
d = Domain.first d = Domain.first
expect(d.dnskeys.pluck(:flags)).to match_array([257, 0, 256]) expect(d.dnskeys.pluck(:flags)).to match_array([257, 0, 256])
@ -365,6 +365,45 @@ describe 'EPP Domain', epp: true do
841936717ae427ace63c28d04918569a841936717ae427ace63c28d0 841936717ae427ace63c28d04918569a841936717ae427ace63c28d0
)) ))
end end
it 'does not create a domain when dnskeys are invalid' do
xml = domain_create_xml({
dnssec: [
{
dnskey: {
flags: { value: '257' },
protocol: { value: '3' },
alg: { value: '9' },
pubKey: { value: 'AwEAAddt2AkLfYGKgiEZB5SmIF8EvrjxNMH6HtxWEA4RJ9Ao6LCWheg8' }
}
},
{
dnskey: {
flags: { value: '0' },
protocol: { value: '3' },
alg: { value: '10' },
pubKey: { value: '700b97b591ed27ec2590d19f06f88bba700b97b591ed27ec2590d19f' }
}
},
{
dnskey: {
flags: { value: '256' },
protocol: { value: '3' },
alg: { value: '254' },
pubKey: { value: '841936717ae427ace63c28d04918569a841936717ae427ace63c28d0' }
}
}
]
})
response = epp_request(xml, :xml)
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
end
end end
context 'with juridical persion as an owner' do context 'with juridical persion as an owner' do