diff --git a/Gemfile b/Gemfile index a1f128339..a69ae00e4 100644 --- a/Gemfile +++ b/Gemfile @@ -89,7 +89,7 @@ group :development, :test do gem 'epp', '~> 1.4.0' # EPP XMLs - gem 'epp-xml', '~> 0.3.0' + gem 'epp-xml', '~> 0.5.0' # Replacement for fixtures gem 'fabrication', '~> 2.11.3' diff --git a/Gemfile.lock b/Gemfile.lock index 7f3a051c7..7787dac0d 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -93,7 +93,7 @@ GEM epp (1.4.0) hpricot libxml-ruby - epp-xml (0.3.0) + epp-xml (0.5.0) activesupport (~> 4.1) builder (~> 3.2) equalizer (0.0.9) @@ -365,7 +365,7 @@ DEPENDENCIES database_cleaner (~> 1.3.0) devise (~> 3.3.0) epp (~> 1.4.0) - epp-xml (~> 0.3.0) + epp-xml (~> 0.5.0) fabrication (~> 2.11.3) faker (~> 1.3.0) guard (~> 2.6.1) diff --git a/app/helpers/epp/domains_helper.rb b/app/helpers/epp/domains_helper.rb index d8d8aca9a..777b8f415 100644 --- a/app/helpers/epp/domains_helper.rb +++ b/app/helpers/epp/domains_helper.rb @@ -31,7 +31,11 @@ module Epp::DomainsHelper @domain = find_domain handle_errors(@domain) and return unless @domain - handle_errors(@domain) and return unless @domain.renew(@ph[:curExpDate], @ph[:period]) + handle_errors(@domain) and return unless @domain.renew( + parsed_frame.css('curExpDate').text, + parsed_frame.css('period').text, + parsed_frame.css('period').first['unit'] + ) render '/epp/domains/renew' end diff --git a/app/models/epp/epp_domain.rb b/app/models/epp/epp_domain.rb index 3148ff9ed..c2cc3958d 100644 --- a/app/models/epp/epp_domain.rb +++ b/app/models/epp/epp_domain.rb @@ -22,7 +22,8 @@ class Epp::EppDomain < Domain [:admin_contacts, :out_of_range], [:base, :ds_data_with_key_not_allowed], [:base, :ds_data_not_allowed], - [:base, :key_data_not_allowed] + [:base, :key_data_not_allowed], + [:period, :not_a_number] ], '2004' => [ # Parameter value range error [:nameservers, :out_of_range, @@ -268,7 +269,6 @@ class Epp::EppDomain < Domain return false if errors.any? p = self.class.convert_period_to_time(period, unit) - self.valid_to = valid_to + p self.period = period self.period_unit = unit @@ -288,6 +288,11 @@ class Epp::EppDomain < Domain return approve_pending_transfer(params[:current_user]) end + if !pt && params[:action] != 'query' + add_epp_error('2306', nil, nil, I18n.t('errors.messages.attribute_op_is_invalid')) + return false + end + if !pt && params[:action] == 'query' return false unless can_be_transferred_to?(params[:current_user].registrar) end @@ -313,7 +318,7 @@ class Epp::EppDomain < Domain generate_auth_info self.registrar = params[:current_user].registrar - save + save(validate: false) end end # rubocop: enable Metrics/PerceivedComplexity @@ -335,13 +340,18 @@ class Epp::EppDomain < Domain generate_auth_info self.registrar = pt.transfer_to - save + save(validate: false) end ### VALIDATIONS ### def validate_exp_dates(cur_exp_date) - return if cur_exp_date.to_date == valid_to + begin + return if cur_exp_date.to_date == valid_to + rescue + add_epp_error('2306', 'curExpDate', cur_exp_date, I18n.t('errors.messages.epp_exp_dates_do_not_match')) + return + end add_epp_error('2306', 'curExpDate', cur_exp_date, I18n.t('errors.messages.epp_exp_dates_do_not_match')) end diff --git a/spec/epp/domain_spec.rb b/spec/epp/domain_spec.rb index ac1022fcc..4d864d9d1 100644 --- a/spec/epp/domain_spec.rb +++ b/spec/epp/domain_spec.rb @@ -682,7 +682,12 @@ describe 'EPP Domain', epp: true do it 'renews a domain' do exp_date = (Date.today + 1.year) - xml = domain_renew_xml(curExpDate: exp_date.to_s) + xml = EppXml::Domain.renew( + name: { value: 'example.ee' }, + curExpDate: { value: exp_date.to_s }, + period: { value: '1', attrs: { unit: 'y' } } + ) + response = epp_request(xml, :xml) ex_date = response[:parsed].css('renData exDate').text name = response[:parsed].css('renData name').text @@ -691,7 +696,11 @@ describe 'EPP Domain', epp: true do end it 'returns an error when given and current exp dates do not match' do - xml = domain_renew_xml(curExpDate: '2016-08-07') + xml = EppXml::Domain.renew( + name: { value: 'example.ee' }, + curExpDate: { value: '2016-08-07' }, + period: { value: '1', attrs: { unit: 'y' } } + ) response = epp_request(xml, :xml) expect(response[:results][0][:result_code]).to eq('2306') @@ -700,7 +709,12 @@ describe 'EPP Domain', epp: true do it 'returns an error when period is invalid' do exp_date = (Date.today + 1.year) - xml = domain_renew_xml(period_value: 4, curExpDate: exp_date.to_s) + + xml = EppXml::Domain.renew( + name: { value: 'example.ee' }, + curExpDate: { value: exp_date.to_s }, + period: { value: '4', attrs: { unit: 'y' } } + ) response = epp_request(xml, :xml) expect(response[:results][0][:result_code]).to eq('2004')