diff --git a/app/models/domain.rb b/app/models/domain.rb index d79da3bc8..0b483cc15 100644 --- a/app/models/domain.rb +++ b/app/models/domain.rb @@ -49,7 +49,6 @@ class Domain < ApplicationRecord statuses.include? DomainStatus::SERVER_REGISTRANT_CHANGE_PROHIBITED end - # NB! contacts, admin_contacts, tech_contacts are empty for a new record has_many :domain_contacts, dependent: :destroy has_many :contacts, through: :domain_contacts, source: :contact diff --git a/app/models/nameserver.rb b/app/models/nameserver.rb index ababd84cf..4f7130908 100644 --- a/app/models/nameserver.rb +++ b/app/models/nameserver.rb @@ -31,6 +31,7 @@ class Nameserver < ApplicationRecord before_validation :normalize_attributes before_validation :check_puny_symbols before_validation :check_label_length + before_validation :check_presence_of_dnssec_keys delegate :name, to: :domain, prefix: true @@ -55,6 +56,36 @@ class Nameserver < ApplicationRecord } end + def check_presence_of_dnssec_keys + r = NameserverValidator.run(domain_name: domain, nameserver: self) + return if r[:result] + + text = parse_result(r, self) + add_epp_error(2302, self, self.hostname, text) + end + + def parse_result(result, nameserver) + text = '' + case result[:reason] + when 'answer' + text = "DNS Server **#{nameserver.hostname}** not responding" + when 'serial' + text = "Serial number for nameserver hostname **#{nameserver.hostname}** of #{nameserver.domain.name} doesn't present in zone. SOA validation failed." + when 'cname' + text = "Warning: SOA record expected but CNAME found instead. This setup can lead to unexpected errors when using the domain: hostname - **#{nameserver.hostname}** of #{nameserver.domain.name}" + when 'not found' + text = "Seems nameserver hostname **#{nameserver.hostname}** doesn't exist" + when 'exception' + text = "Something went wrong, exception reason: **#{result[:error_info]}**" + when 'domain' + text = "#{domain.name} zone is not in nameserver**#{nameserver.hostname}**" + when 'glup record' + text = "Hostname #{nameserver.hostname} didn't resovle by glue record to #{domain.name}" + end + + text + end + def failed_validation? return false if validation_counter.nil? diff --git a/app/services/nameserver_validator.rb b/app/services/nameserver_validator.rb index 6436ba363..29d229eb6 100644 --- a/app/services/nameserver_validator.rb +++ b/app/services/nameserver_validator.rb @@ -11,11 +11,9 @@ module NameserverValidator result_response = validate(domain_name: domain_name, hostname: nameserver.hostname) unless result_response[:result] && result_response[:reason] == :exception - if result_response[:error_info].to_s.include? "Nameserver invalid!" + if result_response[:error_info].to_s.include? 'Nameserver invalid!' if nameserver.ipv4.present? result_response = validate(domain_name: domain_name, hostname: nameserver.ipv4) - # elsif nameserver.ipv6.present? - # result_response = validate(domain_name: domain_name, hostname: nameserver.ipv6) end return { result: false, reason: 'glup record' } unless result_response[:result]