mirror of
https://github.com/internetee/registry.git
synced 2025-07-01 16:53:37 +02:00
Refactor domain create xml builder, add dnskey model
This commit is contained in:
parent
b85420a598
commit
7d7a399ead
8 changed files with 102 additions and 45 deletions
|
@ -43,7 +43,7 @@ class Client::DomainsController < ClientController
|
||||||
redirect_to [:client, @domain]
|
redirect_to [:client, @domain]
|
||||||
else
|
else
|
||||||
build_associations
|
build_associations
|
||||||
flash[:alert] = I18n.t('shared.failed_to_update_domain')
|
flash.now[:alert] = I18n.t('shared.failed_to_update_domain')
|
||||||
render 'edit'
|
render 'edit'
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
3
app/models/dnskey.rb
Normal file
3
app/models/dnskey.rb
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
class Dnskey < ActiveRecord::Base
|
||||||
|
belongs_to :domain
|
||||||
|
end
|
|
@ -27,6 +27,8 @@ class Domain < ActiveRecord::Base
|
||||||
|
|
||||||
has_many :domain_transfers, dependent: :delete_all
|
has_many :domain_transfers, dependent: :delete_all
|
||||||
|
|
||||||
|
has_many :dnskeys, dependent: :delete_all
|
||||||
|
|
||||||
delegate :code, to: :owner_contact, prefix: true
|
delegate :code, to: :owner_contact, prefix: true
|
||||||
delegate :email, to: :owner_contact, prefix: true
|
delegate :email, to: :owner_contact, prefix: true
|
||||||
delegate :ident, to: :owner_contact, prefix: true
|
delegate :ident, to: :owner_contact, prefix: true
|
||||||
|
|
|
@ -42,6 +42,7 @@ class Epp::EppDomain < Domain
|
||||||
attach_contacts(self.class.parse_contacts_from_frame(parsed_frame))
|
attach_contacts(self.class.parse_contacts_from_frame(parsed_frame))
|
||||||
attach_nameservers(self.class.parse_nameservers_from_frame(parsed_frame))
|
attach_nameservers(self.class.parse_nameservers_from_frame(parsed_frame))
|
||||||
attach_statuses(self.class.parse_statuses_from_frame(parsed_frame))
|
attach_statuses(self.class.parse_statuses_from_frame(parsed_frame))
|
||||||
|
attach_dnskeys(self.class.parse_dnskeys_from_frame(parsed_frame))
|
||||||
|
|
||||||
errors.empty?
|
errors.empty?
|
||||||
end
|
end
|
||||||
|
@ -166,6 +167,12 @@ class Epp::EppDomain < Domain
|
||||||
domain_statuses.delete(to_delete)
|
domain_statuses.delete(to_delete)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def attach_dnskeys(dnskey_list)
|
||||||
|
dnskey_list.each do |dnskey_attrs|
|
||||||
|
dnskeys.build(dnskey_attrs)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
### RENEW ###
|
### RENEW ###
|
||||||
|
|
||||||
def renew(cur_exp_date, period, unit = 'y')
|
def renew(cur_exp_date, period, unit = 'y')
|
||||||
|
@ -329,6 +336,12 @@ class Epp::EppDomain < Domain
|
||||||
res
|
res
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def parse_dnskeys_from_frame(parsed_frame)
|
||||||
|
res = []
|
||||||
|
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
def check_availability(domains)
|
def check_availability(domains)
|
||||||
domains = [domains] if domains.is_a?(String)
|
domains = [domains] if domains.is_a?(String)
|
||||||
|
|
||||||
|
|
11
db/migrate/20141001085322_create_dnskeys.rb
Normal file
11
db/migrate/20141001085322_create_dnskeys.rb
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
class CreateDnskeys < ActiveRecord::Migration
|
||||||
|
def change
|
||||||
|
create_table :dnskeys do |t|
|
||||||
|
t.integer :domain_id
|
||||||
|
t.integer :flags
|
||||||
|
t.integer :protocol
|
||||||
|
t.integer :alg
|
||||||
|
t.string :public_key
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
10
db/schema.rb
10
db/schema.rb
|
@ -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: 20140930093039) do
|
ActiveRecord::Schema.define(version: 20141001085322) 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"
|
||||||
|
@ -68,6 +68,14 @@ ActiveRecord::Schema.define(version: 20140930093039) do
|
||||||
t.datetime "updated_at"
|
t.datetime "updated_at"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
create_table "dnskeys", force: true do |t|
|
||||||
|
t.integer "domain_id"
|
||||||
|
t.integer "flags"
|
||||||
|
t.integer "protocol"
|
||||||
|
t.integer "alg"
|
||||||
|
t.string "public_key"
|
||||||
|
end
|
||||||
|
|
||||||
create_table "domain_contacts", force: true do |t|
|
create_table "domain_contacts", force: true do |t|
|
||||||
t.integer "contact_id"
|
t.integer "contact_id"
|
||||||
t.integer "domain_id"
|
t.integer "domain_id"
|
||||||
|
|
|
@ -204,14 +204,14 @@ describe 'EPP Domain', epp: true do
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'validates nameserver ipv4 when in same zone as domain' do
|
it 'validates nameserver ipv4 when in same zone as domain' do
|
||||||
xml_params = {
|
xml = domain_create_xml({
|
||||||
nameservers: [
|
ns: [
|
||||||
{ hostObj: 'ns1.example.ee' },
|
{ hostObj: { value: 'ns1.example.ee' } },
|
||||||
{ hostObj: 'ns2.example.ee' }
|
{ hostObj: { value: 'ns2.example.ee' } }
|
||||||
]
|
]
|
||||||
}
|
})
|
||||||
|
|
||||||
response = epp_request(domain_create_xml(xml_params), :xml)
|
response = epp_request(xml, :xml)
|
||||||
|
|
||||||
expect(response[:result_code]).to eq('2306')
|
expect(response[:result_code]).to eq('2306')
|
||||||
expect(response[:msg]).to eq('IPv4 is missing')
|
expect(response[:msg]).to eq('IPv4 is missing')
|
||||||
|
@ -228,7 +228,7 @@ describe 'EPP Domain', epp: true do
|
||||||
it 'does not create reserved domain' do
|
it 'does not create reserved domain' do
|
||||||
Fabricate(:reserved_domain)
|
Fabricate(:reserved_domain)
|
||||||
|
|
||||||
xml = domain_create_xml(name: '1162.ee')
|
xml = domain_create_xml(name: { value: '1162.ee' })
|
||||||
|
|
||||||
response = epp_request(xml, :xml)
|
response = epp_request(xml, :xml)
|
||||||
expect(response[:result_code]).to eq('2302')
|
expect(response[:result_code]).to eq('2302')
|
||||||
|
@ -245,7 +245,7 @@ describe 'EPP Domain', epp: true do
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'does not create domain without nameservers' do
|
it 'does not create domain without nameservers' do
|
||||||
xml = domain_create_xml(nameservers: [])
|
xml = domain_create_xml(ns: [])
|
||||||
response = epp_request(xml, :xml)
|
response = epp_request(xml, :xml)
|
||||||
expect(response[:result_code]).to eq('2003')
|
expect(response[:result_code]).to eq('2003')
|
||||||
expect(response[:msg]).to eq('Required parameter missing: ns')
|
expect(response[:msg]).to eq('Required parameter missing: ns')
|
||||||
|
@ -253,8 +253,8 @@ describe 'EPP Domain', epp: true do
|
||||||
|
|
||||||
it 'does not create domain with too many nameservers' do
|
it 'does not create domain with too many nameservers' do
|
||||||
nameservers = []
|
nameservers = []
|
||||||
14.times { |i| nameservers << { hostObj: "ns#{i}.example.net" } }
|
14.times { |i| nameservers << { hostObj: { value: "ns#{i}.example.net" } } }
|
||||||
xml = domain_create_xml(nameservers: nameservers)
|
xml = domain_create_xml(ns: nameservers)
|
||||||
|
|
||||||
response = epp_request(xml, :xml)
|
response = epp_request(xml, :xml)
|
||||||
expect(response[:result_code]).to eq('2004')
|
expect(response[:result_code]).to eq('2004')
|
||||||
|
@ -262,7 +262,13 @@ describe 'EPP Domain', epp: true do
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'returns error when invalid nameservers are present' do
|
it 'returns error when invalid nameservers are present' do
|
||||||
xml = domain_create_xml(nameservers: [{ hostObj: 'invalid1-' }, { hostObj: '-invalid2' }])
|
xml = domain_create_xml({
|
||||||
|
ns: [
|
||||||
|
{ hostObj: { value: 'invalid1-' } },
|
||||||
|
{ hostObj: { value: '-invalid2' } },
|
||||||
|
]
|
||||||
|
|
||||||
|
})
|
||||||
|
|
||||||
response = epp_request(xml, :xml)
|
response = epp_request(xml, :xml)
|
||||||
expect(response[:result_code]).to eq('2005')
|
expect(response[:result_code]).to eq('2005')
|
||||||
|
@ -299,7 +305,9 @@ describe 'EPP Domain', epp: true do
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'does not create a domain with invalid period' do
|
it 'does not create a domain with invalid period' do
|
||||||
xml = domain_create_xml(period_value: 367, period_unit: 'd')
|
xml = domain_create_xml({
|
||||||
|
period: {value: '367', attrs: { unit: 'd' } }
|
||||||
|
})
|
||||||
|
|
||||||
response = epp_request(xml, :xml)
|
response = epp_request(xml, :xml)
|
||||||
expect(response[:results][0][:result_code]).to eq('2004')
|
expect(response[:results][0][:result_code]).to eq('2004')
|
||||||
|
@ -316,7 +324,11 @@ describe 'EPP Domain', epp: true do
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'creates a domain with contacts' do
|
it 'creates a domain with contacts' do
|
||||||
xml = domain_create_xml(contacts: [{ contact_value: 'sh8013', contact_type: 'admin' }])
|
xml = domain_create_xml({
|
||||||
|
_other: [
|
||||||
|
{ contact: { value: 'sh8013', attrs: { type: 'admin' } } }
|
||||||
|
]
|
||||||
|
})
|
||||||
|
|
||||||
response = epp_request(xml, :xml)
|
response = epp_request(xml, :xml)
|
||||||
expect(response[:result_code]).to eq('1000')
|
expect(response[:result_code]).to eq('1000')
|
||||||
|
@ -331,7 +343,11 @@ describe 'EPP Domain', epp: true do
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'does not create a domain without admin contact' do
|
it 'does not create a domain without admin contact' do
|
||||||
xml = domain_create_xml(contacts: [{ contact_value: 'sh8013', contact_type: 'tech' }])
|
xml = domain_create_xml({
|
||||||
|
_other: [
|
||||||
|
{ contact: { value: 'sh8013', attrs: { type: 'tech' } } }
|
||||||
|
]
|
||||||
|
})
|
||||||
|
|
||||||
response = epp_request(xml, :xml)
|
response = epp_request(xml, :xml)
|
||||||
expect(response[:result_code]).to eq('2306')
|
expect(response[:result_code]).to eq('2306')
|
||||||
|
|
|
@ -53,18 +53,33 @@ module Epp
|
||||||
### REQUEST TEMPLATES ###
|
### REQUEST TEMPLATES ###
|
||||||
|
|
||||||
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[:contacts] = xml_params[:contacts] || [
|
defaults = {
|
||||||
{ contact_value: 'sh8013', contact_type: 'admin' },
|
name: { value: 'example.ee' },
|
||||||
{ contact_value: 'sh8013', contact_type: 'tech' },
|
period: { value: '1', attrs: { unit: 'y' } },
|
||||||
{ contact_value: 'sh801333', contact_type: 'tech' }
|
ns: [
|
||||||
]
|
{ hostObj: { value: 'ns1.example.com' } },
|
||||||
|
{ hostObj: { value: 'ns2.example.com' } }
|
||||||
|
],
|
||||||
|
registrant: { value: 'jd1234' },
|
||||||
|
dnssec: [
|
||||||
|
{
|
||||||
|
dnskey: {
|
||||||
|
flags: { value: '257' },
|
||||||
|
protocol: { value: '3' },
|
||||||
|
alg: { value: '5' },
|
||||||
|
pubKey: { value: 'AwEAAddt2AkLfYGKgiEZB5SmIF8EvrjxNMH6HtxWEA4RJ9Ao6LCWheg8' }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
|
_other: [
|
||||||
|
{ contact: { value: 'sh8013', attrs: { type: 'admin' } } },
|
||||||
|
{ contact: { value: 'sh8013', attrs: { type: 'tech' } } },
|
||||||
|
{ contact: { value: 'sh801333', attrs: { type: 'tech' } } }
|
||||||
|
],
|
||||||
|
}
|
||||||
|
|
||||||
# {hostAttr: {hostName: 'ns1.example.net', hostAddr_value: '192.0.2.2', hostAddr_ip}}
|
xml_params = defaults.deep_merge(xml_params)
|
||||||
|
|
||||||
xml = Builder::XmlMarkup.new
|
xml = Builder::XmlMarkup.new
|
||||||
|
|
||||||
|
@ -73,24 +88,7 @@ module Epp
|
||||||
xml.command do
|
xml.command do
|
||||||
xml.create do
|
xml.create do
|
||||||
xml.tag!('domain:create', 'xmlns:domain' => 'urn:ietf:params:xml:ns:domain-1.0') do
|
xml.tag!('domain:create', 'xmlns:domain' => 'urn:ietf:params:xml:ns:domain-1.0') do
|
||||||
|
generate_xml_from_hash(xml_params, xml, 'domain')
|
||||||
xml.tag!('domain:name', (xml_params[:name] || 'example.ee')) if xml_params[:name] != false
|
|
||||||
|
|
||||||
if xml_params[:period] != false
|
|
||||||
xml.tag!('domain:period', (xml_params[:period_value] || 1), 'unit' => (xml_params[:period_unit] || 'y'))
|
|
||||||
end
|
|
||||||
|
|
||||||
xml.tag!('domain:ns') do
|
|
||||||
xml_params[:nameservers].each do |x|
|
|
||||||
xml.tag!('domain:hostObj', x[:hostObj])
|
|
||||||
end
|
|
||||||
end if xml_params[:nameservers].any?
|
|
||||||
|
|
||||||
xml.tag!('domain:registrant', (xml_params[:registrant] || 'jd1234')) if xml_params[:registrant] != false
|
|
||||||
|
|
||||||
xml_params[:contacts].each do |x|
|
|
||||||
xml.tag!('domain:contact', x[:contact_value], 'type' => (x[:contact_type]))
|
|
||||||
end if xml_params[:contacts].any?
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
xml.clTRID 'ABC-12345'
|
xml.clTRID 'ABC-12345'
|
||||||
|
@ -197,6 +195,11 @@ module Epp
|
||||||
end
|
end
|
||||||
# Value is an array
|
# Value is an array
|
||||||
elsif v.is_a?(Array)
|
elsif v.is_a?(Array)
|
||||||
|
if k.to_s.start_with?('_')
|
||||||
|
v.each do |x|
|
||||||
|
generate_xml_from_hash(x, xml, ns)
|
||||||
|
end
|
||||||
|
else
|
||||||
xml.tag!("#{ns}:#{k}") do
|
xml.tag!("#{ns}:#{k}") do
|
||||||
v.each do |x|
|
v.each do |x|
|
||||||
generate_xml_from_hash(x, xml, ns)
|
generate_xml_from_hash(x, xml, ns)
|
||||||
|
@ -205,6 +208,7 @@ module Epp
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
def domain_transfer_xml(xml_params = {})
|
def domain_transfer_xml(xml_params = {})
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue