mirror of
https://github.com/internetee/registry.git
synced 2025-07-02 01:03:35 +02:00
Contact Epp tests refactored to use EppXml gem
This commit is contained in:
parent
afcec06fe3
commit
b046927c95
6 changed files with 171 additions and 195 deletions
|
@ -10,7 +10,7 @@ module Epp::ContactsHelper
|
|||
# FIXME: Update returns 2303 update multiple times
|
||||
code = params_hash['epp']['command']['update']['update'][:id]
|
||||
@contact = Contact.where(code: code).first
|
||||
if owner? && stamp(@contact) && @contact.update_attributes(contact_and_address_attributes(:update))
|
||||
if update_rights? && stamp(@contact) && @contact.update_attributes(contact_and_address_attributes(:update))
|
||||
render 'epp/contacts/update'
|
||||
else
|
||||
contact_exists?(code)
|
||||
|
@ -21,7 +21,7 @@ module Epp::ContactsHelper
|
|||
# rubocop:disable Metrics/CyclomaticComplexity
|
||||
def delete_contact
|
||||
@contact = find_contact
|
||||
handle_errors(@contact) and return unless owner?
|
||||
handle_errors(@contact) and return unless rights? #owner?
|
||||
handle_errors(@contact) and return unless @contact
|
||||
handle_errors(@contact) and return unless @contact.destroy_and_clean
|
||||
|
||||
|
@ -53,19 +53,23 @@ module Epp::ContactsHelper
|
|||
## CREATE
|
||||
def validate_contact_create_request
|
||||
@ph = params_hash['epp']['command']['create']['create']
|
||||
xml_attrs_present?(@ph, [%w(postalInfo)])
|
||||
return false unless validate_params
|
||||
#xml_attrs_present?(@ph, [%w(postalInfo)])
|
||||
xml_attrs_present?(@ph, [%w(postalInfo name), %w(postalInfo addr city), %w(postalInfo addr cc),
|
||||
%w(ident), %w(voice), %w(email)])
|
||||
|
||||
return epp_errors.empty? unless @ph['postalInfo'].is_a?(Hash) || @ph['postalInfo'].is_a?(Array)
|
||||
|
||||
return epp_errors.empty? #unless @ph['postalInfo'].is_a?(Hash) || @ph['postalInfo'].is_a?(Array)
|
||||
|
||||
# (epp_errors << Address.validate_postal_info_types(parsed_frame)).flatten!
|
||||
xml_attrs_array_present?(@ph['postalInfo'], [%w(name), %w(addr city), %w(addr cc)])
|
||||
#xml_attrs_array_present?(@ph['postalInfo'], [%w(name), %w(addr city), %w(addr cc)])
|
||||
end
|
||||
|
||||
## UPDATE
|
||||
def validate_contact_update_request
|
||||
@ph = params_hash['epp']['command']['update']['update']
|
||||
update_attrs_present?
|
||||
xml_attrs_present?(@ph, [['id']])
|
||||
xml_attrs_present?(@ph, [['id'], %w(authInfo pw)])
|
||||
end
|
||||
|
||||
def contact_exists?(code)
|
||||
|
@ -127,15 +131,23 @@ module Epp::ContactsHelper
|
|||
pw = @ph.try(:[], :authInfo).try(:[], :pw)
|
||||
|
||||
return true if current_epp_user.try(:registrar) == @contact.try(:registrar)
|
||||
return true if @contact.auth_info_matches(pw)
|
||||
return true if pw && @contact.auth_info_matches(pw) # @contact.try(:auth_info_matches, pw)
|
||||
|
||||
epp_errors << { code: '2201', msg: t('errors.messages.epp_authorization_error'), value: { obj: 'pw', val: pw } }
|
||||
false
|
||||
end
|
||||
|
||||
def update_rights?
|
||||
pw = @ph.try(:[], :authInfo).try(:[], :pw)
|
||||
return true if pw && @contact.auth_info_matches(pw)
|
||||
epp_errors << { code: '2201', msg: t('errors.messages.epp_authorization_error'), value: { obj: 'pw', val: pw } }
|
||||
false
|
||||
end
|
||||
|
||||
def contact_and_address_attributes(type = :create)
|
||||
case type
|
||||
when :update
|
||||
# TODO: support for rem/add
|
||||
contact_hash = merge_attribute_hash(@ph[:chg], type)
|
||||
else
|
||||
contact_hash = merge_attribute_hash(@ph, type)
|
||||
|
@ -163,4 +175,10 @@ module Epp::ContactsHelper
|
|||
Contact::IDENT_TYPES.any? { |type| return type if result.include?(type) }
|
||||
nil
|
||||
end
|
||||
|
||||
def validate_params
|
||||
return true if @ph
|
||||
epp_errors << { code: '2001', msg: t(:'errors.messages.epp_command_syntax_error') }
|
||||
false
|
||||
end
|
||||
end
|
||||
|
|
|
@ -237,6 +237,7 @@ en:
|
|||
epp_domain_not_found: 'Domain not found'
|
||||
epp_exp_dates_do_not_match: 'Given and current expire dates do not match'
|
||||
epp_registrant_not_found: 'Registrant not found'
|
||||
epp_command_syntax_error: 'Command syntax error'
|
||||
required_parameter_missing: 'Required parameter missing: %{key}'
|
||||
attr_missing: 'Required parameter missing: %{key}'
|
||||
repeating_postal_info: 'Only one of each postal info types may be provided'
|
||||
|
|
|
@ -2,13 +2,13 @@ require 'rails_helper'
|
|||
|
||||
describe 'EPP Contact', epp: true do
|
||||
before do
|
||||
# we don't really care about the code validations here, it's done in models
|
||||
# dynamic Contact.code just makes it harder to test EPP
|
||||
Contact.skip_callback(:create, :before, :generate_code)
|
||||
Contact.skip_callback(:create, :before, :generate_auth_info)
|
||||
end
|
||||
|
||||
after do
|
||||
Contact.set_callback(:create, :before, :generate_code)
|
||||
Contact.set_callback(:create, :before, :generate_auth_info)
|
||||
end
|
||||
|
||||
let(:server_zone) { Epp::Server.new({ server: 'localhost', tag: 'zone', password: 'ghyt9e4fu', port: 701 }) }
|
||||
|
@ -26,38 +26,55 @@ describe 'EPP Contact', epp: true do
|
|||
|
||||
context 'create command' do
|
||||
|
||||
it 'fails if request is invalid' do
|
||||
response = epp_request(contact_create_xml({ addr: { cc: false, city: false } }), :xml)
|
||||
it 'fails if request xml is missing' do
|
||||
xml = EppXml::Contact.create
|
||||
response = epp_request(xml, :xml)
|
||||
expect(response[:results][0][:result_code]).to eq('2001')
|
||||
|
||||
expect(response[:results][0][:msg]).to eq('Command syntax error')
|
||||
expect(response[:results].count).to eq 1
|
||||
end
|
||||
|
||||
it 'fails if request xml is missing' do
|
||||
xml = EppXml::Contact.create(
|
||||
postalInfo: { addr: { value: nil } }
|
||||
)
|
||||
response = epp_request(xml, :xml)
|
||||
expect(response[:results][0][:result_code]).to eq('2003')
|
||||
expect(response[:results][1][:result_code]).to eq('2003')
|
||||
expect(response[:results][2][:result_code]).to eq('2003')
|
||||
expect(response[:results][3][:result_code]).to eq('2003')
|
||||
expect(response[:results][4][:result_code]).to eq('2003')
|
||||
expect(response[:results][5][:result_code]).to eq('2003')
|
||||
|
||||
expect(response[:results][0][:msg]).to eq('Required parameter missing: city')
|
||||
expect(response[:results][1][:msg]).to eq('Required parameter missing: cc')
|
||||
expect(response[:results].count).to eq 2
|
||||
expect(response[:results][0][:msg]).to eq('Required parameter missing: name')
|
||||
expect(response[:results][1][:msg]).to eq('Required parameter missing: city')
|
||||
expect(response[:results][2][:msg]).to eq('Required parameter missing: cc')
|
||||
expect(response[:results][3][:msg]).to eq('Required parameter missing: ident')
|
||||
expect(response[:results][4][:msg]).to eq('Required parameter missing: voice')
|
||||
expect(response[:results][5][:msg]).to eq('Required parameter missing: email')
|
||||
expect(response[:results].count).to eq 6
|
||||
end
|
||||
|
||||
it 'successfully creates a contact' do
|
||||
response = epp_request(contact_create_xml, :xml)
|
||||
response = epp_request(create_contact_xml, :xml)
|
||||
|
||||
expect(response[:result_code]).to eq('1000')
|
||||
expect(response[:msg]).to eq('Command completed successfully')
|
||||
# expect(response[:clTRID]).to eq('ABC-12345')
|
||||
expect(Contact.first.created_by_id).to eq 2
|
||||
|
||||
expect(Contact.first.registrar).to eq(zone)
|
||||
expect(zone.epp_users).to include(Contact.first.created_by)
|
||||
expect(Contact.first.updated_by_id).to eq nil
|
||||
|
||||
expect(Contact.count).to eq(1)
|
||||
|
||||
expect(Contact.first.org_name).to eq('Example Inc.')
|
||||
expect(Contact.first.ident).to eq '37605030299'
|
||||
expect(Contact.first.ident_type).to eq 'op'
|
||||
|
||||
expect(Contact.first.address.street).to eq('123 Example Dr.')
|
||||
# expect(Contact.first.address.street2).to eq('Suite 100')
|
||||
# expect(Contact.first.address.street3).to eq nil
|
||||
expect(Contact.first.address.street).to eq('123 Example')
|
||||
end
|
||||
|
||||
it 'successfully adds registrar' do
|
||||
response = epp_request(contact_create_xml, :xml)
|
||||
response = epp_request(create_contact_xml, :xml)
|
||||
|
||||
expect(response[:result_code]).to eq('1000')
|
||||
expect(response[:msg]).to eq('Command completed successfully')
|
||||
|
@ -67,17 +84,8 @@ describe 'EPP Contact', epp: true do
|
|||
expect(Contact.first.registrar).to eq(zone)
|
||||
end
|
||||
|
||||
it 'successfully creates contact with 2 addresses' do
|
||||
response = epp_request('contacts/create_with_two_addresses.xml')
|
||||
|
||||
expect(response[:result_code]).to eq('1000')
|
||||
|
||||
expect(Contact.count).to eq(1)
|
||||
expect(Address.count).to eq(1)
|
||||
end
|
||||
|
||||
it 'returns result data upon success' do
|
||||
response = epp_request(contact_create_xml, :xml)
|
||||
response = epp_request(create_contact_xml, :xml)
|
||||
|
||||
expect(response[:result_code]).to eq('1000')
|
||||
expect(response[:msg]).to eq('Command completed successfully')
|
||||
|
@ -93,19 +101,22 @@ describe 'EPP Contact', epp: true do
|
|||
|
||||
context 'update command' do
|
||||
it 'fails if request is invalid' do
|
||||
response = epp_request('contacts/update_missing_attr.xml')
|
||||
xml = EppXml::Contact.update
|
||||
response = epp_request(xml, :xml) #epp_request('contacts/update_missing_attr.xml')
|
||||
|
||||
expect(response[:results][0][:result_code]).to eq('2003')
|
||||
expect(response[:results][0][:msg]).to eq('Required parameter missing: add, rem or chg')
|
||||
expect(response[:results][1][:result_code]).to eq('2003')
|
||||
expect(response[:results][1][:msg]).to eq('Required parameter missing: id')
|
||||
expect(response[:results].count).to eq 2
|
||||
expect(response[:results][2][:result_code]).to eq('2003')
|
||||
expect(response[:results][2][:msg]).to eq('Required parameter missing: pw')
|
||||
expect(response[:results].count).to eq 3
|
||||
end
|
||||
|
||||
it 'fails with wrong authentication info' do
|
||||
Fabricate(:contact, code: 'sh8013', auth_info: 'secure_password')
|
||||
Fabricate(:contact, code: 'sh8013', auth_info: 'password_wrong')
|
||||
|
||||
response = epp_request('contacts/update.xml')
|
||||
response = epp_request(update_contact_xml({id: { value: 'sh8013'}}), :xml, :elkdata ) #('contacts/update.xml')
|
||||
|
||||
expect(response[:msg]).to eq('Authorization error')
|
||||
expect(response[:result_code]).to eq('2201')
|
||||
|
@ -118,15 +129,13 @@ describe 'EPP Contact', epp: true do
|
|||
registrar: zone,
|
||||
email: 'not_updated@test.test',
|
||||
code: 'sh8013',
|
||||
auth_info: '2fooBAR'
|
||||
auth_info: 'password'
|
||||
)
|
||||
response = epp_request('contacts/update.xml')
|
||||
response = epp_request(update_contact_xml({id: { value: 'sh8013' }}), :xml)
|
||||
|
||||
expect(response[:msg]).to eq('Command completed successfully')
|
||||
expect(Contact.first.name).to eq('John Doe')
|
||||
expect(Contact.first.email).to eq('jdoe@example.com')
|
||||
expect(Contact.first.ident).to eq('J836954')
|
||||
expect(Contact.first.ident_type).to eq('passport')
|
||||
expect(Contact.first.name).to eq('John Doe Edited')
|
||||
expect(Contact.first.email).to eq('edited@example.example')
|
||||
end
|
||||
|
||||
it 'returns phone and email error' do
|
||||
|
@ -136,10 +145,18 @@ describe 'EPP Contact', epp: true do
|
|||
created_by_id: 1,
|
||||
email: 'not_updated@test.test',
|
||||
code: 'sh8013',
|
||||
auth_info: '2fooBAR'
|
||||
auth_info: 'password'
|
||||
)
|
||||
|
||||
response = epp_request('contacts/update_with_errors.xml')
|
||||
xml = {
|
||||
id: { value: 'sh8013' },
|
||||
chg: {
|
||||
voice: { value: '123213' },
|
||||
email: { value: 'aaa' }
|
||||
}
|
||||
}
|
||||
|
||||
response = epp_request(update_contact_xml(xml), :xml)
|
||||
|
||||
expect(response[:results][0][:result_code]).to eq('2005')
|
||||
expect(response[:results][0][:msg]).to eq('Phone nr is invalid')
|
||||
|
@ -162,7 +179,8 @@ describe 'EPP Contact', epp: true do
|
|||
|
||||
context 'delete command' do
|
||||
it 'fails if request is invalid' do
|
||||
response = epp_request('contacts/delete_missing_attr.xml')
|
||||
xml = EppXml::Contact.delete({ uid: { value: '23123' } })
|
||||
response = epp_request(xml, :xml)
|
||||
|
||||
expect(response[:results][0][:result_code]).to eq('2003')
|
||||
expect(response[:results][0][:msg]).to eq('Required parameter missing: id')
|
||||
|
@ -171,7 +189,7 @@ describe 'EPP Contact', epp: true do
|
|||
|
||||
it 'deletes contact' do
|
||||
Fabricate(:contact, code: 'dwa1234', created_by_id: EppUser.first.id, registrar: zone)
|
||||
response = epp_request('contacts/delete.xml')
|
||||
response = epp_request(delete_contact_xml({ id: { value: 'dwa1234' } }), :xml)
|
||||
expect(response[:result_code]).to eq('1000')
|
||||
expect(response[:msg]).to eq('Command completed successfully')
|
||||
expect(response[:clTRID]).to eq('ABC-12345')
|
||||
|
@ -180,7 +198,7 @@ describe 'EPP Contact', epp: true do
|
|||
end
|
||||
|
||||
it 'returns error if obj doesnt exist' do
|
||||
response = epp_request('contacts/delete.xml')
|
||||
response = epp_request(delete_contact_xml, :xml)
|
||||
expect(response[:result_code]).to eq('2303')
|
||||
expect(response[:msg]).to eq('Object does not exist')
|
||||
end
|
||||
|
@ -196,7 +214,7 @@ describe 'EPP Contact', epp: true do
|
|||
registrar: zone)
|
||||
)
|
||||
expect(Domain.first.owner_contact.address.present?).to be true
|
||||
response = epp_request('contacts/delete.xml')
|
||||
response = epp_request(delete_contact_xml({ id: { value: 'dwa1234' } }), :xml)
|
||||
|
||||
expect(response[:result_code]).to eq('2305')
|
||||
expect(response[:msg]).to eq('Object association prohibits operation')
|
||||
|
@ -208,7 +226,8 @@ describe 'EPP Contact', epp: true do
|
|||
|
||||
context 'check command' do
|
||||
it 'fails if request is invalid' do
|
||||
response = epp_request(contact_check_xml(ids: [false]), :xml)
|
||||
xml = EppXml::Contact.check( { uid: { value: '123asde' } } )
|
||||
response = epp_request(xml, :xml)
|
||||
|
||||
expect(response[:results][0][:result_code]).to eq('2003')
|
||||
expect(response[:results][0][:msg]).to eq('Required parameter missing: id')
|
||||
|
@ -218,7 +237,7 @@ describe 'EPP Contact', epp: true do
|
|||
it 'returns info about contact availability' do
|
||||
Fabricate(:contact, code: 'check-1234')
|
||||
|
||||
response = epp_request(contact_check_xml(ids: [{ id: 'check-1234' }, { id: 'check-4321' }]), :xml)
|
||||
response = epp_request(check_multiple_contacts_xml, :xml)
|
||||
|
||||
expect(response[:result_code]).to eq('1000')
|
||||
expect(response[:msg]).to eq('Command completed successfully')
|
||||
|
@ -234,7 +253,7 @@ describe 'EPP Contact', epp: true do
|
|||
|
||||
context 'info command' do
|
||||
it 'fails if request invalid' do
|
||||
response = epp_request('contacts/delete_missing_attr.xml')
|
||||
response = epp_request(EppXml::Contact.info({ uid: { value: '123123' }}), :xml )
|
||||
|
||||
expect(response[:results][0][:result_code]).to eq('2003')
|
||||
expect(response[:results][0][:msg]).to eq('Required parameter missing: id')
|
||||
|
@ -242,7 +261,7 @@ describe 'EPP Contact', epp: true do
|
|||
end
|
||||
|
||||
it 'returns error when object does not exist' do
|
||||
response = epp_request('contacts/info.xml')
|
||||
response = epp_request(info_contact_xml({ id: { value: 'info-4444' } }), :xml)
|
||||
expect(response[:result_code]).to eq('2303')
|
||||
expect(response[:msg]).to eq('Object does not exist')
|
||||
expect(response[:results][0][:value]).to eq('info-4444')
|
||||
|
@ -266,7 +285,7 @@ describe 'EPP Contact', epp: true do
|
|||
pending 'Disclosure needs to have some of the details worked out'
|
||||
Fabricate(:contact, code: 'info-4444', auth_info: '2fooBAR',
|
||||
disclosure: Fabricate(:contact_disclosure, email: false, phone: false))
|
||||
response = epp_request('contacts/info.xml')
|
||||
response = epp_request(info_contact_xml( id: { value: 'info-4444' } ), :xml)
|
||||
contact = response[:parsed].css('resData chkData')
|
||||
|
||||
expect(response[:result_code]).to eq('1000')
|
||||
|
|
|
@ -11,7 +11,7 @@ describe '.extract_attributes' do
|
|||
end
|
||||
|
||||
it 'should return empty hash if no disclosure' do
|
||||
parsed_frame = Nokogiri::XML(contact_create_xml).remove_namespaces!
|
||||
parsed_frame = Nokogiri::XML(create_contact_xml).remove_namespaces!
|
||||
result = ContactDisclosure.extract_attributes(parsed_frame)
|
||||
expect(result).to eq({})
|
||||
end
|
||||
|
|
|
@ -1,140 +0,0 @@
|
|||
module EppContactXmlBuilder
|
||||
def contact_check_xml(xml_params = {})
|
||||
xml_params[:ids] = xml_params[:ids] || [{ id: 'check-1234' }, { id: 'check-4321' }]
|
||||
|
||||
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.check do
|
||||
xml.tag!('contact:check', 'xmlns:contact' => 'urn:ietf:params:xml:ns:contact-1.0') do
|
||||
unless xml_params[:ids] == [false]
|
||||
xml_params[:ids].each do |x|
|
||||
xml.tag!('contact:id', x[:id])
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
xml.clTRID 'ABC-12345'
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def contact_create_xml(xml_params = {})
|
||||
# xml_params[:ids] = xml_params[:ids] || [ { id: 'check-1234' }, { id: 'check-4321' } ]
|
||||
xml = Builder::XmlMarkup.new
|
||||
|
||||
xml_params[:addr] = xml_params[:addr] || { street: '123 Example Dr.', street2: 'Suite 100', street3: nil,
|
||||
city: 'Megaton', sp: 'F3 ', pc: '201-33', cc: 'EE' }
|
||||
xml_params[:authInfo] = xml_params[:authInfo] || { pw: 'Aas34fq' }
|
||||
|
||||
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!('contact:create', 'xmlns:contact' => 'urn:ietf:params:xml:ns:contact-1.0') do
|
||||
xml.tag!('contact:id', xml_params[:id], 'sh8013') unless xml_params[:id] == false
|
||||
unless xml_params[:postalInfo] == [false]
|
||||
xml.tag!('contact:postalInfo', type: 'int') do
|
||||
xml.tag!('contact:name', ( xml_params[:name] || 'Sillius Soddus')) unless xml_params[:name] == false
|
||||
xml.tag!('contact:org', ( xml_params[:org_name] || 'Example Inc.')) unless xml_params[:org_name] == false
|
||||
unless xml_params[:addr] == [false]
|
||||
xml.tag!('contact:addr') do
|
||||
xml.tag!('contact:street', xml_params[:addr][:street]) unless xml_params[:addr][:street] == false
|
||||
#xml.tag!('contact:street', xml_params[:addr][:street2]) unless xml_params[:addr][:street2] == false
|
||||
#xml.tag!('contact:street', xml_params[:addr][:street3]) unless xml_params[:addr][:street3] == false
|
||||
xml.tag!('contact:city', xml_params[:addr][:city]) unless xml_params[:addr][:city] == false
|
||||
xml.tag!('contact:sp', xml_params[:addr][:sp]) unless xml_params[:addr][:sp] == false
|
||||
xml.tag!('contact:pc', xml_params[:addr][:pc]) unless xml_params[:addr][:pc] == false
|
||||
xml.tag!('contact:cc', xml_params[:addr][:cc]) unless xml_params[:addr][:cc] == false
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
xml.tag!('contact:voice', (xml_params[:voice] || '+372.1234567')) unless xml_params[:voice] == false
|
||||
xml.tag!('contact:fax', (xml_params[:fax] || '123123')) unless xml_params[:fax] == false
|
||||
xml.tag!('contact:email', (xml_params[:email] || 'example@test.example')) unless xml_params[:email] == false
|
||||
xml.tag!('contact:ident', (xml_params[:ident] || '37605030299'), type: 'op') unless xml_params[:ident] == false
|
||||
unless xml_params[:authInfo] == [false]
|
||||
xml.tag!('contact:authInfo') do
|
||||
xml.tag!('contact:pw', xml_params[:authInfo][:pw]) unless xml_params[:authInfo][:pw] == false
|
||||
end
|
||||
end
|
||||
# Disclosure logic
|
||||
end
|
||||
end
|
||||
xml.clTRID 'ABC-12345'
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# CONTACT UPDATE NEEDS WORK USE ON YOUR OWN RISK
|
||||
def contact_update_xml(xml_params = {})
|
||||
xml = Builder::XmlMarkup.new
|
||||
|
||||
# postalInfo = xml_params.try(:chg).try(:postalInfo)
|
||||
# addr = postalInfo.try(:addr)
|
||||
postalInfo = xml_params[:chg][:postalInfo] rescue nil
|
||||
addr = postalInfo[:addr] rescue nil
|
||||
|
||||
unless addr
|
||||
addr = { street: 'Downtown', city: 'Stockholm', cc: 'SE' }
|
||||
end
|
||||
|
||||
unless postalInfo
|
||||
postalInfo = { name: 'Jane Doe', org: 'Fake Inc.', voice: '+321.12345', fax: '12312312', addr: addr }
|
||||
end
|
||||
|
||||
xml_params[:chg] = xml_params[:chg] || { postalInfo: postalInfo }
|
||||
|
||||
xml_params[:chg][:postalInfo] = postalInfo
|
||||
xml_params[:chg][:postalInfo][:addr] = addr
|
||||
|
||||
xml_params[:chg][:authInfo] = xml_params[:chg][:authInfo] || { pw: 'ccds4324pok' }
|
||||
|
||||
xml.instruct!(:xml, standalone: 'no')
|
||||
xml.epp('xmlns' => 'urn:ietf:params:xml:ns:epp-1.0') do
|
||||
xml.command do
|
||||
xml.update do
|
||||
xml.tag!('contact:update', 'xmlns:contact' => 'urn:ietf:params:xml:ns:contact-1.0') do
|
||||
xml.tag!('contact:id', (xml_params[:id] || 'sh8013')) unless xml_params[:id] == false
|
||||
unless xml_params[:chg] == [false]
|
||||
xml.tag!('contact:chg') do
|
||||
xml.tag!('contact:voice', xml_params[:chg][:phone] || '+123.321123') unless xml_params[:chg][:phone] == false
|
||||
xml.tag!('contact:email', xml_params[:chg][:email] || 'jane@doe.com') unless xml_params[:chg][:email] == false
|
||||
unless xml_params[:chg][:postalInfo] == false
|
||||
xml.tag!('contact:postalInfo') do
|
||||
xml.tag!('contact:name', xml_params[:chg][:postalInfo][:name]) unless xml_params[:chg][:postalInfo][:name] == false
|
||||
xml.tag!('contact:org', xml_params[:chg][:postalInfo][:org]) unless xml_params[:chg][:postalInfo][:org] == false
|
||||
unless xml_params[:chg][:postalInfo][:addr] == false
|
||||
xml.tag!('contact:addr') do
|
||||
xml.tag!('contact:street', xml_params[:chg][:postalInfo][:addr][:street]) unless xml_params[:chg][:postalInfo][:addr][:street] == false
|
||||
#xml.tag!('contact:street', xml_params[:chg][:postalInfo][:addr][:street2]) unless xml_params[:chg][:postalInfo][:addr][:street2] == false
|
||||
#xml.tag!('contact:street', xml_params[:chg][:postalInfo][:addr][:street3]) unless xml_params[:chg][:postalInfo][:addr][:street3] == false
|
||||
xml.tag!('contact:city', xml_params[:chg][:postalInfo][:addr][:city]) unless xml_params[:chg][:postalInfo][:addr][:city] == false
|
||||
xml.tag!('contact:sp', xml_params[:chg][:postalInfo][:addr][:sp]) unless xml_params[:chg][:postalInfo][:addr][:sp] == false
|
||||
xml.tag!('contact:pc', xml_params[:chg][:postalInfo][:addr][:pc]) unless xml_params[:chg][:postalInfo][:addr][:pc] == false
|
||||
xml.tag!('contact:cc', xml_params[:chg][:postalInfo][:addr][:cc]) unless xml_params[:chg][:postalInfo][:addr][:cc] == false
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
unless xml_params[:chg][:authInfo] == [false]
|
||||
xml.tag!('contact:authInfo') do
|
||||
xml.tag!('contact:pw', xml_params[:chg][:authInfo][:pw]) unless xml_params[:chg][:authInfo][:pw] == false
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
xml.clTRID 'ABC-12345'
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
RSpec.configure do |c|
|
||||
c.include EppContactXmlBuilder
|
||||
end
|
78
spec/support/epp_contact_xml_helper.rb
Normal file
78
spec/support/epp_contact_xml_helper.rb
Normal file
|
@ -0,0 +1,78 @@
|
|||
module EppContactXmlHelper
|
||||
def create_contact_xml(xml_params={})
|
||||
defaults = {
|
||||
postalInfo: {
|
||||
name: { value: 'John Doe' },
|
||||
addr: {
|
||||
street: { value: '123 Example' },
|
||||
city: { value: 'Tallinn' },
|
||||
cc: { value: 'EE' }
|
||||
}
|
||||
},
|
||||
voice: { value: '+372.1234567' },
|
||||
email: { value: 'test@example.example' },
|
||||
ident: { value: '37605030299' }
|
||||
}
|
||||
|
||||
xml_params = defaults.deep_merge(xml_params)
|
||||
EppXml::Contact.create(xml_params)
|
||||
end
|
||||
|
||||
def update_contact_xml(xml_params={})
|
||||
defaults = {
|
||||
id: { value: 'asd123123er' },
|
||||
authInfo: { pw: { value: 'password' } },
|
||||
chg: {
|
||||
postalInfo: {
|
||||
name: { value: 'John Doe Edited' }
|
||||
},
|
||||
voice: { value: '+372.7654321' },
|
||||
email: { value: 'edited@example.example' }
|
||||
}
|
||||
}
|
||||
xml_params = defaults.deep_merge(xml_params)
|
||||
EppXml::Contact.update(xml_params)
|
||||
end
|
||||
|
||||
def delete_contact_xml(xml_params={})
|
||||
defaults = { id: { value: 'sh8012' } }
|
||||
xml_params = defaults.deep_merge(xml_params)
|
||||
EppXml::Contact.delete(xml_params)
|
||||
end
|
||||
|
||||
def info_contact_xml(xml_params={})
|
||||
defaults = { id: { value: 'sh8012' }, authInfo: { pw: { value: 'password' } } }
|
||||
xml_params = defaults.deep_merge(xml_params)
|
||||
EppXml::Contact.info(xml_params)
|
||||
end
|
||||
|
||||
def check_contact_xml(xml_params={})
|
||||
defaults = {
|
||||
id: { value: 'ad123c3' }
|
||||
}
|
||||
xml_params = defaults.deep_merge(xml_params)
|
||||
EppXml::Contact.check(xml_params)
|
||||
end
|
||||
|
||||
def check_multiple_contacts_xml
|
||||
'<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<epp xmlns="urn:ietf:params:xml:ns:epp-1.0">
|
||||
<command>
|
||||
<check>
|
||||
<contact:check
|
||||
xmlns:contact="urn:ietf:params:xml:ns:contact-1.0">
|
||||
<contact:id>check-1234</contact:id>
|
||||
<contact:id>check-4321</contact:id>
|
||||
</contact:check>
|
||||
</check>
|
||||
<clTRID>ABC-12345</clTRID>
|
||||
</command>
|
||||
</epp>'
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
|
||||
RSpec.configure do |c|
|
||||
c.include EppContactXmlHelper
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue