From 793b0d22ffd858aa8230ef644d01a854bcdbacf0 Mon Sep 17 00:00:00 2001 From: Martin Lensment Date: Wed, 13 Aug 2014 17:11:10 +0300 Subject: [PATCH] Add different ip version support to nameserver --- app/models/domain.rb | 4 ++-- app/models/nameserver.rb | 4 ++-- config/locales/en.yml | 6 +++--- db/migrate/20140813135408_add_ipv6_to_nameserver.rb | 6 ++++++ db/schema.rb | 5 +++-- spec/epp/domain_spec.rb | 4 ++-- spec/support/epp.rb | 2 -- 7 files changed, 18 insertions(+), 13 deletions(-) create mode 100644 db/migrate/20140813135408_add_ipv6_to_nameserver.rb diff --git a/app/models/domain.rb b/app/models/domain.rb index 7cda78657..1c85df786 100644 --- a/app/models/domain.rb +++ b/app/models/domain.rb @@ -113,10 +113,10 @@ class Domain < ActiveRecord::Base if ns[:hostAddr] if ns[:hostAddr].is_a?(Array) ns[:hostAddr].each do |ip| - attrs[:ip] = ip unless attrs[:ip] + attrs[:ipv4] = ip unless attrs[:ipv4] end else - attrs[:ip] = ns[:hostAddr] + attrs[:ipv4] = ns[:hostAddr] end end diff --git a/app/models/nameserver.rb b/app/models/nameserver.rb index e8b24b0a8..d866bd5f6 100644 --- a/app/models/nameserver.rb +++ b/app/models/nameserver.rb @@ -2,7 +2,7 @@ class Nameserver < ActiveRecord::Base include EppErrors EPP_CODE_MAP = { - '2005' => ['Hostname is invalid', 'IP is invalid'] + '2005' => ['Hostname is invalid', 'IPv4 is invalid'] } EPP_ATTR_MAP = { @@ -13,5 +13,5 @@ class Nameserver < ActiveRecord::Base 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 :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 diff --git a/config/locales/en.yml b/config/locales/en.yml index 65effec09..0b1f12d7e 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -51,15 +51,15 @@ en: nameservers: out_of_range: 'Nameservers count must be between %{min}-%{max}' hostname_invalid: 'Hostname is invalid' - ip_invalid: 'IP is invalid' + ip_invalid: 'IPv4 is invalid' period: out_of_range: 'Period must add up to 1, 2 or 3 years' nameserver: attributes: hostname: invalid: 'Hostname is invalid' - ip: - invalid: 'IP is invalid' + ipv4: + invalid: 'IPv4 is invalid' attributes: domain: name: 'Domain name' diff --git a/db/migrate/20140813135408_add_ipv6_to_nameserver.rb b/db/migrate/20140813135408_add_ipv6_to_nameserver.rb new file mode 100644 index 000000000..37f763044 --- /dev/null +++ b/db/migrate/20140813135408_add_ipv6_to_nameserver.rb @@ -0,0 +1,6 @@ +class AddIpv6ToNameserver < ActiveRecord::Migration + def change + rename_column :nameservers, :ip, :ipv4 + add_column :nameservers, :ipv6, :string + end +end diff --git a/db/schema.rb b/db/schema.rb index ff86a607d..1f10eb9b4 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # 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 enable_extension "plpgsql" @@ -108,10 +108,11 @@ ActiveRecord::Schema.define(version: 20140813102245) do create_table "nameservers", force: true do |t| t.string "hostname" - t.string "ip" + t.string "ipv4" t.integer "ns_set_id" t.datetime "created_at" t.datetime "updated_at" + t.string "ipv6" end create_table "nameservers_ns_sets", force: true do |t| diff --git a/spec/epp/domain_spec.rb b/spec/epp/domain_spec.rb index abbcba2e4..c4a0e2bf0 100644 --- a/spec/epp/domain_spec.rb +++ b/spec/epp/domain_spec.rb @@ -104,13 +104,13 @@ describe 'EPP Domain', epp: true do response = epp_request('domains/create_w_host_attrs.xml') expect(Domain.first.nameservers.count).to eq(2) ns = Domain.first.nameservers.first - expect(ns.ip).to eq('192.0.2.2') + expect(ns.ipv4).to eq('192.0.2.2') end it 'returns error when nameserver has invalid ip' 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 'IP is invalid' + expect(response[:results][0][:msg]).to eq 'IPv4 is invalid' end it 'creates a domain with period in days' do diff --git a/spec/support/epp.rb b/spec/support/epp.rb index e834313db..29d26c737 100644 --- a/spec/support/epp.rb +++ b/spec/support/epp.rb @@ -43,8 +43,6 @@ module Epp ### REQUEST TEMPLATES ### - # THIS FEATURE IS EXPERIMENTAL AND NOT IN USE ATM - def domain_create_xml(xml_params={}) xml_params[:nameservers] = xml_params[:nameservers] || [{hostObj: 'ns1.example.net'}, {hostObj: 'ns2.example.net'}] xml_params[:contacts] = xml_params[:contacts] || [