From e46484405ef0304170abe3cebf95072d1a0b844d Mon Sep 17 00:00:00 2001 From: Martin Lensment Date: Mon, 20 Jul 2015 15:12:28 +0300 Subject: [PATCH] Validate period attribute on domain create #2763 --- app/controllers/epp/domains_controller.rb | 2 ++ spec/epp/domain_spec.rb | 36 +++++++++++++++++++++++ 2 files changed, 38 insertions(+) diff --git a/app/controllers/epp/domains_controller.rb b/app/controllers/epp/domains_controller.rb index d7f71d95b..00dddee11 100644 --- a/app/controllers/epp/domains_controller.rb +++ b/app/controllers/epp/domains_controller.rb @@ -161,6 +161,8 @@ class Epp::DomainsController < EppController @prefix = nil requires 'extension > extdata > legalDocument' + optional_attribute 'period', 'unit', values: %w(d m y) + status_editing_disabled end diff --git a/spec/epp/domain_spec.rb b/spec/epp/domain_spec.rb index 11ce18f8c..1b9d42bf3 100644 --- a/spec/epp/domain_spec.rb +++ b/spec/epp/domain_spec.rb @@ -435,6 +435,24 @@ describe 'EPP Domain', epp: true do a.activity_type = AccountActivity::CREATE end + it 'creates a domain without period' do + old_balance = @registrar1.balance + old_activities = @registrar1.cash_account.account_activities.count + xml = domain_create_xml(period: nil) + + response = epp_plain_request(xml) + response[:msg].should == 'Command completed successfully' + response[:result_code].should == '1000' + Domain.last.valid_to.should be_within(60).of(1.years.since) + @registrar1.balance.should be < old_balance + @registrar1.cash_account.account_activities.count.should == old_activities + 1 + a = @registrar1.cash_account.account_activities.last + a.description.should == "Create #{Domain.last.name}" + a.sum.should == -BigDecimal.new('10.0') + a.activity_type = AccountActivity::CREATE + a.log_pricelist_id.should == @pricelist_reg_1_year.id + end + it 'does not create a domain with invalid period' do old_balance = @registrar1.balance old_activities = @registrar1.cash_account.account_activities.count @@ -450,6 +468,24 @@ describe 'EPP Domain', epp: true do @registrar1.cash_account.account_activities.count.should == old_activities end + it 'does not create a domain with invalid period unit' do + xml = domain_create_xml({ + period: { value: '1', attrs: { unit: '' } } + }) + + response = epp_plain_request(xml, validate_input: false) + response[:results][0][:msg].should == 'Attribute is invalid: unit' + response[:results][0][:result_code].should == '2306' + + xml = domain_create_xml({ + period: { value: '1', attrs: { unit: 'bla' } } + }) + + response = epp_plain_request(xml, validate_input: false) + response[:results][0][:msg].should == 'Attribute is invalid: unit' + response[:results][0][:result_code].should == '2306' + end + it 'creates a domain with multiple dnskeys' do xml = domain_create_xml({}, { _anonymus: [