From 28a6b59a5507de8d070681b1dc954780eaa151b6 Mon Sep 17 00:00:00 2001 From: Martin Lensment Date: Thu, 14 Aug 2014 16:50:54 +0300 Subject: [PATCH] Add a new test for domain info query, epp_errors improvement --- app/helpers/epp/domains_helper.rb | 2 ++ app/models/concerns/epp_errors.rb | 4 +++- app/models/domain.rb | 11 ++++++++++- config/locales/en.yml | 2 ++ spec/epp/domain_spec.rb | 6 ++++++ spec/epp/epp_helper_spec.rb | 8 +++++++- spec/support/epp.rb | 4 ++++ 7 files changed, 34 insertions(+), 3 deletions(-) diff --git a/app/helpers/epp/domains_helper.rb b/app/helpers/epp/domains_helper.rb index 174401e15..21b77322b 100644 --- a/app/helpers/epp/domains_helper.rb +++ b/app/helpers/epp/domains_helper.rb @@ -29,6 +29,8 @@ module Epp::DomainsHelper def info_domain @domain = find_domain + handle_errors(@domain) and return unless @domain + render '/epp/domains/info' end diff --git a/app/models/concerns/epp_errors.rb b/app/models/concerns/epp_errors.rb index d21c85b0c..e8c56918e 100644 --- a/app/models/concerns/epp_errors.rb +++ b/app/models/concerns/epp_errors.rb @@ -22,7 +22,9 @@ module EppErrors values.each do |err| if err.is_a?(Hash) next unless code = find_epp_code(err[:msg]) - epp_errors << {code: code, msg: err[:msg], value: {val: err[:val], obj: err[:obj]}} + err_msg = {code: code, msg: err[:msg]} + err_msg[:value] = {val: err[:val], obj: err[:obj]} if err[:val] + epp_errors << err_msg else next unless code = find_epp_code(err) err = {code: code, msg: err} diff --git a/app/models/domain.rb b/app/models/domain.rb index d8172bb64..eb6de0f13 100644 --- a/app/models/domain.rb +++ b/app/models/domain.rb @@ -8,7 +8,8 @@ class Domain < ActiveRecord::Base '2302' => ['Domain name already exists', 'Domain name is reserved or restricted'], # Object exists '2306' => ['Registrant is missing', 'Admin contact is missing', 'Given and current expire dates do not match'], # Parameter policy error '2004' => ['Nameservers count must be between 1-13', 'Period must add up to 1, 2 or 3 years'], # Parameter value range error - '2303' => ['Registrant not found', 'Contact was not found'] # Object does not exist + '2303' => ['Registrant not found', 'Contact was not found'], # Object does not exist + '2200' => ['Authentication error'] } EPP_ATTR_MAP = { @@ -156,6 +157,14 @@ class Domain < ActiveRecord::Base }) if cur_exp_date.to_date != valid_to end + ## SHARED + + # For domain transfer + def authenticate(pw) + errors.add(:auth_info, {msg: errors.generate_message(:auth_info, :wrong_pw)}) if pw != auth_info + errors.empty? + end + class << self def convert_period_to_time(period, unit) return period.to_i.days if unit == 'd' diff --git a/config/locales/en.yml b/config/locales/en.yml index 2b15d25f2..62537f891 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -54,6 +54,8 @@ en: ip_invalid: 'IPv4 is invalid' period: out_of_range: 'Period must add up to 1, 2 or 3 years' + auth_info: + wrong_pw: 'Authentication error' nameserver: attributes: hostname: diff --git a/spec/epp/domain_spec.rb b/spec/epp/domain_spec.rb index 099c0f2c9..074a503b0 100644 --- a/spec/epp/domain_spec.rb +++ b/spec/epp/domain_spec.rb @@ -234,6 +234,12 @@ describe 'EPP Domain', epp: true do expect(inf_data.css('upDate').text).to eq(d.updated_at.to_time.utc.to_s) end + + it 'returns error when domain can not be found' do + response = epp_request(domain_info_xml(name_value: 'test.ee'), :xml) + expect(response[:results][0][:result_code]).to eq('2303') + expect(response[:results][0][:msg]).to eq('Domain not found') + end end it 'checks a domain' do diff --git a/spec/epp/epp_helper_spec.rb b/spec/epp/epp_helper_spec.rb index 39e027907..c4835f35c 100644 --- a/spec/epp/epp_helper_spec.rb +++ b/spec/epp/epp_helper_spec.rb @@ -114,6 +114,9 @@ describe 'EPP Helper', epp: true do example.ee + + 2fooBAR + ABC-12345 @@ -132,6 +135,9 @@ describe 'EPP Helper', epp: true do one.ee + + b3rafsla + ABC-12345 @@ -140,7 +146,7 @@ describe 'EPP Helper', epp: true do ').to_s.squish - generated = Nokogiri::XML(domain_info_xml(name_value: 'one.ee', name_hosts: 'sub')).to_s.squish + generated = Nokogiri::XML(domain_info_xml(name_value: 'one.ee', name_hosts: 'sub', pw: 'b3rafsla')).to_s.squish expect(generated).to eq(expected) end end diff --git a/spec/support/epp.rb b/spec/support/epp.rb index 29b2d52f5..fb85caf36 100644 --- a/spec/support/epp.rb +++ b/spec/support/epp.rb @@ -128,6 +128,7 @@ module Epp def domain_info_xml(xml_params={}) xml_params[:name_value] = xml_params[:name_value] || 'example.ee' xml_params[:name_hosts] = xml_params[:name_hosts] || 'all' + xml_params[:pw] = xml_params[:pw] || '2fooBAR' xml = Builder::XmlMarkup.new @@ -137,6 +138,9 @@ module Epp xml.info do xml.tag!('domain:info', 'xmlns:domain' => 'urn:ietf:params:xml:ns:domain-1.0') do xml.tag!('domain:name', xml_params[:name_value], 'hosts' => xml_params[:name_hosts]) if xml_params[:name] != false + xml.tag!('domain:authInfo') do + xml.tag!('domain:pw', xml_params[:pw]) + end end end xml.clTRID 'ABC-12345'