mirror of
https://github.com/internetee/registry.git
synced 2025-08-05 17:28:18 +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
|
@ -204,14 +204,14 @@ describe 'EPP Domain', epp: true do
|
|||
end
|
||||
|
||||
it 'validates nameserver ipv4 when in same zone as domain' do
|
||||
xml_params = {
|
||||
nameservers: [
|
||||
{ hostObj: 'ns1.example.ee' },
|
||||
{ hostObj: 'ns2.example.ee' }
|
||||
xml = domain_create_xml({
|
||||
ns: [
|
||||
{ hostObj: { value: 'ns1.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[:msg]).to eq('IPv4 is missing')
|
||||
|
@ -228,7 +228,7 @@ describe 'EPP Domain', epp: true do
|
|||
it 'does not create reserved domain' do
|
||||
Fabricate(:reserved_domain)
|
||||
|
||||
xml = domain_create_xml(name: '1162.ee')
|
||||
xml = domain_create_xml(name: { value: '1162.ee' })
|
||||
|
||||
response = epp_request(xml, :xml)
|
||||
expect(response[:result_code]).to eq('2302')
|
||||
|
@ -245,7 +245,7 @@ describe 'EPP Domain', epp: true do
|
|||
end
|
||||
|
||||
it 'does not create domain without nameservers' do
|
||||
xml = domain_create_xml(nameservers: [])
|
||||
xml = domain_create_xml(ns: [])
|
||||
response = epp_request(xml, :xml)
|
||||
expect(response[:result_code]).to eq('2003')
|
||||
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
|
||||
nameservers = []
|
||||
14.times { |i| nameservers << { hostObj: "ns#{i}.example.net" } }
|
||||
xml = domain_create_xml(nameservers: nameservers)
|
||||
14.times { |i| nameservers << { hostObj: { value: "ns#{i}.example.net" } } }
|
||||
xml = domain_create_xml(ns: nameservers)
|
||||
|
||||
response = epp_request(xml, :xml)
|
||||
expect(response[:result_code]).to eq('2004')
|
||||
|
@ -262,7 +262,13 @@ describe 'EPP Domain', epp: true do
|
|||
end
|
||||
|
||||
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)
|
||||
expect(response[:result_code]).to eq('2005')
|
||||
|
@ -299,7 +305,9 @@ describe 'EPP Domain', epp: true do
|
|||
end
|
||||
|
||||
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)
|
||||
expect(response[:results][0][:result_code]).to eq('2004')
|
||||
|
@ -316,7 +324,11 @@ describe 'EPP Domain', epp: true do
|
|||
end
|
||||
|
||||
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)
|
||||
expect(response[:result_code]).to eq('1000')
|
||||
|
@ -331,7 +343,11 @@ describe 'EPP Domain', epp: true do
|
|||
end
|
||||
|
||||
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)
|
||||
expect(response[:result_code]).to eq('2306')
|
||||
|
|
|
@ -53,18 +53,33 @@ module Epp
|
|||
### REQUEST TEMPLATES ###
|
||||
|
||||
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] || [
|
||||
{ contact_value: 'sh8013', contact_type: 'admin' },
|
||||
{ contact_value: 'sh8013', contact_type: 'tech' },
|
||||
{ contact_value: 'sh801333', contact_type: 'tech' }
|
||||
]
|
||||
defaults = {
|
||||
name: { value: 'example.ee' },
|
||||
period: { value: '1', attrs: { unit: 'y' } },
|
||||
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
|
||||
|
||||
|
@ -73,24 +88,7 @@ module Epp
|
|||
xml.command do
|
||||
xml.create do
|
||||
xml.tag!('domain:create', 'xmlns:domain' => 'urn:ietf:params:xml:ns:domain-1.0') do
|
||||
|
||||
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?
|
||||
generate_xml_from_hash(xml_params, xml, 'domain')
|
||||
end
|
||||
end
|
||||
xml.clTRID 'ABC-12345'
|
||||
|
@ -197,10 +195,16 @@ module Epp
|
|||
end
|
||||
# Value is an array
|
||||
elsif v.is_a?(Array)
|
||||
xml.tag!("#{ns}:#{k}") do
|
||||
if k.to_s.start_with?('_')
|
||||
v.each do |x|
|
||||
generate_xml_from_hash(x, xml, ns)
|
||||
end
|
||||
else
|
||||
xml.tag!("#{ns}:#{k}") do
|
||||
v.each do |x|
|
||||
generate_xml_from_hash(x, xml, ns)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue