diff --git a/app/helpers/epp/domains_helper.rb b/app/helpers/epp/domains_helper.rb index 7ba753864..7828433a6 100644 --- a/app/helpers/epp/domains_helper.rb +++ b/app/helpers/epp/domains_helper.rb @@ -63,7 +63,7 @@ module Epp::DomainsHelper '2302' => [:epp_domain_taken, :epp_domain_reserved], '2306' => [:blank, [:out_of_range, {min: 1, max: 13}]], '2303' => [:not_found], - '2005' => [:hostname_invalid] + '2005' => [:hostname_invalid, :ip_invalid] }, @domain ) end diff --git a/app/models/domain.rb b/app/models/domain.rb index 5644b81fc..5d6569ddc 100644 --- a/app/models/domain.rb +++ b/app/models/domain.rb @@ -68,9 +68,15 @@ class Domain < ActiveRecord::Base if ns.is_a?(Hash) attrs = {hostname: ns[:hostName]} - ns[:hostAddr].each do |ip| - attrs[:ip] = ip unless attrs[:ip] - end if ns[:hostAddr] + if ns[:hostAddr] + if ns[:hostAddr].is_a?(Array) + ns[:hostAddr].each do |ip| + attrs[:ip] = ip unless attrs[:ip] + end + else + attrs[:ip] = ns[:hostAddr] + end + end self.nameservers.build(attrs) #ns with just hostname diff --git a/app/models/nameserver.rb b/app/models/nameserver.rb index 4f8789e47..f95e56f07 100644 --- a/app/models/nameserver.rb +++ b/app/models/nameserver.rb @@ -3,5 +3,5 @@ class Nameserver < ActiveRecord::Base has_and_belongs_to_many :domains validates :hostname, hostname: true - validates :ip, format: { with: /\A(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\z/, allow_nil: true} + validates :ip, format: { with: /\A(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\z/, allow_nil: true, message: :ip_invalid} end diff --git a/config/locales/en.yml b/config/locales/en.yml index 662722d42..598cab91a 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -49,10 +49,13 @@ en: blank: 'Required parameter missing - nameserver' out_of_range: 'Domain must have %{min}-%{max} nameservers' hostname_invalid: 'Hostname is invalid' + ip_invalid: 'IP is invalid' nameserver: attributes: hostname: invalid: 'Hostname is invalid' + ip: + ip_invalid: 'IP is invalid' errors: diff --git a/spec/epp/domain_spec.rb b/spec/epp/domain_spec.rb index 277b579f7..46bf2ceda 100644 --- a/spec/epp/domain_spec.rb +++ b/spec/epp/domain_spec.rb @@ -92,6 +92,12 @@ describe 'EPP Domain', epp: true do ns = Domain.first.nameservers.first expect(ns.ip).to eq('192.0.2.2') end + + it 'returns error when nameserver has invalid ip' do + response = epp_request('domains/create_w_invalid_ns_ip.xml') + expect(response[:results][0][:result_code]).to eq '2005' + expect(response[:results][0][:msg]).to eq 'IP is invalid' + end end context 'with juridical persion as an owner' do diff --git a/spec/epp/requests/domains/create_w_invalid_ns_ip.xml b/spec/epp/requests/domains/create_w_invalid_ns_ip.xml new file mode 100644 index 000000000..ca7237ce2 --- /dev/null +++ b/spec/epp/requests/domains/create_w_invalid_ns_ip.xml @@ -0,0 +1,29 @@ + + + + + + example.ee + 1 + + + ns1.example.net + 192.0.2.2.invalid + + + ns2.example.net + + + jd1234 + sh8013 + sh8013 + sh801333 + + 2fooBAR + + + + ABC-12345 + +