mirror of
https://github.com/internetee/registry.git
synced 2025-07-25 03:58:27 +02:00
Add IPv6 support to nameserver
This commit is contained in:
parent
fba13f5576
commit
ed73278620
5 changed files with 34 additions and 29 deletions
|
@ -54,7 +54,7 @@ class Domain < ActiveRecord::Base
|
|||
def attach_objects(ph, parsed_frame)
|
||||
attach_owner_contact(ph[:registrant])
|
||||
attach_contacts(self.class.parse_contacts_from_frame(parsed_frame))
|
||||
attach_nameservers(self.class.parse_nameservers_from_params(ph[:ns]))
|
||||
attach_nameservers(self.class.parse_nameservers_from_frame(parsed_frame))
|
||||
|
||||
errors.empty?
|
||||
end
|
||||
|
@ -100,29 +100,11 @@ class Domain < ActiveRecord::Base
|
|||
end
|
||||
|
||||
def attach_nameservers(ns_list)
|
||||
ns_list.each do |ns|
|
||||
attach_nameserver(ns)
|
||||
ns_list.each do |ns_attrs|
|
||||
self.nameservers.build(ns_attrs)
|
||||
end
|
||||
end
|
||||
|
||||
def attach_nameserver(ns)
|
||||
self.nameservers.build(hostname: ns) and return if ns.is_a?(String)
|
||||
|
||||
attrs = {hostname: ns[:hostName]}
|
||||
|
||||
if ns[:hostAddr]
|
||||
if ns[:hostAddr].is_a?(Array)
|
||||
ns[:hostAddr].each do |ip|
|
||||
attrs[:ipv4] = ip unless attrs[:ipv4]
|
||||
end
|
||||
else
|
||||
attrs[:ipv4] = ns[:hostAddr]
|
||||
end
|
||||
end
|
||||
|
||||
self.nameservers.build(attrs)
|
||||
end
|
||||
|
||||
### RENEW ###
|
||||
|
||||
def renew(cur_exp_date, period, unit='y')
|
||||
|
@ -190,11 +172,23 @@ class Domain < ActiveRecord::Base
|
|||
res
|
||||
end
|
||||
|
||||
def parse_nameservers_from_params(ph)
|
||||
return [] unless ph
|
||||
return ph[:hostObj] if ph[:hostObj]
|
||||
return ph[:hostAttr] if ph[:hostAttr]
|
||||
[]
|
||||
def parse_nameservers_from_frame(parsed_frame)
|
||||
res = []
|
||||
parsed_frame.css('hostAttr').each do |x|
|
||||
res << {
|
||||
hostname: x.css('hostName').first.try(:text),
|
||||
ipv4: x.css('hostAddr[ip="v4"]').first.try(:text),
|
||||
ipv6: x.css('hostAddr[ip="v6"]').first.try(:text)
|
||||
}
|
||||
end
|
||||
|
||||
parsed_frame.css('hostObj').each do |x|
|
||||
res << {
|
||||
hostname: x.text
|
||||
}
|
||||
end
|
||||
|
||||
res
|
||||
end
|
||||
|
||||
def parse_period_unit_from_frame(parsed_frame)
|
||||
|
|
|
@ -2,7 +2,7 @@ class Nameserver < ActiveRecord::Base
|
|||
include EppErrors
|
||||
|
||||
EPP_CODE_MAP = {
|
||||
'2005' => ['Hostname is invalid', 'IPv4 is invalid']
|
||||
'2005' => ['Hostname is invalid', 'IPv4 is invalid', 'IPv6 is invalid']
|
||||
}
|
||||
|
||||
EPP_ATTR_MAP = {
|
||||
|
@ -14,4 +14,5 @@ class Nameserver < ActiveRecord::Base
|
|||
|
||||
validates :hostname, format: { with: /\A(([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\-]*[a-zA-Z0-9])\.)*([A-Za-z0-9]|[A-Za-z0-9][A-Za-z0-9\-]*[A-Za-z0-9])\z/ }
|
||||
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_nil: true }
|
||||
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_nil: true }
|
||||
end
|
||||
|
|
|
@ -60,6 +60,8 @@ en:
|
|||
invalid: 'Hostname is invalid'
|
||||
ipv4:
|
||||
invalid: 'IPv4 is invalid'
|
||||
ipv6:
|
||||
invalid: 'IPv6 is invalid'
|
||||
attributes:
|
||||
domain:
|
||||
name: 'Domain name'
|
||||
|
|
|
@ -105,12 +105,19 @@ describe 'EPP Domain', epp: true do
|
|||
expect(Domain.first.nameservers.count).to eq(2)
|
||||
ns = Domain.first.nameservers.first
|
||||
expect(ns.ipv4).to eq('192.0.2.2')
|
||||
expect(ns.ipv6).to eq('1080:0:0:0:8:800:200C:417A')
|
||||
end
|
||||
|
||||
it 'returns error when nameserver has invalid ip' do
|
||||
it 'returns error when nameserver has invalid ips' 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 'IPv4 is invalid'
|
||||
expect(response[:results][0][:value]).to eq '192.0.2.2.invalid'
|
||||
expect(response[:results][1][:result_code]).to eq '2005'
|
||||
expect(response[:results][1][:msg]).to eq 'IPv6 is invalid'
|
||||
expect(response[:results][1][:value]).to eq 'invalid_ipv6'
|
||||
expect(Domain.count).to eq(0)
|
||||
expect(Nameserver.count).to eq(0)
|
||||
end
|
||||
|
||||
it 'creates a domain with period in days' do
|
||||
|
|
|
@ -12,7 +12,8 @@
|
|||
<domain:hostAddr ip="v4">192.0.2.2.invalid</domain:hostAddr>
|
||||
</domain:hostAttr>
|
||||
<domain:hostAttr>
|
||||
<domain:hostName>ns2.example.net</domain:hostName>
|
||||
<domain:hostName>ns2.example.net</domain:hostName>
|
||||
<domain:hostAddr ip="v6">invalid_ipv6</domain:hostAddr>
|
||||
</domain:hostAttr>
|
||||
</domain:ns>
|
||||
<domain:registrant>jd1234</domain:registrant>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue