diff --git a/spec/epp/domain_spec.rb b/spec/epp/domain_spec.rb index 3cc254ccd..5920cf4d3 100644 --- a/spec/epp/domain_spec.rb +++ b/spec/epp/domain_spec.rb @@ -952,8 +952,6 @@ describe 'EPP Domain', epp: true do ] }) - puts Nokogiri::XML(xml).to_s - epp_request(xml, :xml) expect(d.dnskeys.count).to eq(1) diff --git a/spec/epp/epp_helper_spec.rb b/spec/epp/epp_helper_spec.rb index 40a721c32..3d8ec60c2 100644 --- a/spec/epp/epp_helper_spec.rb +++ b/spec/epp/epp_helper_spec.rb @@ -2,6 +2,31 @@ require 'rails_helper' describe 'EPP Helper', epp: true do context 'in context of Domain' do + it 'generates valid login xml' do + expected = Nokogiri::XML(' + + + + gitlab + ghyt9e4fu + + 1.0 + en + + + urn:ietf:params:xml:ns:contact-1.0 + + + ABC-12345 + + + ').to_s.squish + + generated = Nokogiri::XML(login_xml).to_s.squish + expect(generated).to eq(expected) + end + it 'generates valid create xml' do expected = Nokogiri::XML(' diff --git a/spec/support/epp.rb b/spec/support/epp.rb index 7b88ce1c8..9f9295b12 100644 --- a/spec/support/epp.rb +++ b/spec/support/epp.rb @@ -52,6 +52,40 @@ module Epp ### 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 = {}) defaults = { @@ -91,12 +125,12 @@ module Epp xml.command do xml.create 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 xml.extension 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 if dnssec_params != false xml.clTRID 'ABC-12345' @@ -161,7 +195,7 @@ module Epp xml.command do xml.info 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 xml.clTRID 'ABC-12345' @@ -184,13 +218,13 @@ module Epp xml.command do xml.update 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 xml.extension 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 if dnssec_params != false xml.clTRID 'ABC-12345' @@ -198,14 +232,14 @@ module Epp 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| # Value is a hash which has string type value 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 elsif v.is_a?(Hash) - xml.tag!("#{ns}:#{k}") do + xml.tag!("#{ns}#{k}") do generate_xml_from_hash(v, xml, ns) end # Value is an array @@ -215,7 +249,7 @@ module Epp generate_xml_from_hash(x, xml, ns) end else - xml.tag!("#{ns}:#{k}") do + xml.tag!("#{ns}#{k}") do v.each do |x| generate_xml_from_hash(x, xml, ns) end