From 5e6a6566e4ce0cc76edc085db6fb163249666ce9 Mon Sep 17 00:00:00 2001 From: Martin Lensment Date: Wed, 13 Aug 2014 11:28:22 +0300 Subject: [PATCH] Experimental XML template system for tests --- spec/support/epp.rb | 49 ++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 48 insertions(+), 1 deletion(-) diff --git a/spec/support/epp.rb b/spec/support/epp.rb index 7111d9ed1..dd00bace0 100644 --- a/spec/support/epp.rb +++ b/spec/support/epp.rb @@ -4,7 +4,7 @@ module Epp end # handles connection and login automatically - def epp_request filename + def epp_request(data) begin parse_response(server.request(read_body(filename))) rescue Exception => e @@ -40,6 +40,53 @@ module Epp obj end + ### REQUEST TEMPLATES ### + + # THIS FEATURE IS EXPERIMENTAL AND NOT IN USE ATM + + def domain_create_template(xml_params={}) + xml_params[:nameservers] = xml_params[:ns] || [{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'} + ] + + # {hostAttr: {hostName: 'ns1.example.net', hostAddr_value: '192.0.2.2', hostAddr_ip}} + + xml = Builder::XmlMarkup.new + + xml.instruct!(:xml, :standalone => 'no') + xml.epp('xmlns' => 'urn:ietf:params:xml:ns:epp-1.0') do + 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] || 'expample.ee')) + + xml.tag!('domain:period', (xml_params[:period_value] || 1), 'unit' => (xml_params[:period_unit] || 'y')) + + xml.tag!('domain:ns') do + xml_params[:nameservers].each do |x| + xml.tag!('domain:hostObj', x[:hostObj]) + end + end + + xml.tag!('domain:registrant', (xml_params[:registrant] || 'jd1234')) + + xml_params[:contacts].each do |x| + xml.tag!('domain:contact', x[:contact_value], 'type' => (x[:contact_type])) + end + + xml.tag!('domain:authInfo') do + xml.tag!('domain:pw', xml_params[:pw] || '2fooBAR') + end + end + end + xml.clTRID 'ABC-12345' + end + end + end end RSpec.configure do |c|