mirror of
https://github.com/internetee/registry.git
synced 2025-05-17 09:57:23 +02:00
Create login xml builder
This commit is contained in:
parent
5464e4c342
commit
6b8d03a645
3 changed files with 68 additions and 11 deletions
|
@ -952,8 +952,6 @@ describe 'EPP Domain', epp: true do
|
||||||
]
|
]
|
||||||
})
|
})
|
||||||
|
|
||||||
puts Nokogiri::XML(xml).to_s
|
|
||||||
|
|
||||||
epp_request(xml, :xml)
|
epp_request(xml, :xml)
|
||||||
|
|
||||||
expect(d.dnskeys.count).to eq(1)
|
expect(d.dnskeys.count).to eq(1)
|
||||||
|
|
|
@ -2,6 +2,31 @@ require 'rails_helper'
|
||||||
|
|
||||||
describe 'EPP Helper', epp: true do
|
describe 'EPP Helper', epp: true do
|
||||||
context 'in context of Domain' do
|
context 'in context of Domain' do
|
||||||
|
it 'generates valid login xml' do
|
||||||
|
expected = Nokogiri::XML('<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||||
|
<epp xmlns="urn:ietf:params:xml:ns:epp-1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" '\
|
||||||
|
'xsi:schemaLocation="urn:ietf:params:xml:ns:epp-1.0 epp-1.0.xsd">
|
||||||
|
<command>
|
||||||
|
<login>
|
||||||
|
<clID>gitlab</clID>
|
||||||
|
<pw>ghyt9e4fu</pw>
|
||||||
|
<options>
|
||||||
|
<version>1.0</version>
|
||||||
|
<lang>en</lang>
|
||||||
|
</options>
|
||||||
|
<svcs>
|
||||||
|
<objURI>urn:ietf:params:xml:ns:contact-1.0</objURI>
|
||||||
|
</svcs>
|
||||||
|
</login>
|
||||||
|
<clTRID>ABC-12345</clTRID>
|
||||||
|
</command>
|
||||||
|
</epp>
|
||||||
|
').to_s.squish
|
||||||
|
|
||||||
|
generated = Nokogiri::XML(login_xml).to_s.squish
|
||||||
|
expect(generated).to eq(expected)
|
||||||
|
end
|
||||||
|
|
||||||
it 'generates valid create xml' do
|
it 'generates valid create xml' do
|
||||||
expected = Nokogiri::XML('<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
expected = Nokogiri::XML('<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||||
<epp xmlns="urn:ietf:params:xml:ns:epp-1.0">
|
<epp xmlns="urn:ietf:params:xml:ns:epp-1.0">
|
||||||
|
|
|
@ -52,6 +52,40 @@ module Epp
|
||||||
|
|
||||||
### REQUEST TEMPLATES ###
|
### REQUEST TEMPLATES ###
|
||||||
|
|
||||||
|
def login_xml(xml_params = {})
|
||||||
|
defaults = {
|
||||||
|
clID: { value: 'gitlab' },
|
||||||
|
pw: { value: 'ghyt9e4fu' },
|
||||||
|
options: {
|
||||||
|
version: { value: '1.0' },
|
||||||
|
lang: { value: 'en' }
|
||||||
|
},
|
||||||
|
svcs: {
|
||||||
|
_objURIs: [
|
||||||
|
objURI: { value: 'urn:ietf:params:xml:ns:contact-1.0' }
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
xml_params = defaults.deep_merge(xml_params)
|
||||||
|
|
||||||
|
xml = Builder::XmlMarkup.new
|
||||||
|
|
||||||
|
xml.instruct!(:xml, standalone: 'no')
|
||||||
|
xml.epp(
|
||||||
|
'xmlns' => 'urn:ietf:params:xml:ns:epp-1.0',
|
||||||
|
'xmlns:xsi' => 'http://www.w3.org/2001/XMLSchema-instance',
|
||||||
|
'xsi:schemaLocation' => 'urn:ietf:params:xml:ns:epp-1.0 epp-1.0.xsd'
|
||||||
|
) do
|
||||||
|
xml.command do
|
||||||
|
xml.login do
|
||||||
|
generate_xml_from_hash(xml_params, xml)
|
||||||
|
end
|
||||||
|
xml.clTRID 'ABC-12345'
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def domain_create_xml(xml_params = {}, dnssec_params = {})
|
def domain_create_xml(xml_params = {}, dnssec_params = {})
|
||||||
|
|
||||||
defaults = {
|
defaults = {
|
||||||
|
@ -91,12 +125,12 @@ 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')
|
generate_xml_from_hash(xml_params, xml, 'domain:')
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
xml.extension do
|
xml.extension do
|
||||||
xml.tag!('secDNS:create', 'xmlns:secDNS' => 'urn:ietf:params:xml:ns:secDNS-1.1') do
|
xml.tag!('secDNS:create', 'xmlns:secDNS' => 'urn:ietf:params:xml:ns:secDNS-1.1') do
|
||||||
generate_xml_from_hash(dnssec_params, xml, 'secDNS')
|
generate_xml_from_hash(dnssec_params, xml, 'secDNS:')
|
||||||
end
|
end
|
||||||
end if dnssec_params != false
|
end if dnssec_params != false
|
||||||
xml.clTRID 'ABC-12345'
|
xml.clTRID 'ABC-12345'
|
||||||
|
@ -161,7 +195,7 @@ module Epp
|
||||||
xml.command do
|
xml.command do
|
||||||
xml.info do
|
xml.info do
|
||||||
xml.tag!('domain:info', 'xmlns:domain' => 'urn:ietf:params:xml:ns:domain-1.0') do
|
xml.tag!('domain:info', 'xmlns:domain' => 'urn:ietf:params:xml:ns:domain-1.0') do
|
||||||
generate_xml_from_hash(xml_params, xml, 'domain')
|
generate_xml_from_hash(xml_params, xml, 'domain:')
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
xml.clTRID 'ABC-12345'
|
xml.clTRID 'ABC-12345'
|
||||||
|
@ -184,13 +218,13 @@ module Epp
|
||||||
xml.command do
|
xml.command do
|
||||||
xml.update do
|
xml.update do
|
||||||
xml.tag!('domain:update', 'xmlns:domain' => 'urn:ietf:params:xml:ns:domain-1.0') do
|
xml.tag!('domain:update', 'xmlns:domain' => 'urn:ietf:params:xml:ns:domain-1.0') do
|
||||||
generate_xml_from_hash(xml_params, xml, 'domain')
|
generate_xml_from_hash(xml_params, xml, 'domain:')
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
xml.extension do
|
xml.extension do
|
||||||
xml.tag!('secDNS:create', 'xmlns:secDNS' => 'urn:ietf:params:xml:ns:secDNS-1.1') do
|
xml.tag!('secDNS:create', 'xmlns:secDNS' => 'urn:ietf:params:xml:ns:secDNS-1.1') do
|
||||||
generate_xml_from_hash(dnssec_params, xml, 'secDNS')
|
generate_xml_from_hash(dnssec_params, xml, 'secDNS:')
|
||||||
end
|
end
|
||||||
end if dnssec_params != false
|
end if dnssec_params != false
|
||||||
xml.clTRID 'ABC-12345'
|
xml.clTRID 'ABC-12345'
|
||||||
|
@ -198,14 +232,14 @@ module Epp
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def generate_xml_from_hash(xml_params, xml, ns)
|
def generate_xml_from_hash(xml_params, xml, ns = '')
|
||||||
xml_params.each do |k, v|
|
xml_params.each do |k, v|
|
||||||
# Value is a hash which has string type value
|
# Value is a hash which has string type value
|
||||||
if v.is_a?(Hash) && v[:value].is_a?(String)
|
if v.is_a?(Hash) && v[:value].is_a?(String)
|
||||||
xml.tag!("#{ns}:#{k}", v[:value], v[:attrs])
|
xml.tag!("#{ns}#{k}", v[:value], v[:attrs])
|
||||||
# Value is a hash which is nested
|
# Value is a hash which is nested
|
||||||
elsif v.is_a?(Hash)
|
elsif v.is_a?(Hash)
|
||||||
xml.tag!("#{ns}:#{k}") do
|
xml.tag!("#{ns}#{k}") do
|
||||||
generate_xml_from_hash(v, xml, ns)
|
generate_xml_from_hash(v, xml, ns)
|
||||||
end
|
end
|
||||||
# Value is an array
|
# Value is an array
|
||||||
|
@ -215,7 +249,7 @@ module Epp
|
||||||
generate_xml_from_hash(x, xml, ns)
|
generate_xml_from_hash(x, xml, ns)
|
||||||
end
|
end
|
||||||
else
|
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)
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue