diff --git a/spec/epp/domain_spec.rb b/spec/epp/domain_spec.rb index 4d864d9d1..25b758f50 100644 --- a/spec/epp/domain_spec.rb +++ b/spec/epp/domain_spec.rb @@ -45,7 +45,7 @@ describe 'EPP Domain', epp: true do it 'transfers a domain' do pw = domain.auth_info - xml = domain_transfer_xml(pw: pw) + xml = domain_transfer_xml({ authInfo: { pw: { value: pw } } }) response = epp_request(xml, :xml, :elkdata) domain.reload @@ -66,7 +66,7 @@ describe 'EPP Domain', epp: true do domain.reload pw = domain.auth_info - xml = domain_transfer_xml(pw: pw) # request with new password + xml = domain_transfer_xml({ authInfo: { pw: { value: pw } } }) # request with new password response = epp_request(xml, :xml, :zone) trn_data = response[:parsed].css('trnData') @@ -110,7 +110,7 @@ describe 'EPP Domain', epp: true do transfer_from: zone }) - xml = domain_transfer_xml(pw: domain.auth_info, op: 'approve') + xml = domain_transfer_xml({ authInfo: { pw: { value: domain.auth_info } } }, 'approve') response = epp_request(xml, :xml, :elkdata) expect(response[:result_code]).to eq('2304') expect(response[:msg]).to eq('Transfer can be approved only by current domain registrar') @@ -124,7 +124,7 @@ describe 'EPP Domain', epp: true do transfer_from: zone }) - xml = domain_transfer_xml(pw: domain.auth_info, op: 'approve') + xml = domain_transfer_xml({ authInfo: { pw: { value: domain.auth_info } } }, 'approve') response = epp_request(xml, :xml, :zone) domain.reload dtl = domain.domain_transfers.last @@ -140,14 +140,15 @@ describe 'EPP Domain', epp: true do end it 'does not transfer with invalid pw' do - response = epp_request(domain_transfer_xml(pw: 'test'), :xml) + xml = domain_transfer_xml({ authInfo: { pw: { value: 'test' } } }) + response = epp_request(xml, :xml) expect(response[:result_code]).to eq('2201') expect(response[:msg]).to eq('Authorization error') end it 'ignores transfer when owner registrar requests transfer' do pw = domain.auth_info - xml = domain_transfer_xml(pw: pw) + xml = domain_transfer_xml({ authInfo: { pw: { value: pw } } }) response = epp_request(xml, :xml, :zone) expect(response[:result_code]).to eq('2002') @@ -155,7 +156,7 @@ describe 'EPP Domain', epp: true do end it 'returns an error for incorrect op attribute' do - response = epp_request(domain_transfer_xml(op: 'bla'), :xml, :zone) + response = epp_request(domain_transfer_xml({}, 'bla'), :xml, :zone) expect(response[:result_code]).to eq('2306') expect(response[:msg]).to eq('Attribute op is invalid') end diff --git a/spec/epp/epp_helper_spec.rb b/spec/epp/epp_helper_spec.rb index 1283c164e..0a0ccc80e 100644 --- a/spec/epp/epp_helper_spec.rb +++ b/spec/epp/epp_helper_spec.rb @@ -2,47 +2,6 @@ require 'rails_helper' describe 'EPP Helper', epp: true do context 'in context of Domain' do - it 'generates valid renew xml' do - expected = Nokogiri::XML(' - - - - - example.ee - 2014-08-07 - 1 - - - ABC-12345 - - - ').to_s.squish - - generated = Nokogiri::XML(domain_renew_xml).to_s.squish - expect(generated).to eq(expected) - - expected = Nokogiri::XML(' - - - - - one.ee - 2009-11-15 - 365 - - - ABC-12345 - - - ').to_s.squish - - generated = Nokogiri::XML(domain_renew_xml(name: 'one.ee', curExpDate: '2009-11-15', - period_value: '365', period_unit: 'd')).to_s.squish - expect(generated).to eq(expected) - end - it 'generates valid transfer xml' do expected = Nokogiri::XML(' @@ -81,7 +40,12 @@ describe 'EPP Helper', epp: true do ').to_s.squish - xml = domain_transfer_xml(name: 'one.ee', op: 'approve', pw: 'test', roid: 'askdf') + xml = domain_transfer_xml({ + name: { value: 'one.ee' }, + authInfo: { + pw: { value: 'test', attrs: { roid: 'askdf' } } + } + }, 'approve') generated = Nokogiri::XML(xml).to_s.squish expect(generated).to eq(expected) diff --git a/spec/support/epp.rb b/spec/support/epp.rb index 1f456775d..8708db24e 100644 --- a/spec/support/epp.rb +++ b/spec/support/epp.rb @@ -52,80 +52,16 @@ module Epp ### REQUEST TEMPLATES ### - def domain_renew_xml(xml_params = {}) - xml = Builder::XmlMarkup.new + def domain_transfer_xml(xml_params = {}, op = 'query') + defaults = { + name: { value: 'example.ee' }, + authInfo: { + pw: { value: '98oiewslkfkd', attrs: { roid: 'JD1234-REP' } } + } + } - xml.instruct!(:xml, standalone: 'no') - xml.epp('xmlns' => 'urn:ietf:params:xml:ns:epp-1.0') do - xml.command do - xml.renew do - xml.tag!('domain:renew', '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 - xml.tag!('domain:curExpDate', (xml_params[:curExpDate] || '2014-08-07')) if xml_params[:curExpDate] != false - - if xml_params[:period] != false - xml.tag!('domain:period', (xml_params[:period_value] || 1), 'unit' => (xml_params[:period_unit] || 'y')) - end - end - end - xml.clTRID 'ABC-12345' - end - end - end - - 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]) - # Value is a hash which is nested - elsif v.is_a?(Hash) - xml.tag!("#{ns}#{k}") do - generate_xml_from_hash(v, xml, ns) - end - # Value is an 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 - v.each do |x| - generate_xml_from_hash(x, xml, ns) - end - end - end - end - end - end - - - def domain_transfer_xml(xml_params = {}) - xml_params[:name] = xml_params[:name] || 'example.ee' - xml_params[:pw] = xml_params[:pw] || '98oiewslkfkd' - xml_params[:op] = xml_params[:op] || 'query' - xml_params[:roid] = xml_params[:roid] || 'JD1234-REP' - - 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.transfer('op' => xml_params[:op]) do - xml.tag!('domain:transfer', 'xmlns:domain' => 'urn:ietf:params:xml:ns:domain-1.0') do - if xml_params[:name] != false - xml.tag!('domain:name', xml_params[:name]) - end - - xml.tag!('domain:authInfo') do - xml.tag!('domain:pw', xml_params[:pw], 'roid' => xml_params[:roid]) - end if xml_params[:authInfo] != false - end - end - xml.clTRID 'ABC-12345' - end - end + xml_params = defaults.deep_merge(xml_params) + EppXml::Domain.transfer(xml_params, op) end end