Add different ip version support to nameserver

This commit is contained in:
Martin Lensment 2014-08-13 17:11:10 +03:00
parent a846a51444
commit 793b0d22ff
7 changed files with 18 additions and 13 deletions

View file

@ -113,10 +113,10 @@ class Domain < ActiveRecord::Base
if ns[:hostAddr] if ns[:hostAddr]
if ns[:hostAddr].is_a?(Array) if ns[:hostAddr].is_a?(Array)
ns[:hostAddr].each do |ip| ns[:hostAddr].each do |ip|
attrs[:ip] = ip unless attrs[:ip] attrs[:ipv4] = ip unless attrs[:ipv4]
end end
else else
attrs[:ip] = ns[:hostAddr] attrs[:ipv4] = ns[:hostAddr]
end end
end end

View file

@ -2,7 +2,7 @@ class Nameserver < ActiveRecord::Base
include EppErrors include EppErrors
EPP_CODE_MAP = { EPP_CODE_MAP = {
'2005' => ['Hostname is invalid', 'IP is invalid'] '2005' => ['Hostname is invalid', 'IPv4 is invalid']
} }
EPP_ATTR_MAP = { EPP_ATTR_MAP = {
@ -13,5 +13,5 @@ class Nameserver < ActiveRecord::Base
has_and_belongs_to_many :domains has_and_belongs_to_many :domains
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 :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 :ip, 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 :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 }
end end

View file

@ -51,15 +51,15 @@ en:
nameservers: nameservers:
out_of_range: 'Nameservers count must be between %{min}-%{max}' out_of_range: 'Nameservers count must be between %{min}-%{max}'
hostname_invalid: 'Hostname is invalid' hostname_invalid: 'Hostname is invalid'
ip_invalid: 'IP is invalid' ip_invalid: 'IPv4 is invalid'
period: period:
out_of_range: 'Period must add up to 1, 2 or 3 years' out_of_range: 'Period must add up to 1, 2 or 3 years'
nameserver: nameserver:
attributes: attributes:
hostname: hostname:
invalid: 'Hostname is invalid' invalid: 'Hostname is invalid'
ip: ipv4:
invalid: 'IP is invalid' invalid: 'IPv4 is invalid'
attributes: attributes:
domain: domain:
name: 'Domain name' name: 'Domain name'

View file

@ -0,0 +1,6 @@
class AddIpv6ToNameserver < ActiveRecord::Migration
def change
rename_column :nameservers, :ip, :ipv4
add_column :nameservers, :ipv6, :string
end
end

View file

@ -11,7 +11,7 @@
# #
# It's strongly recommended that you check this file into your version control system. # It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 20140813102245) do ActiveRecord::Schema.define(version: 20140813135408) do
# These are extensions that must be enabled in order to support this database # These are extensions that must be enabled in order to support this database
enable_extension "plpgsql" enable_extension "plpgsql"
@ -108,10 +108,11 @@ ActiveRecord::Schema.define(version: 20140813102245) do
create_table "nameservers", force: true do |t| create_table "nameservers", force: true do |t|
t.string "hostname" t.string "hostname"
t.string "ip" t.string "ipv4"
t.integer "ns_set_id" t.integer "ns_set_id"
t.datetime "created_at" t.datetime "created_at"
t.datetime "updated_at" t.datetime "updated_at"
t.string "ipv6"
end end
create_table "nameservers_ns_sets", force: true do |t| create_table "nameservers_ns_sets", force: true do |t|

View file

@ -104,13 +104,13 @@ describe 'EPP Domain', epp: true do
response = epp_request('domains/create_w_host_attrs.xml') response = epp_request('domains/create_w_host_attrs.xml')
expect(Domain.first.nameservers.count).to eq(2) expect(Domain.first.nameservers.count).to eq(2)
ns = Domain.first.nameservers.first ns = Domain.first.nameservers.first
expect(ns.ip).to eq('192.0.2.2') expect(ns.ipv4).to eq('192.0.2.2')
end end
it 'returns error when nameserver has invalid ip' do it 'returns error when nameserver has invalid ip' do
response = epp_request('domains/create_w_invalid_ns_ip.xml') response = epp_request('domains/create_w_invalid_ns_ip.xml')
expect(response[:results][0][:result_code]).to eq '2005' expect(response[:results][0][:result_code]).to eq '2005'
expect(response[:results][0][:msg]).to eq 'IP is invalid' expect(response[:results][0][:msg]).to eq 'IPv4 is invalid'
end end
it 'creates a domain with period in days' do it 'creates a domain with period in days' do

View file

@ -43,8 +43,6 @@ module Epp
### REQUEST TEMPLATES ### ### REQUEST TEMPLATES ###
# THIS FEATURE IS EXPERIMENTAL AND NOT IN USE ATM
def domain_create_xml(xml_params={}) def domain_create_xml(xml_params={})
xml_params[:nameservers] = xml_params[:nameservers] || [{hostObj: 'ns1.example.net'}, {hostObj: 'ns2.example.net'}] xml_params[:nameservers] = xml_params[:nameservers] || [{hostObj: 'ns1.example.net'}, {hostObj: 'ns2.example.net'}]
xml_params[:contacts] = xml_params[:contacts] || [ xml_params[:contacts] = xml_params[:contacts] || [