From 338a58a6117c0c1e867b23b30689b64d35b85101 Mon Sep 17 00:00:00 2001 From: Martin Lensment Date: Thu, 2 Oct 2014 11:25:31 +0300 Subject: [PATCH] Validate flags an attributes presence on dnskey --- app/models/dnskey.rb | 13 ++++++++++++- config/locales/en.yml | 8 ++++++++ spec/epp/domain_spec.rb | 23 +++++++++++++++-------- 3 files changed, 35 insertions(+), 9 deletions(-) diff --git a/app/models/dnskey.rb b/app/models/dnskey.rb index ee0727c0a..151314b21 100644 --- a/app/models/dnskey.rb +++ b/app/models/dnskey.rb @@ -3,17 +3,23 @@ class Dnskey < ActiveRecord::Base belongs_to :domain + validates :alg, :protocol, :flags, :public_key, presence: true validate :validate_algorithm validate :validate_protocol + validate :validate_flags def epp_code_map { '2005' => [ [:alg, :invalid, { value: { obj: 'alg', val: alg } }], [:protocol, :invalid, { value: { obj: 'protocol', val: protocol } }], + [:flags, :invalid, { value: { obj: 'flags', val: flags } }] ], '2306' => [ - [:ipv4, :blank] + [:alg, :blank], + [:protocol, :blank], + [:flags, :blank], + [:public_key, :blank] ] } end @@ -27,4 +33,9 @@ class Dnskey < ActiveRecord::Base return if %w(3).include?(protocol.to_s) errors.add(:protocol, :invalid) end + + def validate_flags + return if %w(0 256 257).include?(flags.to_s) + errors.add(:flags, :invalid) + end end diff --git a/config/locales/en.yml b/config/locales/en.yml index 5fc95e1fc..65a19f359 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -187,8 +187,16 @@ en: attributes: alg: invalid: 'Algorithm is invalid' + blank: 'Algorithm is missing' protocol: invalid: 'Protocol is invalid' + blank: 'Protocol is missing' + flags: + invalid: 'Flag is invalid' + blank: 'Flag is missing' + public_key: + blank: 'Public key is missing' + attributes: epp_domain: &epp_domain_attributes diff --git a/spec/epp/domain_spec.rb b/spec/epp/domain_spec.rb index 47930e4ce..cef16057e 100644 --- a/spec/epp/domain_spec.rb +++ b/spec/epp/domain_spec.rb @@ -371,7 +371,7 @@ describe 'EPP Domain', epp: true do dnssec: [ { dnskey: { - flags: { value: '257' }, + flags: { value: '250' }, protocol: { value: '4' }, alg: { value: '9' }, pubKey: { value: 'AwEAAddt2AkLfYGKgiEZB5SmIF8EvrjxNMH6HtxWEA4RJ9Ao6LCWheg8' } @@ -379,7 +379,7 @@ describe 'EPP Domain', epp: true do }, { dnskey: { - flags: { value: '0' }, + flags: { value: '1' }, protocol: { value: '3' }, alg: { value: '10' }, pubKey: { value: '700b97b591ed27ec2590d19f06f88bba700b97b591ed27ec2590d19f' } @@ -390,14 +390,13 @@ describe 'EPP Domain', epp: true do flags: { value: '256' }, protocol: { value: '5' }, alg: { value: '254' }, - pubKey: { value: '841936717ae427ace63c28d04918569a841936717ae427ace63c28d0' } + pubKey: { value: '' } } } ] }) 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') @@ -405,11 +404,19 @@ describe 'EPP Domain', epp: true do 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][2][:msg]).to eq('Flag is invalid') + expect(response[:results][2][:value]).to eq('250') - expect(response[:results][3][:msg]).to eq('Protocol is invalid') - expect(response[:results][3][:value]).to eq('5') + expect(response[:results][3][:msg]).to eq('Algorithm is invalid') + expect(response[:results][3][:value]).to eq('10') + + expect(response[:results][4][:msg]).to eq('Flag is invalid') + expect(response[:results][4][:value]).to eq('1') + + expect(response[:results][5][:msg]).to eq('Public key is missing') + + expect(response[:results][6][:msg]).to eq('Protocol is invalid') + expect(response[:results][6][:value]).to eq('5') end end