From 4f10cccdfa398b0242536922b48e51fd76e3d49a Mon Sep 17 00:00:00 2001 From: Martin Lensment Date: Tue, 23 Dec 2014 11:48:38 +0200 Subject: [PATCH] Additional validations for keyrelay --- app/models/keyrelay.rb | 8 +++++++- config/locales/en.yml | 11 +++++++++++ spec/epp/keyrelay_spec.rb | 23 +++++++++++++++++++++++ spec/fabricators/keyrelay_fabricator.rb | 5 +++++ 4 files changed, 46 insertions(+), 1 deletion(-) diff --git a/app/models/keyrelay.rb b/app/models/keyrelay.rb index a39bf7883..95e6946c7 100644 --- a/app/models/keyrelay.rb +++ b/app/models/keyrelay.rb @@ -9,6 +9,7 @@ class Keyrelay < ActiveRecord::Base delegate :name, to: :domain, prefix: true validates :expiry_relative, duration_iso8601: true + validates :key_data_public_key, :key_data_flags, :key_data_protocol, :key_data_alg, :auth_info_pw, presence: true validate :validate_expiry_relative_xor_expiry_absolute @@ -18,7 +19,12 @@ class Keyrelay < ActiveRecord::Base [:expiry_relative, :unknown_pattern, { value: { obj: 'relative', val: expiry_relative } }] ], '2003' => [ - [:base, :only_one_parameter_allowed, { param_1: 'relative', param_2: 'absolute' }] + [:base, :only_one_parameter_allowed, { param_1: 'relative', param_2: 'absolute' }], + [:key_data_public_key, :blank], + [:key_data_flags, :blank], + [:key_data_protocol, :blank], + [:key_data_alg, :blank], + [:auth_info_pw, :blank] ] } end diff --git a/config/locales/en.yml b/config/locales/en.yml index 4fc1beefc..443522eab 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -210,6 +210,17 @@ en: only_one_parameter_allowed: 'Only one parameter allowed: %{param_1} or %{param_2}' expiry_relative: unknown_pattern: 'Expiry relative must be compatible to ISO 8601' + key_data_public_key: + blank: 'Public key is missing' + key_data_flags: + blank: 'Flag is missing' + key_data_protocol: + blank: 'Protocol is missing' + key_data_alg: + blank: 'Algorithm is missing' + auth_info_pw: + blank: 'Password is missing' + attributes: epp_domain: &epp_domain_attributes diff --git a/spec/epp/keyrelay_spec.rb b/spec/epp/keyrelay_spec.rb index 0aedc694b..5c883eb74 100644 --- a/spec/epp/keyrelay_spec.rb +++ b/spec/epp/keyrelay_spec.rb @@ -41,6 +41,29 @@ describe 'EPP Keyrelay', epp: true do expect(zone.messages.queued.count).to eq(1) end + it 'returns an error when parameters are missing' do + xml = epp_xml.keyrelay({ + name: { value: 'example.ee' }, + keyData: { + flags: { value: '' }, + protocol: { value: '3' }, + alg: { value: '8' }, + pubKey: { value: 'cmlraXN0aGViZXN0' } + }, + authInfo: { + pw: { value: domain.auth_info } + }, + expiry: { + relative: { value: 'Invalid Expiry' } + } + }) + + response = epp_request(xml, :xml, :elkdata) + expect(response[:msg]).to eq('Required parameter missing: flags') + + expect(zone.messages.queued.count).to eq(0) + end + it 'returns an error on invalid relative expiry' do xml = epp_xml.keyrelay({ name: { value: 'example.ee' }, diff --git a/spec/fabricators/keyrelay_fabricator.rb b/spec/fabricators/keyrelay_fabricator.rb index 451a967de..27f5d7883 100644 --- a/spec/fabricators/keyrelay_fabricator.rb +++ b/spec/fabricators/keyrelay_fabricator.rb @@ -1,4 +1,9 @@ Fabricator(:keyrelay) do pa_date { DateTime.now } expiry_relative 'P1W' + key_data_public_key 'abc' + key_data_flags 0 + key_data_protocol 3 + key_data_alg 3 + auth_info_pw 'abc' end