diff --git a/app/models/domain.rb b/app/models/domain.rb index 6d6c0500b..03b89fd03 100644 --- a/app/models/domain.rb +++ b/app/models/domain.rb @@ -49,6 +49,7 @@ class Domain < ActiveRecord::Base validate :validate_tech_contacts_uniqueness validate :validate_admin_contacts_uniqueness validate :validate_domain_statuses_uniqueness + validate :validate_nameserver_ips attr_accessor :owner_contact_typeahead @@ -98,6 +99,15 @@ class Domain < ActiveRecord::Base end end + def validate_nameserver_ips + nameservers.each do |ns| + next if !ns.hostname.end_with?(name) + next if ns.ipv4.present? + errors.add(:nameservers, :invalid) if errors[:nameservers].blank? + ns.errors.add(:ipv4, :blank) + end + end + def validate_tech_contacts_uniqueness contacts = domain_contacts.reject(&:marked_for_destruction?).select { |x| x.contact_type == DomainContact::TECH } validate_domain_contacts_uniqueness(contacts) diff --git a/app/models/nameserver.rb b/app/models/nameserver.rb index 643c6c6c4..625271485 100644 --- a/app/models/nameserver.rb +++ b/app/models/nameserver.rb @@ -17,6 +17,9 @@ class Nameserver < ActiveRecord::Base [:hostname, :invalid, { value: { obj: 'hostObj', val: hostname } }], [:ipv4, :invalid, { value: { obj: 'hostAddr', val: ipv4 } }], [:ipv6, :invalid, { value: { obj: 'hostAddr', val: ipv6 } }] + ], + '2306' => [ + [:ipv4, :blank] ] } end diff --git a/config/locales/en.yml b/config/locales/en.yml index 3e3f94d87..6d6527f86 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -121,6 +121,7 @@ en: invalid: 'Hostname is invalid' taken: 'Nameserver already exists on this domain' ipv4: + blank: 'IPv4 is missing' invalid: 'IPv4 is invalid' ipv6: invalid: 'IPv6 is invalid' diff --git a/spec/epp/domain_spec.rb b/spec/epp/domain_spec.rb index ac766de52..da783d889 100644 --- a/spec/epp/domain_spec.rb +++ b/spec/epp/domain_spec.rb @@ -203,6 +203,20 @@ describe 'EPP Domain', epp: true do expect(d.auth_info).not_to be_empty end + it 'validates nameserver ipv4 when in same zone as domain' do + xml_params = { + nameservers: [ + { hostObj: 'ns1.example.ee' }, + { hostObj: 'ns2.example.ee' } + ] + } + + response = epp_request(domain_create_xml(xml_params), :xml) + + expect(response[:result_code]).to eq('2306') + expect(response[:msg]).to eq('IPv4 is missing') + end + it 'does not create duplicate domain' do epp_request(domain_create_xml, :xml) response = epp_request(domain_create_xml, :xml)