mirror of
https://github.com/internetee/registry.git
synced 2025-08-15 22:13:54 +02:00
added nameservier validator during creating or updating nameservers
This commit is contained in:
parent
1deb6fa39f
commit
a23d7cfce6
3 changed files with 32 additions and 4 deletions
|
@ -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
|
||||
|
|
|
@ -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?
|
||||
|
||||
|
|
|
@ -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]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue