mirror of
https://github.com/internetee/registry.git
synced 2025-06-08 05:34:46 +02:00
commit
fbbada1c37
33 changed files with 712 additions and 215 deletions
6
.reek
6
.reek
|
@ -111,7 +111,6 @@ UncommunicativeVariableName:
|
||||||
- Invoice#cancel_overdue_invoices
|
- Invoice#cancel_overdue_invoices
|
||||||
- Legacy::Db
|
- Legacy::Db
|
||||||
- LegalDocument#save_to_filesystem
|
- LegalDocument#save_to_filesystem
|
||||||
- Nameserver#replace_hostname_ends
|
|
||||||
- RegistrantUser#find_or_create_by_idc_data
|
- RegistrantUser#find_or_create_by_idc_data
|
||||||
- RegistrantUser#find_or_create_by_mid_data
|
- RegistrantUser#find_or_create_by_mid_data
|
||||||
- Registrar
|
- Registrar
|
||||||
|
@ -318,7 +317,6 @@ DuplicateMethodCall:
|
||||||
- Invoice#set_invoice_number
|
- Invoice#set_invoice_number
|
||||||
- LegalDocument#save_to_filesystem
|
- LegalDocument#save_to_filesystem
|
||||||
- LegalDocument#self.remove_duplicates
|
- LegalDocument#self.remove_duplicates
|
||||||
- Nameserver#replace_hostname_ends
|
|
||||||
- Setting#self.params_errors
|
- Setting#self.params_errors
|
||||||
- Setting#self.reload_settings!
|
- Setting#self.reload_settings!
|
||||||
- Soap::Arireg#associated_businesses
|
- Soap::Arireg#associated_businesses
|
||||||
|
@ -806,7 +804,6 @@ TooManyStatements:
|
||||||
- Invoice#set_invoice_number
|
- Invoice#set_invoice_number
|
||||||
- LegalDocument#save_to_filesystem
|
- LegalDocument#save_to_filesystem
|
||||||
- LegalDocument#self.remove_duplicates
|
- LegalDocument#self.remove_duplicates
|
||||||
- Nameserver#replace_hostname_ends
|
|
||||||
- RegistrantUser#find_or_create_by_idc_data
|
- RegistrantUser#find_or_create_by_idc_data
|
||||||
- Registrar#generate_iso_11649_reference_no
|
- Registrar#generate_iso_11649_reference_no
|
||||||
- Soap::Arireg#associated_businesses
|
- Soap::Arireg#associated_businesses
|
||||||
|
@ -1003,7 +1000,6 @@ NestedIterators:
|
||||||
- Domain#self.to_csv
|
- Domain#self.to_csv
|
||||||
- Epp::Domain#nameservers_from
|
- Epp::Domain#nameservers_from
|
||||||
- LegalDocument#self.remove_duplicates
|
- LegalDocument#self.remove_duplicates
|
||||||
- Nameserver#replace_hostname_ends
|
|
||||||
- RegistrantPresenter#domain_names_with_roles
|
- RegistrantPresenter#domain_names_with_roles
|
||||||
- UniquenessMultiValidator#validate_each
|
- UniquenessMultiValidator#validate_each
|
||||||
UnusedParameters:
|
UnusedParameters:
|
||||||
|
@ -1140,7 +1136,5 @@ UncommunicativeParameterName:
|
||||||
- Dnskey#int_to_hex
|
- Dnskey#int_to_hex
|
||||||
UncommunicativeMethodName:
|
UncommunicativeMethodName:
|
||||||
exclude:
|
exclude:
|
||||||
- Nameserver#val_ipv4
|
|
||||||
- Nameserver#val_ipv6
|
|
||||||
- Soap::Arireg#country_code_3
|
- Soap::Arireg#country_code_3
|
||||||
- WhiteIp#validate_ipv4_and_ipv6
|
- WhiteIp#validate_ipv4_and_ipv6
|
||||||
|
|
|
@ -58,5 +58,6 @@ module Repp
|
||||||
mount Repp::ContactV1
|
mount Repp::ContactV1
|
||||||
mount Repp::AccountV1
|
mount Repp::AccountV1
|
||||||
mount Repp::DomainTransfersV1
|
mount Repp::DomainTransfersV1
|
||||||
|
mount Repp::NameserversV1
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
44
app/api/repp/nameservers_v1.rb
Normal file
44
app/api/repp/nameservers_v1.rb
Normal file
|
@ -0,0 +1,44 @@
|
||||||
|
module Repp
|
||||||
|
class NameserversV1 < Grape::API
|
||||||
|
version 'v1', using: :path
|
||||||
|
|
||||||
|
resource 'registrar/nameservers' do
|
||||||
|
put '/' do
|
||||||
|
params do
|
||||||
|
requires :data, type: Hash, allow_blank: false do
|
||||||
|
requires :type, type: String, allow_blank: false
|
||||||
|
requires :id, type: String, allow_blank: false
|
||||||
|
requires :attributes, type: Hash, allow_blank: false do
|
||||||
|
requires :hostname, type: String, allow_blank: false
|
||||||
|
requires :ipv4, type: Array
|
||||||
|
requires :ipv6, type: Array
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
hostname = params[:data][:id]
|
||||||
|
|
||||||
|
unless current_user.registrar.nameservers.exists?(hostname: hostname)
|
||||||
|
error!({ errors: [{ title: "Hostname #{hostname} does not exist" }] }, 404)
|
||||||
|
end
|
||||||
|
|
||||||
|
new_attributes = {
|
||||||
|
hostname: params[:data][:attributes][:hostname],
|
||||||
|
ipv4: params[:data][:attributes][:ipv4],
|
||||||
|
ipv6: params[:data][:attributes][:ipv6],
|
||||||
|
}
|
||||||
|
|
||||||
|
begin
|
||||||
|
current_user.registrar.replace_nameservers(hostname, new_attributes)
|
||||||
|
rescue ActiveRecord::RecordInvalid => e
|
||||||
|
error!({ errors: e.record.errors.full_messages.map { |error| { title: error } } }, 400)
|
||||||
|
end
|
||||||
|
|
||||||
|
status 200
|
||||||
|
@response = { data: { type: 'nameserver',
|
||||||
|
id: params[:data][:attributes][:hostname],
|
||||||
|
attributes: params[:data][:attributes] } }
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
|
@ -0,0 +1,59 @@
|
||||||
|
class Registrar
|
||||||
|
class RegistrarNameserversController < DeppController
|
||||||
|
def edit
|
||||||
|
authorize! :manage, :repp
|
||||||
|
end
|
||||||
|
|
||||||
|
def update
|
||||||
|
authorize! :manage, :repp
|
||||||
|
|
||||||
|
ipv4 = params[:ipv4].split("\r\n")
|
||||||
|
ipv6 = params[:ipv6].split("\r\n")
|
||||||
|
|
||||||
|
uri = URI.parse("#{ENV['repp_url']}registrar/nameservers")
|
||||||
|
request = Net::HTTP::Put.new(uri, 'Content-Type' => 'application/json')
|
||||||
|
request.body = { data: { type: 'nameserver', id: params[:old_hostname],
|
||||||
|
attributes: { hostname: params[:new_hostname],
|
||||||
|
ipv4: ipv4,
|
||||||
|
ipv6: ipv6 } } }.to_json
|
||||||
|
request.basic_auth(current_user.username, current_user.password)
|
||||||
|
|
||||||
|
if Rails.env.test?
|
||||||
|
response = Net::HTTP.start(uri.hostname, uri.port,
|
||||||
|
use_ssl: (uri.scheme == 'https'),
|
||||||
|
verify_mode: OpenSSL::SSL::VERIFY_NONE) do |http|
|
||||||
|
http.request(request)
|
||||||
|
end
|
||||||
|
elsif Rails.env.development?
|
||||||
|
client_cert = File.read(ENV['cert_path'])
|
||||||
|
client_key = File.read(ENV['key_path'])
|
||||||
|
response = Net::HTTP.start(uri.hostname, uri.port,
|
||||||
|
use_ssl: (uri.scheme == 'https'),
|
||||||
|
verify_mode: OpenSSL::SSL::VERIFY_NONE,
|
||||||
|
cert: OpenSSL::X509::Certificate.new(client_cert),
|
||||||
|
key: OpenSSL::PKey::RSA.new(client_key)) do |http|
|
||||||
|
http.request(request)
|
||||||
|
end
|
||||||
|
else
|
||||||
|
client_cert = File.read(ENV['cert_path'])
|
||||||
|
client_key = File.read(ENV['key_path'])
|
||||||
|
response = Net::HTTP.start(uri.hostname, uri.port,
|
||||||
|
use_ssl: (uri.scheme == 'https'),
|
||||||
|
cert: OpenSSL::X509::Certificate.new(client_cert),
|
||||||
|
key: OpenSSL::PKey::RSA.new(client_key)) do |http|
|
||||||
|
http.request(request)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
parsed_response = JSON.parse(response.body, symbolize_names: true)
|
||||||
|
|
||||||
|
if response.code == '200'
|
||||||
|
flash[:notice] = t '.replaced'
|
||||||
|
redirect_to registrar_domains_url
|
||||||
|
else
|
||||||
|
@api_errors = parsed_response[:errors]
|
||||||
|
render :edit
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
|
@ -40,7 +40,7 @@ class Domain < ActiveRecord::Base
|
||||||
has_many :contacts, through: :domain_contacts, source: :contact
|
has_many :contacts, through: :domain_contacts, source: :contact
|
||||||
has_many :admin_contacts, through: :admin_domain_contacts, source: :contact
|
has_many :admin_contacts, through: :admin_domain_contacts, source: :contact
|
||||||
has_many :tech_contacts, through: :tech_domain_contacts, source: :contact
|
has_many :tech_contacts, through: :tech_domain_contacts, source: :contact
|
||||||
has_many :nameservers, dependent: :destroy
|
has_many :nameservers, dependent: :destroy, inverse_of: :domain
|
||||||
|
|
||||||
accepts_nested_attributes_for :nameservers, allow_destroy: true,
|
accepts_nested_attributes_for :nameservers, allow_destroy: true,
|
||||||
reject_if: proc { |attrs| attrs[:hostname].blank? }
|
reject_if: proc { |attrs| attrs[:hostname].blank? }
|
||||||
|
|
|
@ -2,18 +2,31 @@ class Nameserver < ActiveRecord::Base
|
||||||
include Versions # version/nameserver_version.rb
|
include Versions # version/nameserver_version.rb
|
||||||
include EppErrors
|
include EppErrors
|
||||||
|
|
||||||
# belongs_to :registrar
|
HOSTNAME_REGEXP = /\A(([a-zA-Z0-9]|[a-zA-ZäöüõšžÄÖÜÕŠŽ0-9][a-zA-ZäöüõšžÄÖÜÕŠŽ0-9\-]
|
||||||
belongs_to :domain
|
*[a-zA-ZäöüõšžÄÖÜÕŠŽ0-9])\.)
|
||||||
|
*([A-Za-z0-9]|[A-Za-z0-9][A-Za-z0-9\-]
|
||||||
|
*[A-Za-z0-9])\z/x
|
||||||
|
|
||||||
# scope :owned_by_registrar, -> (registrar) { joins(:domain).where('domains.registrar_id = ?', registrar.id) }
|
IPV4_REGEXP = /\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/x
|
||||||
|
|
||||||
# rubocop: disable Metrics/LineLength
|
IPV6_REGEXP = /(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|
|
||||||
validates :hostname, format: { with: /\A(([a-zA-Z0-9]|[a-zA-ZäöüõšžÄÖÜÕŠŽ0-9][a-zA-ZäöüõšžÄÖÜÕŠŽ0-9\-]*[a-zA-ZäöüõšžÄÖÜÕŠŽ0-9])\.)*([A-Za-z0-9]|[A-Za-z0-9][A-Za-z0-9\-]*[A-Za-z0-9])\z/ }
|
([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|
|
||||||
# validates :ipv4, 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_blank: true }
|
([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|
|
||||||
# validates :ipv6, format: { with: /(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]).){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]).){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))/, allow_blank: true }
|
([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|
|
||||||
validate :val_ipv4
|
([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|
|
||||||
validate :val_ipv6
|
:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|
|
||||||
# rubocop: enable Metrics/LineLength
|
::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]).){3,3}(25[0-5]|(2[0-4]|
|
||||||
|
1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|
|
||||||
|
1{0,1}[0-9]){0,1}[0-9]).){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))/x
|
||||||
|
|
||||||
|
belongs_to :domain, required: true
|
||||||
|
|
||||||
|
validates :hostname, presence: true
|
||||||
|
validates :hostname, format: { with: HOSTNAME_REGEXP }, allow_blank: true
|
||||||
|
validate :validate_ipv4_format
|
||||||
|
validate :validate_ipv6_format
|
||||||
|
validate :require_ip, if: :glue_record_required?
|
||||||
|
|
||||||
before_validation :normalize_attributes
|
before_validation :normalize_attributes
|
||||||
before_validation :check_puny_symbols
|
before_validation :check_puny_symbols
|
||||||
|
@ -38,6 +51,39 @@ class Nameserver < ActiveRecord::Base
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def to_s
|
||||||
|
hostname
|
||||||
|
end
|
||||||
|
|
||||||
|
def hostname=(hostname)
|
||||||
|
self[:hostname] = SimpleIDN.to_unicode(hostname)
|
||||||
|
self[:hostname_puny] = SimpleIDN.to_ascii(hostname)
|
||||||
|
end
|
||||||
|
|
||||||
|
class << self
|
||||||
|
def find_by_hash_params params
|
||||||
|
params = params.with_indifferent_access
|
||||||
|
rel = all
|
||||||
|
rel = rel.where(hostname: params[:hostname])
|
||||||
|
rel
|
||||||
|
end
|
||||||
|
|
||||||
|
def hostnames
|
||||||
|
pluck(:hostname)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def require_ip
|
||||||
|
errors.add(:base, :ip_required) if ipv4.blank? && ipv6.blank?
|
||||||
|
end
|
||||||
|
|
||||||
|
def glue_record_required?
|
||||||
|
return unless hostname? && domain
|
||||||
|
hostname.end_with?(domain.name)
|
||||||
|
end
|
||||||
|
|
||||||
def normalize_attributes
|
def normalize_attributes
|
||||||
self.hostname = hostname.try(:strip).try(:downcase)
|
self.hostname = hostname.try(:strip).try(:downcase)
|
||||||
self.ipv4 = Array(ipv4).reject(&:blank?).map(&:strip)
|
self.ipv4 = Array(ipv4).reject(&:blank?).map(&:strip)
|
||||||
|
@ -45,6 +91,8 @@ class Nameserver < ActiveRecord::Base
|
||||||
end
|
end
|
||||||
|
|
||||||
def check_label_length
|
def check_label_length
|
||||||
|
return unless hostname
|
||||||
|
|
||||||
hostname_puny.split('.').each do |label|
|
hostname_puny.split('.').each do |label|
|
||||||
errors.add(:hostname, :puny_to_long) if label.length > 63
|
errors.add(:hostname, :puny_to_long) if label.length > 63
|
||||||
end
|
end
|
||||||
|
@ -55,71 +103,15 @@ class Nameserver < ActiveRecord::Base
|
||||||
errors.add(:hostname, :invalid) if hostname =~ regexp
|
errors.add(:hostname, :invalid) if hostname =~ regexp
|
||||||
end
|
end
|
||||||
|
|
||||||
def to_s
|
def validate_ipv4_format
|
||||||
hostname
|
|
||||||
end
|
|
||||||
|
|
||||||
def hostname=(hostname)
|
|
||||||
self[:hostname] = SimpleIDN.to_unicode(hostname)
|
|
||||||
self[:hostname_puny] = SimpleIDN.to_ascii(hostname)
|
|
||||||
end
|
|
||||||
|
|
||||||
def val_ipv4
|
|
||||||
regexp = /\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/
|
|
||||||
ipv4.to_a.each do |ip|
|
ipv4.to_a.each do |ip|
|
||||||
errors.add(:ipv4, :invalid) unless ip =~ regexp
|
errors.add(:ipv4, :invalid) unless ip =~ IPV4_REGEXP
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
def val_ipv6
|
|
||||||
regexp = /(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]).){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]).){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))/
|
def validate_ipv6_format
|
||||||
ipv6.to_a.each do |ip|
|
ipv6.to_a.each do |ip|
|
||||||
errors.add(:ipv6, :invalid) unless ip =~ regexp
|
errors.add(:ipv6, :invalid) unless ip =~ IPV6_REGEXP
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
class << self
|
|
||||||
def replace_hostname_ends(domains, old_end, new_end)
|
|
||||||
domains = domains.where('EXISTS(
|
|
||||||
select 1 from nameservers ns where ns.domain_id = domains.id AND ns.hostname LIKE ?
|
|
||||||
)', "%#{old_end}")
|
|
||||||
|
|
||||||
count, success_count = 0.0, 0.0
|
|
||||||
domains.each do |d|
|
|
||||||
ns_attrs = { nameservers_attributes: [] }
|
|
||||||
|
|
||||||
d.nameservers.each do |ns|
|
|
||||||
next unless ns.hostname.end_with?(old_end)
|
|
||||||
|
|
||||||
hn = ns.hostname.chomp(old_end)
|
|
||||||
ns_attrs[:nameservers_attributes] << {
|
|
||||||
id: ns.id,
|
|
||||||
hostname: "#{hn}#{new_end}"
|
|
||||||
}
|
|
||||||
end
|
|
||||||
|
|
||||||
success_count += 1 if d.update(ns_attrs)
|
|
||||||
count += 1
|
|
||||||
end
|
|
||||||
|
|
||||||
return 'replaced_none' if count == 0.0
|
|
||||||
|
|
||||||
prc = success_count / count
|
|
||||||
|
|
||||||
return 'replaced_all' if prc == 1.0
|
|
||||||
'replaced_some'
|
|
||||||
end
|
|
||||||
|
|
||||||
def find_by_hash_params params
|
|
||||||
params = params.with_indifferent_access
|
|
||||||
rel = all
|
|
||||||
rel = rel.where(hostname: params[:hostname])
|
|
||||||
# rel = rel.where(hostname: params[:hostname]) if params[:ipv4]
|
|
||||||
# ignoring ips
|
|
||||||
rel
|
|
||||||
end
|
|
||||||
|
|
||||||
def hostnames
|
|
||||||
pluck(:hostname)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -158,6 +158,20 @@ class Registrar < ActiveRecord::Base
|
||||||
white_ips.api.pluck(:ipv4, :ipv6).flatten.include?(ip)
|
white_ips.api.pluck(:ipv4, :ipv6).flatten.include?(ip)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Audit log is needed, therefore no raw SQL
|
||||||
|
def replace_nameservers(hostname, new_attributes)
|
||||||
|
transaction do
|
||||||
|
nameservers.where(hostname: hostname).find_each do |original_nameserver|
|
||||||
|
new_nameserver = Nameserver.new
|
||||||
|
new_nameserver.domain = original_nameserver.domain
|
||||||
|
new_nameserver.attributes = new_attributes
|
||||||
|
new_nameserver.save!
|
||||||
|
|
||||||
|
original_nameserver.destroy!
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def set_defaults
|
def set_defaults
|
||||||
|
|
|
@ -1,12 +1,14 @@
|
||||||
<div class="page-header">
|
<div class="page-header">
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-sm-9">
|
<div class="col-sm-7">
|
||||||
<h1><%= t '.header' %></h1>
|
<h1><%= t '.header' %></h1>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="col-sm-3 text-right">
|
<div class="col-sm-5 text-right">
|
||||||
<%= link_to t('.new_btn'), new_registrar_domain_path, class: 'btn btn-primary' %>
|
<%= link_to t('.new_btn'), new_registrar_domain_path, class: 'btn btn-primary' %>
|
||||||
<%= link_to t('.transfer_btn'), new_registrar_domain_transfer_path, class: 'btn btn-default' %>
|
<%= link_to t('.transfer_btn'), new_registrar_domain_transfer_path, class: 'btn btn-default' %>
|
||||||
|
<%= link_to t('.replace_nameserver_btn'), registrar_edit_registrar_nameserver_path,
|
||||||
|
class: 'btn btn-default' %>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
55
app/views/registrar/registrar_nameservers/_form.html.erb
Normal file
55
app/views/registrar/registrar_nameservers/_form.html.erb
Normal file
|
@ -0,0 +1,55 @@
|
||||||
|
<%= form_tag registrar_update_registrar_nameserver_path, method: :put, class: 'form-horizontal' do %>
|
||||||
|
<div class="form-group">
|
||||||
|
<div class="col-md-2 control-label">
|
||||||
|
<%= label_tag :old_hostname %>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="col-md-5">
|
||||||
|
<%= text_field_tag :old_hostname, params[:old_hostname], autofocus: true,
|
||||||
|
required: true,
|
||||||
|
spellcheck: false,
|
||||||
|
class: 'form-control' %>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="form-group">
|
||||||
|
<div class="col-md-2 control-label">
|
||||||
|
<%= label_tag :new_hostname %>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="col-md-5">
|
||||||
|
<%= text_field_tag :new_hostname, params[:new_hostname], required: true,
|
||||||
|
spellcheck: false,
|
||||||
|
class: 'form-control' %>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="form-group">
|
||||||
|
<div class="col-md-2 control-label">
|
||||||
|
<%= label_tag :ipv4 %>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="col-md-3">
|
||||||
|
<%= text_area_tag :ipv4, params[:ipv4], spellcheck: false, class: 'form-control' %>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="form-group">
|
||||||
|
<div class="col-md-2 control-label">
|
||||||
|
<%= label_tag :ipv6 %>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="col-md-3">
|
||||||
|
<%= text_area_tag :ipv6, params[:ipv6], spellcheck: false, class: 'form-control' %>
|
||||||
|
<span class="help-block"><%= t '.ip_hint' %></span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="form-group">
|
||||||
|
<div class="col-md-5 col-md-offset-2 text-right">
|
||||||
|
<button class="btn btn-warning">
|
||||||
|
<%= t '.replace_btn' %>
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<% end %>
|
11
app/views/registrar/registrar_nameservers/edit.html.erb
Normal file
11
app/views/registrar/registrar_nameservers/edit.html.erb
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
<ol class="breadcrumb">
|
||||||
|
<li><%= link_to t('registrar.domains.index.header'), registrar_domains_path %></li>
|
||||||
|
</ol>
|
||||||
|
|
||||||
|
<div class="page-header">
|
||||||
|
<h1><%= t '.header' %></h1>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<%= render 'registrar/domain_transfers/form/api_errors' %>
|
||||||
|
|
||||||
|
<%= render 'form' %>
|
|
@ -464,8 +464,6 @@ en:
|
||||||
name: 'Name'
|
name: 'Name'
|
||||||
type: 'Type'
|
type: 'Type'
|
||||||
code: 'Code'
|
code: 'Code'
|
||||||
nameservers: 'Nameservers'
|
|
||||||
hostname: 'Hostname'
|
|
||||||
dnskeys: 'DNS Keys'
|
dnskeys: 'DNS Keys'
|
||||||
flag: 'Flag'
|
flag: 'Flag'
|
||||||
protocol: 'Protocol'
|
protocol: 'Protocol'
|
||||||
|
|
8
config/locales/nameservers.en.yml
Normal file
8
config/locales/nameservers.en.yml
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
en:
|
||||||
|
activerecord:
|
||||||
|
errors:
|
||||||
|
models:
|
||||||
|
nameserver:
|
||||||
|
attributes:
|
||||||
|
base:
|
||||||
|
ip_required: Either IPv4 or IPv6 is required for glue record generation
|
|
@ -5,6 +5,7 @@ en:
|
||||||
header: Domains
|
header: Domains
|
||||||
new_btn: New domain
|
new_btn: New domain
|
||||||
transfer_btn: Transfer
|
transfer_btn: Transfer
|
||||||
|
replace_nameserver_btn: Replace nameserver
|
||||||
csv:
|
csv:
|
||||||
domain_name: Domain
|
domain_name: Domain
|
||||||
transfer_code: Transfer code
|
transfer_code: Transfer code
|
||||||
|
|
13
config/locales/registrar/registrar_nameservers.en.yml
Normal file
13
config/locales/registrar/registrar_nameservers.en.yml
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
en:
|
||||||
|
registrar:
|
||||||
|
registrar_nameservers:
|
||||||
|
edit:
|
||||||
|
header: Replace nameserver
|
||||||
|
replace_btn: Replace
|
||||||
|
|
||||||
|
form:
|
||||||
|
ip_hint: One IP per line
|
||||||
|
replace_btn: Replace nameserver
|
||||||
|
|
||||||
|
update:
|
||||||
|
replaced: Nameserver have been successfully replaced
|
|
@ -62,6 +62,8 @@ Rails.application.routes.draw do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
resources :domain_transfers, only: %i[new create]
|
resources :domain_transfers, only: %i[new create]
|
||||||
|
get 'registrar/nameservers', to: 'registrar_nameservers#edit', as: :edit_registrar_nameserver
|
||||||
|
put 'registrar/nameservers', to: 'registrar_nameservers#update', as: :update_registrar_nameserver
|
||||||
|
|
||||||
resources :contacts, constraints: {:id => /[^\/]+(?=#{ ActionController::Renderers::RENDERERS.map{|e| "\\.#{e}\\z"}.join("|") })|[^\/]+/} do
|
resources :contacts, constraints: {:id => /[^\/]+(?=#{ ActionController::Renderers::RENDERERS.map{|e| "\\.#{e}\\z"}.join("|") })|[^\/]+/} do
|
||||||
member do
|
member do
|
||||||
|
|
|
@ -0,0 +1,5 @@
|
||||||
|
class AddNameserversDomainIdFk < ActiveRecord::Migration
|
||||||
|
def change
|
||||||
|
add_foreign_key :nameservers, :domains, name: 'nameservers_domain_id_fk'
|
||||||
|
end
|
||||||
|
end
|
|
@ -0,0 +1,5 @@
|
||||||
|
class ChangeNameserversDomainIdToNotNull < ActiveRecord::Migration
|
||||||
|
def change
|
||||||
|
change_column_null :nameservers, :domain_id, false
|
||||||
|
end
|
||||||
|
end
|
|
@ -0,0 +1,5 @@
|
||||||
|
class ChangeNameserversHostnameToNotNull < ActiveRecord::Migration
|
||||||
|
def change
|
||||||
|
change_column_null :nameservers, :hostname, false
|
||||||
|
end
|
||||||
|
end
|
|
@ -2220,12 +2220,12 @@ ALTER SEQUENCE messages_id_seq OWNED BY messages.id;
|
||||||
|
|
||||||
CREATE TABLE nameservers (
|
CREATE TABLE nameservers (
|
||||||
id integer NOT NULL,
|
id integer NOT NULL,
|
||||||
hostname character varying,
|
hostname character varying NOT NULL,
|
||||||
ipv4 character varying[] DEFAULT '{}'::character varying[],
|
ipv4 character varying[] DEFAULT '{}'::character varying[],
|
||||||
created_at timestamp without time zone,
|
created_at timestamp without time zone,
|
||||||
updated_at timestamp without time zone,
|
updated_at timestamp without time zone,
|
||||||
ipv6 character varying[] DEFAULT '{}'::character varying[],
|
ipv6 character varying[] DEFAULT '{}'::character varying[],
|
||||||
domain_id integer,
|
domain_id integer NOT NULL,
|
||||||
creator_str character varying,
|
creator_str character varying,
|
||||||
updator_str character varying,
|
updator_str character varying,
|
||||||
legacy_domain_id integer,
|
legacy_domain_id integer,
|
||||||
|
@ -4532,6 +4532,14 @@ ALTER TABLE ONLY messages
|
||||||
ADD CONSTRAINT messages_registrar_id_fk FOREIGN KEY (registrar_id) REFERENCES registrars(id);
|
ADD CONSTRAINT messages_registrar_id_fk FOREIGN KEY (registrar_id) REFERENCES registrars(id);
|
||||||
|
|
||||||
|
|
||||||
|
--
|
||||||
|
-- Name: nameservers_domain_id_fk; Type: FK CONSTRAINT; Schema: public; Owner: -
|
||||||
|
--
|
||||||
|
|
||||||
|
ALTER TABLE ONLY nameservers
|
||||||
|
ADD CONSTRAINT nameservers_domain_id_fk FOREIGN KEY (domain_id) REFERENCES domains(id);
|
||||||
|
|
||||||
|
|
||||||
--
|
--
|
||||||
-- Name: user_registrar_id_fk; Type: FK CONSTRAINT; Schema: public; Owner: -
|
-- Name: user_registrar_id_fk; Type: FK CONSTRAINT; Schema: public; Owner: -
|
||||||
--
|
--
|
||||||
|
@ -5086,6 +5094,12 @@ INSERT INTO schema_migrations (version) VALUES ('20180126104536');
|
||||||
|
|
||||||
INSERT INTO schema_migrations (version) VALUES ('20180126104903');
|
INSERT INTO schema_migrations (version) VALUES ('20180126104903');
|
||||||
|
|
||||||
|
INSERT INTO schema_migrations (version) VALUES ('20180129143538');
|
||||||
|
|
||||||
|
INSERT INTO schema_migrations (version) VALUES ('20180129232054');
|
||||||
|
|
||||||
|
INSERT INTO schema_migrations (version) VALUES ('20180129233223');
|
||||||
|
|
||||||
INSERT INTO schema_migrations (version) VALUES ('20180206213435');
|
INSERT INTO schema_migrations (version) VALUES ('20180206213435');
|
||||||
|
|
||||||
INSERT INTO schema_migrations (version) VALUES ('20180206234620');
|
INSERT INTO schema_migrations (version) VALUES ('20180206234620');
|
||||||
|
|
|
@ -22,7 +22,7 @@ Domain name mapping protocol short version:
|
||||||
<domain:ns> 0-1
|
<domain:ns> 0-1
|
||||||
<domain:hostAttr> 2-11
|
<domain:hostAttr> 2-11
|
||||||
<domain:hostName> 1 Hostname of the nameserver
|
<domain:hostName> 1 Hostname of the nameserver
|
||||||
<domain:hostAddr> 0-2 Required if nameserver is under domain zone.
|
<domain:hostAddr> 0-2 Required if nameserver hostname is under the same domain.
|
||||||
Attribute ip="v4 / v6"
|
Attribute ip="v4 / v6"
|
||||||
<domain:registrant> 1 Contact reference to the registrant
|
<domain:registrant> 1 Contact reference to the registrant
|
||||||
<domain:contact> 0-n Contact reference. Admin contact is required if registrant is
|
<domain:contact> 0-n Contact reference. Admin contact is required if registrant is
|
||||||
|
@ -62,7 +62,7 @@ Domain name mapping protocol short version:
|
||||||
<domain:ns> 0-1
|
<domain:ns> 0-1
|
||||||
<domain:hostAttr> 1
|
<domain:hostAttr> 1
|
||||||
<domain:hostName> 1 Hostname of the nameserver
|
<domain:hostName> 1 Hostname of the nameserver
|
||||||
<domain:hostAddr> 0-2 Required if nameserver is under domain zone.
|
<domain:hostAddr> 0-2 Required if nameserver hostname is under the same domain.
|
||||||
Attribute ip="v4 / v6"
|
Attribute ip="v4 / v6"
|
||||||
<domain:rem> 0-1 Objects to remove
|
<domain:rem> 0-1 Objects to remove
|
||||||
<domain:contact> 0-n Contact reference. Attribute: type="admin / tech"
|
<domain:contact> 0-n Contact reference. Attribute: type="admin / tech"
|
||||||
|
|
|
@ -19,3 +19,4 @@ Main communication specification through Restful EPP (REPP):
|
||||||
[Domain related functions](repp/v1/domain.md)
|
[Domain related functions](repp/v1/domain.md)
|
||||||
[Domain transfers](repp/v1/domain_transfers.md)
|
[Domain transfers](repp/v1/domain_transfers.md)
|
||||||
[Account related functions](repp/v1/account.md)
|
[Account related functions](repp/v1/account.md)
|
||||||
|
[Nameservers](repp/v1/nameservers.md)
|
||||||
|
|
56
doc/repp/v1/nameservers.md
Normal file
56
doc/repp/v1/nameservers.md
Normal file
|
@ -0,0 +1,56 @@
|
||||||
|
# Nameservers
|
||||||
|
|
||||||
|
## PUT /repp/v1/registrar/nameservers
|
||||||
|
Replaces all name servers of current registrar domains.
|
||||||
|
|
||||||
|
#### Request
|
||||||
|
```
|
||||||
|
PUT /repp/v1/registrar/nameservers
|
||||||
|
Accept: application/json
|
||||||
|
Content-Type: application/json
|
||||||
|
Authorization: Basic dGVzdDp0ZXN0dGVzdA==
|
||||||
|
{
|
||||||
|
"data":{
|
||||||
|
"type": "nameserver",
|
||||||
|
"id": "ns1.example.com",
|
||||||
|
"attributes": {
|
||||||
|
"hostname": "new-ns1.example.com",
|
||||||
|
"ipv4": ["192.0.2.1", "192.0.2.2"],
|
||||||
|
"ipv6": ["2001:db8::1", "2001:db8::2"]
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Response on success
|
||||||
|
```
|
||||||
|
HTTP/1.1 200
|
||||||
|
Content-Type: application/json
|
||||||
|
{
|
||||||
|
"data":{
|
||||||
|
"type": "nameserver",
|
||||||
|
"id": "new-ns1.example.com",
|
||||||
|
"attributes": {
|
||||||
|
"hostname": "new-ns1.example.com",
|
||||||
|
"ipv4": ["192.0.2.1", "192.0.2.2"],
|
||||||
|
"ipv6": ["2001:db8::1", "2001:db8::2"]
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Response on failure
|
||||||
|
```
|
||||||
|
HTTP/1.1 400
|
||||||
|
Content-Type: application/json
|
||||||
|
{
|
||||||
|
"errors":[
|
||||||
|
{
|
||||||
|
"title":"ns1.example.com does not exist"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"title":"192.0.2.1 is not a valid IPv4 address"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
|
@ -2,5 +2,6 @@ FactoryBot.define do
|
||||||
factory :nameserver do
|
factory :nameserver do
|
||||||
sequence(:hostname) { |n| "ns.test#{n}.ee" }
|
sequence(:hostname) { |n| "ns.test#{n}.ee" }
|
||||||
ipv4 '192.168.1.1'
|
ipv4 '192.168.1.1'
|
||||||
|
domain
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -568,8 +568,8 @@ RSpec.describe Domain do
|
||||||
with_versioning do
|
with_versioning do
|
||||||
context 'when saved' do
|
context 'when saved' do
|
||||||
before(:each) do
|
before(:each) do
|
||||||
domain = create(:domain)
|
domain = create(:domain, nameservers_attributes: [attributes_for(:nameserver),
|
||||||
domain.nameservers << create(:nameserver)
|
attributes_for(:nameserver)])
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'creates domain version' do
|
it 'creates domain version' do
|
||||||
|
@ -660,7 +660,7 @@ RSpec.describe Domain do
|
||||||
end
|
end
|
||||||
|
|
||||||
describe 'nameserver validation', db: true do
|
describe 'nameserver validation', db: true do
|
||||||
let(:domain) { described_class.new }
|
let(:domain) { described_class.new(name: 'whatever.test') }
|
||||||
|
|
||||||
it 'rejects less than min' do
|
it 'rejects less than min' do
|
||||||
Setting.ns_min_count = 2
|
Setting.ns_min_count = 2
|
||||||
|
|
|
@ -1,125 +0,0 @@
|
||||||
require 'rails_helper'
|
|
||||||
|
|
||||||
describe Nameserver do
|
|
||||||
before :example do
|
|
||||||
Setting.ds_algorithm = 2
|
|
||||||
Setting.ds_data_allowed = true
|
|
||||||
Setting.ds_data_with_key_allowed = true
|
|
||||||
Setting.key_data_allowed = true
|
|
||||||
|
|
||||||
Setting.dnskeys_min_count = 0
|
|
||||||
Setting.dnskeys_max_count = 9
|
|
||||||
Setting.ns_min_count = 2
|
|
||||||
Setting.ns_max_count = 11
|
|
||||||
|
|
||||||
Setting.transfer_wait_time = 0
|
|
||||||
|
|
||||||
Setting.admin_contacts_min_count = 1
|
|
||||||
Setting.admin_contacts_max_count = 10
|
|
||||||
Setting.tech_contacts_min_count = 0
|
|
||||||
Setting.tech_contacts_max_count = 10
|
|
||||||
|
|
||||||
Setting.client_side_status_editing_enabled = true
|
|
||||||
|
|
||||||
create(:zone, origin: 'ee')
|
|
||||||
end
|
|
||||||
|
|
||||||
context 'with invalid attribute' do
|
|
||||||
before :example do
|
|
||||||
@nameserver = Nameserver.new
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'should not have any versions' do
|
|
||||||
@nameserver.versions.should == []
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
context 'with valid attributes' do
|
|
||||||
before :example do
|
|
||||||
@nameserver = create(:nameserver)
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'should be valid' do
|
|
||||||
@nameserver.valid?
|
|
||||||
@nameserver.errors.full_messages.should match_array([])
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'should be valid twice' do
|
|
||||||
@nameserver = create(:nameserver)
|
|
||||||
@nameserver.valid?
|
|
||||||
@nameserver.errors.full_messages.should match_array([])
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'should have one version' do
|
|
||||||
with_versioning do
|
|
||||||
@nameserver.versions.should == []
|
|
||||||
@nameserver.hostname = 'hostname.ee'
|
|
||||||
@nameserver.save
|
|
||||||
@nameserver.errors.full_messages.should match_array([])
|
|
||||||
@nameserver.versions.size.should == 1
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
context 'with many nameservers' do
|
|
||||||
before :example do
|
|
||||||
@api_user = create(:api_user)
|
|
||||||
@domain_1 = create(:domain, nameservers: [
|
|
||||||
create(:nameserver, hostname: 'ns1.ns.ee'),
|
|
||||||
create(:nameserver, hostname: 'ns2.ns.ee'),
|
|
||||||
create(:nameserver, hostname: 'ns2.test.ee')
|
|
||||||
], registrar: @api_user.registrar)
|
|
||||||
|
|
||||||
@domain_2 = create(:domain, nameservers: [
|
|
||||||
create(:nameserver, hostname: 'ns1.ns.ee'),
|
|
||||||
create(:nameserver, hostname: 'ns2.ns.ee'),
|
|
||||||
create(:nameserver, hostname: 'ns3.test.ee')
|
|
||||||
], registrar: @api_user.registrar)
|
|
||||||
|
|
||||||
@domain_3 = create(:domain, nameservers: [
|
|
||||||
create(:nameserver, hostname: 'ns1.ns.ee'),
|
|
||||||
create(:nameserver, hostname: 'ns2.ns.ee'),
|
|
||||||
create(:nameserver, hostname: 'ns3.test.ee')
|
|
||||||
])
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'should replace hostname ends' do
|
|
||||||
res = Nameserver.replace_hostname_ends(@api_user.registrar.domains, 'ns.ee', 'test.ee')
|
|
||||||
res.should == 'replaced_some'
|
|
||||||
|
|
||||||
@api_user.registrar.nameservers.where("hostname LIKE '%test.ee'").count.should == 4
|
|
||||||
@domain_1.nameservers.pluck(:hostname).should include('ns1.ns.ee', 'ns2.ns.ee', 'ns2.test.ee')
|
|
||||||
@domain_2.nameservers.pluck(:hostname).should include('ns1.test.ee', 'ns2.test.ee', 'ns3.test.ee')
|
|
||||||
|
|
||||||
res = Nameserver.replace_hostname_ends(@api_user.registrar.domains, 'test.ee', 'testing.ee')
|
|
||||||
res.should == 'replaced_all'
|
|
||||||
|
|
||||||
@api_user.registrar.nameservers.where("hostname LIKE '%testing.ee'").count.should == 4
|
|
||||||
@domain_1.nameservers.pluck(:hostname).should include('ns1.ns.ee', 'ns2.ns.ee', 'ns2.testing.ee')
|
|
||||||
@domain_2.nameservers.pluck(:hostname).should include('ns1.testing.ee', 'ns2.testing.ee', 'ns3.testing.ee')
|
|
||||||
|
|
||||||
res = Nameserver.replace_hostname_ends(@api_user.registrar.domains, 'ns.ee', 'test.ee')
|
|
||||||
res.should == 'replaced_all'
|
|
||||||
|
|
||||||
@api_user.registrar.nameservers.where("hostname LIKE '%test.ee'").count.should == 2
|
|
||||||
@domain_1.nameservers.pluck(:hostname).should include('ns1.test.ee', 'ns2.test.ee', 'ns2.testing.ee')
|
|
||||||
@domain_2.nameservers.pluck(:hostname).should include('ns1.testing.ee', 'ns2.testing.ee', 'ns3.testing.ee')
|
|
||||||
@domain_3.nameservers.pluck(:hostname).should include('ns1.ns.ee', 'ns2.ns.ee', 'ns3.test.ee')
|
|
||||||
|
|
||||||
res = Nameserver.replace_hostname_ends(@api_user.registrar.domains, 'xcv.ee', 'test.ee')
|
|
||||||
res.should == 'replaced_none'
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
RSpec.describe Nameserver do
|
|
||||||
describe '::hostnames', db: false do
|
|
||||||
before :example do
|
|
||||||
expect(described_class).to receive(:pluck).with(:hostname).and_return('hostnames')
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'returns names' do
|
|
||||||
expect(described_class.hostnames).to eq('hostnames')
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
11
test/fixtures/contacts.yml
vendored
11
test/fixtures/contacts.yml
vendored
|
@ -42,6 +42,17 @@ acme_ltd:
|
||||||
code: acme-ltd-001
|
code: acme-ltd-001
|
||||||
auth_info: 720b3c
|
auth_info: 720b3c
|
||||||
|
|
||||||
|
jack:
|
||||||
|
name: Jack
|
||||||
|
email: jack@inbox.test
|
||||||
|
phone: '+555.555'
|
||||||
|
ident: 1234
|
||||||
|
ident_type: org
|
||||||
|
registrar: goodnames
|
||||||
|
ident_country_code: US
|
||||||
|
code: jack-001
|
||||||
|
auth_info: e2c440
|
||||||
|
|
||||||
invalid:
|
invalid:
|
||||||
name: any
|
name: any
|
||||||
code: any
|
code: any
|
||||||
|
|
10
test/fixtures/domains.yml
vendored
10
test/fixtures/domains.yml
vendored
|
@ -28,6 +28,16 @@ library:
|
||||||
period: 1
|
period: 1
|
||||||
period_unit: m
|
period_unit: m
|
||||||
|
|
||||||
|
metro:
|
||||||
|
name: metro.test
|
||||||
|
name_dirty: metro.test
|
||||||
|
registrar: goodnames
|
||||||
|
registrant: jack
|
||||||
|
transfer_code: 1071ad
|
||||||
|
valid_to: 2010-07-05
|
||||||
|
period: 1
|
||||||
|
period_unit: m
|
||||||
|
|
||||||
invalid:
|
invalid:
|
||||||
name: invalid.test
|
name: invalid.test
|
||||||
transfer_code: any
|
transfer_code: any
|
||||||
|
|
23
test/fixtures/nameservers.yml
vendored
Normal file
23
test/fixtures/nameservers.yml
vendored
Normal file
|
@ -0,0 +1,23 @@
|
||||||
|
shop_ns1:
|
||||||
|
hostname: ns1.bestnames.test
|
||||||
|
ipv4:
|
||||||
|
- 192.0.2.1
|
||||||
|
ipv6:
|
||||||
|
- 2001:db8::1
|
||||||
|
domain: shop
|
||||||
|
|
||||||
|
shop_ns2:
|
||||||
|
hostname: ns2.bestnames.test
|
||||||
|
ipv4:
|
||||||
|
- 192.0.2.2
|
||||||
|
ipv6:
|
||||||
|
- 2001:db8::2
|
||||||
|
domain: shop
|
||||||
|
|
||||||
|
airport_ns1:
|
||||||
|
hostname: ns1.bestnames.test
|
||||||
|
domain: airport
|
||||||
|
|
||||||
|
metro_ns1:
|
||||||
|
hostname: ns1.bestnames.test
|
||||||
|
domain: metro
|
97
test/integration/api/nameservers/put_test.rb
Normal file
97
test/integration/api/nameservers/put_test.rb
Normal file
|
@ -0,0 +1,97 @@
|
||||||
|
require 'test_helper'
|
||||||
|
|
||||||
|
class APINameserversPutTest < ActionDispatch::IntegrationTest
|
||||||
|
def test_replaces_registrar_nameservers
|
||||||
|
old_nameserver_ids = [nameservers(:shop_ns1).id,
|
||||||
|
nameservers(:airport_ns1).id,
|
||||||
|
nameservers(:metro_ns1).id]
|
||||||
|
request_params = { format: :json, data: { type: 'nameserver', id: 'ns1.bestnames.test',
|
||||||
|
attributes: { hostname: 'ns55.bestnames.test' } } }
|
||||||
|
put '/repp/v1/registrar/nameservers', request_params, { 'HTTP_AUTHORIZATION' => http_auth_key }
|
||||||
|
assert_empty (old_nameserver_ids & registrars(:bestnames).nameservers(true).ids)
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_saves_all_attributes
|
||||||
|
request_params = { format: :json, data: { type: 'nameserver', id: 'ns1.bestnames.test',
|
||||||
|
attributes: { hostname: 'ns55.bestnames.test',
|
||||||
|
ipv4: ['192.0.2.55'],
|
||||||
|
ipv6: ['2001:db8::55'] } } }
|
||||||
|
put '/repp/v1/registrar/nameservers', request_params, { 'HTTP_AUTHORIZATION' => http_auth_key }
|
||||||
|
|
||||||
|
new_nameserver = domains(:shop).nameservers.find_by(hostname: 'ns55.bestnames.test')
|
||||||
|
assert_equal ['192.0.2.55'], new_nameserver.ipv4
|
||||||
|
assert_equal ['2001:DB8::55'], new_nameserver.ipv6
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_keeps_other_nameserver_intact
|
||||||
|
request_params = { format: :json, data: { type: 'nameserver', id: 'ns1.bestnames.test',
|
||||||
|
attributes: { hostname: 'ns55.bestnames.test' } } }
|
||||||
|
|
||||||
|
other_nameserver_hash = nameservers(:shop_ns2).attributes
|
||||||
|
put '/repp/v1/registrar/nameservers', request_params, { 'HTTP_AUTHORIZATION' => http_auth_key }
|
||||||
|
assert_equal other_nameserver_hash, nameservers(:shop_ns2).reload.attributes
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_keeps_other_registrar_nameservers_intact
|
||||||
|
request_params = { format: :json, data: { type: 'nameserver', id: 'ns1.bestnames.test',
|
||||||
|
attributes: { hostname: 'ns55.bestnames.test' } } }
|
||||||
|
|
||||||
|
nameserver_hash = nameservers(:metro_ns1).attributes
|
||||||
|
put '/repp/v1/registrar/nameservers', request_params, { 'HTTP_AUTHORIZATION' => http_auth_key }
|
||||||
|
assert_equal nameserver_hash, nameservers(:metro_ns1).reload.attributes
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_returns_new_nameserver_record
|
||||||
|
request_params = { format: :json, data: { type: 'nameserver', id: 'ns1.bestnames.test',
|
||||||
|
attributes: { hostname: 'ns55.bestnames.test',
|
||||||
|
ipv4: ['192.0.2.55'],
|
||||||
|
ipv6: ['2001:db8::55'] } } }
|
||||||
|
put '/repp/v1/registrar/nameservers', request_params, { 'HTTP_AUTHORIZATION' => http_auth_key }
|
||||||
|
|
||||||
|
assert_response 200
|
||||||
|
assert_equal ({ data: { type: 'nameserver',
|
||||||
|
id: 'ns55.bestnames.test',
|
||||||
|
attributes: { hostname: 'ns55.bestnames.test',
|
||||||
|
ipv4: ['192.0.2.55'],
|
||||||
|
ipv6: ['2001:db8::55'] } } }),
|
||||||
|
JSON.parse(response.body, symbolize_names: true)
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_optional_params
|
||||||
|
request_params = { format: :json, data: { type: 'nameserver', id: 'ns1.bestnames.test',
|
||||||
|
attributes: { hostname: 'ns55.bestnames.test' } } }
|
||||||
|
put '/repp/v1/registrar/nameservers', request_params, { 'HTTP_AUTHORIZATION' => http_auth_key }
|
||||||
|
assert_response 200
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_non_existent_nameserver_hostname
|
||||||
|
request_params = { format: :json, data: { type: 'nameserver', id: 'non-existent.test',
|
||||||
|
attributes: { hostname: 'any.bestnames.test' } } }
|
||||||
|
put '/repp/v1/registrar/nameservers', request_params, { 'HTTP_AUTHORIZATION' => http_auth_key }
|
||||||
|
|
||||||
|
assert_response 404
|
||||||
|
assert_equal ({ errors: [{ title: 'Hostname non-existent.test does not exist' }] }),
|
||||||
|
JSON.parse(response.body, symbolize_names: true)
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_invalid_request_params
|
||||||
|
request_params = { format: :json, data: { type: 'nameserver', id: 'ns1.bestnames.test',
|
||||||
|
attributes: { hostname: '' } } }
|
||||||
|
put '/repp/v1/registrar/nameservers', request_params, { 'HTTP_AUTHORIZATION' => http_auth_key }
|
||||||
|
|
||||||
|
assert_response 400
|
||||||
|
assert_equal ({ errors: [{ title: 'Hostname is missing' }] }),
|
||||||
|
JSON.parse(response.body, symbolize_names: true)
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_unauthenticated
|
||||||
|
put '/repp/v1/registrar/nameservers'
|
||||||
|
assert_response 401
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def http_auth_key
|
||||||
|
ActionController::HttpAuthentication::Basic.encode_credentials('test_bestnames', 'testtest')
|
||||||
|
end
|
||||||
|
end
|
35
test/integration/epp/domain/create/nameservers_test.rb
Normal file
35
test/integration/epp/domain/create/nameservers_test.rb
Normal file
|
@ -0,0 +1,35 @@
|
||||||
|
require 'test_helper'
|
||||||
|
|
||||||
|
class EppDomainCreateNameserversTest < ActionDispatch::IntegrationTest
|
||||||
|
# Glue record requirement
|
||||||
|
def test_nameserver_ip_address_is_required_if_hostname_is_under_the_same_domain
|
||||||
|
request_xml = <<-XML
|
||||||
|
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||||
|
<epp xmlns="https://epp.tld.ee/schema/epp-ee-1.0.xsd">
|
||||||
|
<command>
|
||||||
|
<create>
|
||||||
|
<domain:create xmlns:domain="https://epp.tld.ee/schema/domain-eis-1.0.xsd">
|
||||||
|
<domain:name>new.test</domain:name>
|
||||||
|
<domain:ns>
|
||||||
|
<domain:hostAttr>
|
||||||
|
<domain:hostName>ns1.new.test</domain:hostName>
|
||||||
|
</domain:hostAttr>
|
||||||
|
</domain:ns>
|
||||||
|
<domain:registrant>john-001</domain:registrant>
|
||||||
|
</domain:create>
|
||||||
|
</create>
|
||||||
|
<extension>
|
||||||
|
<eis:extdata xmlns:eis="https://epp.tld.ee/schema/eis-1.0.xsd">
|
||||||
|
<eis:legalDocument type="pdf">test</eis:legalDocument>
|
||||||
|
</eis:extdata>
|
||||||
|
</extension>
|
||||||
|
</command>
|
||||||
|
</epp>
|
||||||
|
XML
|
||||||
|
|
||||||
|
assert_no_difference 'Domain.count' do
|
||||||
|
post '/epp/command/create', { frame: request_xml }, { 'HTTP_COOKIE' => 'session=api_bestnames' }
|
||||||
|
end
|
||||||
|
assert_equal '2003', Nokogiri::XML(response.body).at_css('result')[:code]
|
||||||
|
end
|
||||||
|
end
|
57
test/integration/registrar/nameserver_replacement_test.rb
Normal file
57
test/integration/registrar/nameserver_replacement_test.rb
Normal file
|
@ -0,0 +1,57 @@
|
||||||
|
require 'test_helper'
|
||||||
|
|
||||||
|
class RegistrarNameserverReplacementTest < ActionDispatch::IntegrationTest
|
||||||
|
def setup
|
||||||
|
WebMock.reset!
|
||||||
|
login_as users(:api_goodnames)
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_replaces_current_registrar_nameservers
|
||||||
|
request_body = { data: { type: 'nameserver',
|
||||||
|
id: 'ns1.bestnames.test',
|
||||||
|
attributes: { hostname: 'new-ns.bestnames.test',
|
||||||
|
ipv4: %w[192.0.2.55 192.0.2.56],
|
||||||
|
ipv6: %w[2001:db8::55 2001:db8::56] } } }
|
||||||
|
request_stub = stub_request(:put, /registrar\/nameservers/).with(body: request_body,
|
||||||
|
headers: { 'Content-type' => 'application/json' },
|
||||||
|
basic_auth: ['test_goodnames', 'testtest'])
|
||||||
|
.to_return(body: { data: [{
|
||||||
|
type: 'nameserver',
|
||||||
|
id: 'new-ns.bestnames.test'
|
||||||
|
}] }.to_json, status: 200)
|
||||||
|
|
||||||
|
visit registrar_domains_url
|
||||||
|
click_link 'Replace nameserver'
|
||||||
|
|
||||||
|
fill_in 'Old hostname', with: 'ns1.bestnames.test'
|
||||||
|
fill_in 'New hostname', with: 'new-ns.bestnames.test'
|
||||||
|
fill_in 'ipv4', with: "192.0.2.55\n192.0.2.56"
|
||||||
|
fill_in 'ipv6', with: "2001:db8::55\n2001:db8::56"
|
||||||
|
click_on 'Replace nameserver'
|
||||||
|
|
||||||
|
assert_requested request_stub
|
||||||
|
assert_current_path registrar_domains_path
|
||||||
|
assert_text 'Nameserver have been successfully replaced'
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_fails_gracefully
|
||||||
|
stub_request(:put, /registrar\/nameservers/).to_return(status: 400,
|
||||||
|
body: { errors: [{ title: 'epic fail' }] }.to_json,
|
||||||
|
headers: { 'Content-type' => 'application/json' })
|
||||||
|
|
||||||
|
visit registrar_domains_url
|
||||||
|
click_link 'Replace nameserver'
|
||||||
|
|
||||||
|
fill_in 'Old hostname', with: 'old hostname'
|
||||||
|
fill_in 'New hostname', with: 'new hostname'
|
||||||
|
fill_in 'ipv4', with: 'ipv4'
|
||||||
|
fill_in 'ipv6', with: 'ipv6'
|
||||||
|
click_on 'Replace nameserver'
|
||||||
|
|
||||||
|
assert_text 'epic fail'
|
||||||
|
assert_field 'Old hostname', with: 'old hostname'
|
||||||
|
assert_field 'New hostname', with: 'new hostname'
|
||||||
|
assert_field 'ipv4', with: 'ipv4'
|
||||||
|
assert_field 'ipv6', with: 'ipv6'
|
||||||
|
end
|
||||||
|
end
|
27
test/models/nameserver/glue_record_test.rb
Normal file
27
test/models/nameserver/glue_record_test.rb
Normal file
|
@ -0,0 +1,27 @@
|
||||||
|
require 'test_helper'
|
||||||
|
|
||||||
|
class NameserverGlueRecordTest < ActiveSupport::TestCase
|
||||||
|
def setup
|
||||||
|
@nameserver = nameservers(:shop_ns1)
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_invalid_without_ip_if_glue_record_is_required
|
||||||
|
@nameserver.hostname = 'ns1.shop.test'
|
||||||
|
@nameserver.ipv4 = @nameserver.ipv6 = ''
|
||||||
|
assert @nameserver.invalid?
|
||||||
|
assert_includes @nameserver.errors.full_messages, 'Either IPv4 or IPv6 is required' \
|
||||||
|
' for glue record generation'
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_valid_with_ip_if_glue_record_is_required
|
||||||
|
@nameserver.hostname = 'ns1.shop.test'
|
||||||
|
@nameserver.ipv4 = ['192.0.2.1']
|
||||||
|
@nameserver.ipv6 = ''
|
||||||
|
assert @nameserver.valid?
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_valid_without_ip_if_glue_record_is_not_required
|
||||||
|
@nameserver.ipv4 = @nameserver.ipv6 = ''
|
||||||
|
assert @nameserver.valid?
|
||||||
|
end
|
||||||
|
end
|
81
test/models/nameserver_test.rb
Normal file
81
test/models/nameserver_test.rb
Normal file
|
@ -0,0 +1,81 @@
|
||||||
|
require 'test_helper'
|
||||||
|
|
||||||
|
class NameserverTest < ActiveSupport::TestCase
|
||||||
|
def setup
|
||||||
|
@nameserver = nameservers(:shop_ns1)
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_valid
|
||||||
|
assert @nameserver.valid?
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_invalid_without_domain
|
||||||
|
@nameserver.domain = nil
|
||||||
|
assert @nameserver.invalid?
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_invalid_without_hostname
|
||||||
|
@nameserver.hostname = ''
|
||||||
|
assert @nameserver.invalid?
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_hostname_format_validation
|
||||||
|
@nameserver.hostname = 'foo.bar'
|
||||||
|
assert @nameserver.valid?
|
||||||
|
|
||||||
|
@nameserver.hostname = 'äöüõšž.ÄÖÜÕŠŽ.umlauts'
|
||||||
|
assert @nameserver.valid?
|
||||||
|
|
||||||
|
@nameserver.hostname = 'foo_bar'
|
||||||
|
assert @nameserver.invalid?
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_ipv4_format_validation
|
||||||
|
@nameserver.ipv4 = ['192.0.2.1']
|
||||||
|
assert @nameserver.valid?
|
||||||
|
|
||||||
|
@nameserver.ipv4 = ['0.0.0.256']
|
||||||
|
assert @nameserver.invalid?
|
||||||
|
|
||||||
|
@nameserver.ipv4 = ['192.168.0.0/24']
|
||||||
|
assert @nameserver.invalid?
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_ipv6_format_validation
|
||||||
|
@nameserver.ipv6 = ['2001:db8::1']
|
||||||
|
assert @nameserver.valid?
|
||||||
|
|
||||||
|
@nameserver.ipv6 = ['3ffe:0b00:0000:0001:0000:0000:000a']
|
||||||
|
assert @nameserver.invalid?
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_hostnames
|
||||||
|
assert_equal %w[ns1.bestnames.test
|
||||||
|
ns2.bestnames.test
|
||||||
|
ns1.bestnames.test
|
||||||
|
ns1.bestnames.test], Nameserver.hostnames
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_normalizes_hostname
|
||||||
|
@nameserver.hostname = ' ns1.bestnameS.test.'
|
||||||
|
@nameserver.validate
|
||||||
|
assert_equal 'ns1.bestnames.test', @nameserver.hostname
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_normalizes_ipv4
|
||||||
|
@nameserver.ipv4 = [' 192.0.2.1']
|
||||||
|
@nameserver.validate
|
||||||
|
assert_equal ['192.0.2.1'], @nameserver.ipv4
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_normalizes_ipv6
|
||||||
|
@nameserver.ipv6 = [' 2001:db8::1']
|
||||||
|
@nameserver.validate
|
||||||
|
assert_equal ['2001:DB8::1'], @nameserver.ipv6
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_encodes_hostname_to_punycode
|
||||||
|
@nameserver.hostname = 'ns1.münchen.de'
|
||||||
|
assert_equal 'ns1.xn--mnchen-3ya.de', @nameserver.hostname_puny
|
||||||
|
end
|
||||||
|
end
|
Loading…
Add table
Add a link
Reference in a new issue