mirror of
https://github.com/internetee/registry.git
synced 2025-07-03 17:53:35 +02:00
Refactored contact with ability
This commit is contained in:
parent
62f8061e10
commit
96d1c60dd8
33 changed files with 763 additions and 1045 deletions
|
@ -1,451 +1,411 @@
|
|||
# require 'rails_helper'
|
||||
|
||||
# describe 'EPP Contact', epp: true do
|
||||
# before :all do
|
||||
# create_settings
|
||||
# create_disclosure_settings
|
||||
# @registrar1 = Fabricate(:registrar1)
|
||||
# @registrar2 = Fabricate(:registrar2)
|
||||
# @epp_xml = EppXml::Contact.new(cl_trid: 'ABC-12345')
|
||||
|
||||
# Fabricate(:api_user, username: 'registrar1', registrar: @registrar1)
|
||||
# Fabricate(:api_user, username: 'registrar2', registrar: @registrar2)
|
||||
|
||||
# login_as :registrar1
|
||||
|
||||
# Contact.skip_callback(:create, :before, :generate_code)
|
||||
# Contact.skip_callback(:create, :before, :generate_auth_info)
|
||||
# end
|
||||
|
||||
# after :all do
|
||||
# Contact.set_callback(:create, :before, :generate_code)
|
||||
# Contact.set_callback(:create, :before, :generate_auth_info)
|
||||
# end
|
||||
|
||||
# context 'with valid user' do
|
||||
# context 'create command' do
|
||||
# it 'fails if request xml is missing' do
|
||||
# xml = @epp_xml.create
|
||||
# response = epp_plain_request(xml, :xml)
|
||||
# response[:results][0][:msg].should == 'Command syntax error'
|
||||
# response[:results][0][:result_code].should == '2001'
|
||||
|
||||
# response[:results].count.should == 1
|
||||
# end
|
||||
|
||||
# it 'fails if request xml is missing' do
|
||||
# xml = @epp_xml.create(
|
||||
# postalInfo: { addr: { value: nil } }
|
||||
# )
|
||||
# response = epp_plain_request(xml, :xml)
|
||||
# response[:results][0][:msg].should == 'Required parameter missing: name'
|
||||
# response[:results][1][:msg].should == 'Required parameter missing: city'
|
||||
# response[:results][2][:msg].should == 'Required parameter missing: cc'
|
||||
# response[:results][3][:msg].should == 'Required parameter missing: ident'
|
||||
# response[:results][4][:msg].should == 'Required parameter missing: voice'
|
||||
# response[:results][5][:msg].should == 'Required parameter missing: email'
|
||||
|
||||
# response[:results][0][:result_code].should == '2003'
|
||||
# response[:results][1][:result_code].should == '2003'
|
||||
# response[:results][2][:result_code].should == '2003'
|
||||
# response[:results][3][:result_code].should == '2003'
|
||||
# response[:results][4][:result_code].should == '2003'
|
||||
# response[:results][5][:result_code].should == '2003'
|
||||
|
||||
# response[:results].count.should == 6
|
||||
# end
|
||||
|
||||
# it 'successfully saves ident type' do
|
||||
# xml = { ident: { value: '1990-22-12', attrs: { type: 'birthday' } } }
|
||||
# epp_plain_request(create_contact_xml(xml), :xml)
|
||||
|
||||
# Contact.last.ident_type.should == 'birthday'
|
||||
# end
|
||||
|
||||
# it 'successfully creates a contact' do
|
||||
# response = epp_plain_request(create_contact_xml, :xml)
|
||||
|
||||
# response[:msg].should == 'Command completed successfully'
|
||||
# response[:result_code].should == '1000'
|
||||
|
||||
# @contact = Contact.last
|
||||
|
||||
# @contact.registrar.should == @registrar1
|
||||
# # registrar1.api_users.should include(@contact.created_by)
|
||||
# # @contact.updated_by_id.should == nil
|
||||
# @contact.ident.should == '37605030299'
|
||||
# @contact.address.street.should == '123 Example'
|
||||
|
||||
# log = ApiLog::EppLog.last
|
||||
# log.request_command.should == 'create'
|
||||
# log.request_object.should == 'contact'
|
||||
# log.request_successful.should == true
|
||||
# log.api_user_name.should == '1-api-registrar1'
|
||||
# log.api_user_registrar.should == 'registrar1'
|
||||
# end
|
||||
|
||||
# it 'successfully adds registrar' do
|
||||
# response = epp_plain_request(create_contact_xml, :xml)
|
||||
|
||||
# response[:msg].should == 'Command completed successfully'
|
||||
# response[:result_code].should == '1000'
|
||||
|
||||
# Contact.last.registrar.should == @registrar1
|
||||
# end
|
||||
|
||||
# it 'returns result data upon success' do
|
||||
# response = epp_plain_request(create_contact_xml, :xml)
|
||||
|
||||
# response[:msg].should == 'Command completed successfully'
|
||||
# response[:result_code].should == '1000'
|
||||
|
||||
# id = response[:parsed].css('resData creData id').first
|
||||
# cr_date = response[:parsed].css('resData creData crDate').first
|
||||
|
||||
# id.text.length.should == 8
|
||||
# # 5 seconds for what-ever weird lag reasons might happen
|
||||
# cr_date.text.to_time.should be_within(5).of(Time.now)
|
||||
# end
|
||||
|
||||
# it 'creates disclosure data' do
|
||||
# xml = {
|
||||
# disclose: { value: {
|
||||
# voice: { value: '' },
|
||||
# addr: { value: '' },
|
||||
# name: { value: '' },
|
||||
# org_name: { value: '' },
|
||||
# email: { value: '' },
|
||||
# fax: { value: '' }
|
||||
# }, attrs: { flag: '1' }
|
||||
# }
|
||||
# }
|
||||
|
||||
# response = epp_plain_request(create_contact_xml(xml), :xml)
|
||||
# response[:result_code].should == '1000'
|
||||
|
||||
# @contact = Contact.last
|
||||
# @contact.disclosure.name.should == true
|
||||
# @contact.disclosure.org_name.should == true
|
||||
# @contact.disclosure.phone.should == true
|
||||
# @contact.disclosure.fax.should == true
|
||||
# @contact.disclosure.email.should == true
|
||||
# @contact.disclosure.address.should == true
|
||||
# end
|
||||
|
||||
# it 'creates disclosure data merging with defaults' do
|
||||
# xml = {
|
||||
# disclose: { value: {
|
||||
# voice: { value: '' },
|
||||
# addr: { value: '' }
|
||||
# }, attrs: { flag: '1' }
|
||||
# }
|
||||
# }
|
||||
|
||||
# response = epp_plain_request(create_contact_xml(xml), :xml)
|
||||
# response[:result_code].should == '1000'
|
||||
|
||||
# @contact = Contact.last
|
||||
# @contact.disclosure.name.should == nil
|
||||
# @contact.disclosure.org_name.should == nil
|
||||
# @contact.disclosure.phone.should == true
|
||||
# @contact.disclosure.fax.should == nil
|
||||
# @contact.disclosure.email.should == nil
|
||||
# @contact.disclosure.address.should == true
|
||||
# end
|
||||
# end
|
||||
|
||||
# context 'update command' do
|
||||
# before :all do
|
||||
# @contact =
|
||||
# Fabricate(
|
||||
# :contact,
|
||||
# # created_by_id: 1,
|
||||
# registrar: @registrar1,
|
||||
# email: 'not_updated@test.test',
|
||||
# code: 'sh8013',
|
||||
# auth_info: 'password'
|
||||
# )
|
||||
# end
|
||||
|
||||
# it 'fails if request is invalid' do
|
||||
# xml = @epp_xml.update
|
||||
# response = epp_plain_request(xml, :xml) # epp_request('contacts/update_missing_attr.xml')
|
||||
|
||||
# response[:results][0][:result_code].should == '2003'
|
||||
# response[:results][0][:msg].should == 'Required parameter missing: add, rem or chg'
|
||||
# response[:results][1][:result_code].should == '2003'
|
||||
# response[:results][1][:msg].should == 'Required parameter missing: id'
|
||||
# response[:results].count.should == 2
|
||||
# end
|
||||
|
||||
# it 'fails with wrong authentication info' do
|
||||
# login_as :registrar2 do
|
||||
# response = epp_plain_request(update_contact_xml({ id: { value: 'sh8013' } }), :xml)
|
||||
# expect(response[:msg]).to eq('Authorization error')
|
||||
# expect(response[:result_code]).to eq('2201')
|
||||
# end
|
||||
# end
|
||||
|
||||
# it 'is succesful' do
|
||||
# response = epp_plain_request(update_contact_xml({ id: { value: 'sh8013' } }), :xml)
|
||||
|
||||
# response[:msg].should == 'Command completed successfully'
|
||||
# @contact.reload
|
||||
# @contact.name.should == 'John Doe Edited'
|
||||
# @contact.email.should == 'edited@example.example'
|
||||
# end
|
||||
|
||||
# it 'returns phone and email error' do
|
||||
# xml = {
|
||||
# id: { value: 'sh8013' },
|
||||
# chg: {
|
||||
# voice: { value: '123213' },
|
||||
# email: { value: 'aaa' }
|
||||
# }
|
||||
# }
|
||||
|
||||
# response = epp_plain_request(update_contact_xml(xml), :xml)
|
||||
|
||||
# response[:results][0][:msg].should == 'Phone nr is invalid'
|
||||
# response[:results][0][:result_code].should == '2005'
|
||||
|
||||
# response[:results][1][:msg].should == 'Email is invalid'
|
||||
# response[:results][1][:result_code].should == '2005'
|
||||
# end
|
||||
|
||||
# it 'updates disclosure items' do
|
||||
# Fabricate(
|
||||
# :contact,
|
||||
# code: 'sh8013disclosure',
|
||||
# auth_info: '2fooBAR',
|
||||
# registrar: @registrar1,
|
||||
# # created_by_id: ApiUser.first.id,
|
||||
# disclosure: Fabricate(:contact_disclosure, phone: true, email: true))
|
||||
|
||||
# xml = {
|
||||
# id: { value: 'sh8013disclosure' },
|
||||
# authInfo: { pw: { value: '2fooBAR' } }
|
||||
# }
|
||||
# @response = epp_plain_request(update_contact_xml(xml), :xml)
|
||||
|
||||
# @response[:results][0][:msg].should == 'Command completed successfully'
|
||||
# @response[:results][0][:result_code].should == '1000'
|
||||
|
||||
# Contact.last.disclosure.phone.should == false
|
||||
# Contact.last.disclosure.email.should == false
|
||||
# end
|
||||
# end
|
||||
|
||||
# context 'delete command' do
|
||||
# it 'fails if request is invalid' do
|
||||
# xml = @epp_xml.delete({ uid: { value: '23123' } })
|
||||
# response = epp_plain_request(xml, :xml)
|
||||
|
||||
# response[:results][0][:msg].should == 'Required parameter missing: id'
|
||||
# response[:results][0][:result_code].should == '2003'
|
||||
# response[:results].count.should == 1
|
||||
# end
|
||||
|
||||
# it 'deletes contact' do
|
||||
# @contact_deleted =
|
||||
# # Fabricate(:contact, code: 'dwa1234', created_by_id: ApiUser.first.id, registrar: registrar1)
|
||||
# Fabricate(:contact, code: 'dwa1234', registrar: @registrar1)
|
||||
|
||||
# response = epp_plain_request(delete_contact_xml({ id: { value: 'dwa1234' } }), :xml)
|
||||
# response[:msg].should == 'Command completed successfully'
|
||||
# response[:result_code].should == '1000'
|
||||
# response[:clTRID].should == 'ABC-12345'
|
||||
|
||||
# Contact.find_by_id(@contact_deleted.id).should == nil
|
||||
# end
|
||||
|
||||
# it 'returns error if obj doesnt exist' do
|
||||
# response = epp_plain_request(delete_contact_xml, :xml)
|
||||
# response[:msg].should == 'Object does not exist'
|
||||
# response[:result_code].should == '2303'
|
||||
# end
|
||||
|
||||
# it 'fails if contact has associated domain' do
|
||||
# Fabricate(
|
||||
# :domain,
|
||||
# registrar: @registrar1,
|
||||
# owner_contact: Fabricate(
|
||||
# :contact,
|
||||
# code: 'dwa1234',
|
||||
# # created_by_id: registrar1.id,
|
||||
# registrar: @registrar1)
|
||||
# )
|
||||
# Domain.last.owner_contact.address.present?.should == true
|
||||
# response = epp_plain_request(delete_contact_xml({ id: { value: 'dwa1234' } }), :xml)
|
||||
|
||||
# response[:msg].should == 'Object association prohibits operation'
|
||||
# response[:result_code].should == '2305'
|
||||
|
||||
# Domain.last.owner_contact.present?.should == true
|
||||
# end
|
||||
# end
|
||||
|
||||
# context 'check command' do
|
||||
# it 'fails if request is invalid' do
|
||||
# xml = @epp_xml.check({ uid: { value: '123asde' } })
|
||||
# response = epp_plain_request(xml, :xml)
|
||||
|
||||
# response[:results][0][:msg].should == 'Required parameter missing: id'
|
||||
# response[:results][0][:result_code].should == '2003'
|
||||
# response[:results].count.should == 1
|
||||
# end
|
||||
|
||||
# it 'returns info about contact availability' do
|
||||
# Fabricate(:contact, code: 'check-1234')
|
||||
|
||||
# response = epp_plain_request(check_multiple_contacts_xml, :xml)
|
||||
|
||||
# response[:msg].should == 'Command completed successfully'
|
||||
# response[:result_code].should == '1000'
|
||||
# ids = response[:parsed].css('resData chkData id')
|
||||
|
||||
# ids[0].attributes['avail'].text.should == '0'
|
||||
# ids[1].attributes['avail'].text.should == '1'
|
||||
|
||||
# ids[0].text.should == 'check-1234'
|
||||
# ids[1].text.should == 'check-4321'
|
||||
# end
|
||||
# end
|
||||
|
||||
# # context 'info command' do
|
||||
# # before :all do
|
||||
# # @registrar1_contact = Fabricate(:contact, code: 'info-4444', registrar: @registrar1,
|
||||
# # name: 'Johnny Awesome', address: Fabricate(:address))
|
||||
# # end
|
||||
|
||||
# # fit 'return info about contact' do
|
||||
# # login_as :registrar2 do
|
||||
# # xml = @epp_xml.info(id: { value: @registrar1_contact.code })
|
||||
# # response = epp_plain_request(xml, :xml)
|
||||
# # response[:msg].should == 'Command completed successfully'
|
||||
# # response[:result_code].should == '1000'
|
||||
|
||||
# # contact = response[:parsed].css('resData chkData')
|
||||
# # contact.css('name').first.text.should == 'Johnny Awesome'
|
||||
# # end
|
||||
# # end
|
||||
|
||||
# # it 'fails if request invalid' do
|
||||
# # response = epp_plain_request(@epp_xml.info({ wrongid: { value: '123123' } }), :xml)
|
||||
# # response[:results][0][:msg].should == 'Required parameter missing: id'
|
||||
# # response[:results][0][:result_code].should == '2003'
|
||||
# # response[:results].count.should == 1
|
||||
# # end
|
||||
|
||||
# # it 'returns error when object does not exist' do
|
||||
# # response = epp_plain_request(info_contact_xml({ id: { value: 'no-contact' } }), :xml)
|
||||
# # response[:msg].should == 'Object does not exist'
|
||||
# # response[:result_code].should == '2303'
|
||||
# # response[:results][0][:value].should == 'no-contact'
|
||||
# # end
|
||||
|
||||
# # # it 'returns auth error for non-owner with wrong password' do
|
||||
# # # @contact = Fabricate(:contact,
|
||||
# # # registrar: registrar2, code: 'info-4444', name: 'Johnny Awesome', auth_info: 'asde',
|
||||
# # # address: Fabricate(:address), disclosure: Fabricate(:contact_disclosure, name: false))
|
||||
|
||||
# # # xml = @epp_xml.info({ id: { value: @contact.code }, authInfo: { pw: { value: 'asdesde' } } })
|
||||
# # # response = epp_plain_request(xml, :xml, :registrar1)
|
||||
|
||||
# # # expect(response[:result_code]).to eq('2200')
|
||||
# # # expect(response[:msg]).to eq('Authentication error')
|
||||
# # # end
|
||||
|
||||
# # context 'about disclose' do
|
||||
# # it 'discloses items with wrong password when queried by owner' do
|
||||
# # @contact = Fabricate(:contact,
|
||||
# # registrar: registrar1, code: 'info-4444',
|
||||
# # name: 'Johnny Awesome', auth_info: 'asde',
|
||||
# # address: Fabricate(:address), disclosure: Fabricate(:contact_disclosure, name: false))
|
||||
|
||||
# # xml = @epp_xml.info({ id: { value: @contact.code } })
|
||||
# # login_as :registrar1 do
|
||||
# # response = epp_plain_request(xml, :xml)
|
||||
# # contact = response[:parsed].css('resData chkData')
|
||||
|
||||
# # expect(response[:result_code]).to eq('1000')
|
||||
# # expect(response[:msg]).to eq('Command completed successfully')
|
||||
# # expect(contact.css('name').first.text).to eq('Johnny Awesome')
|
||||
# # end
|
||||
# # end
|
||||
|
||||
# # it 'doesn\'t disclose items to non-owner with right password' do
|
||||
# # @contact = Fabricate(:contact, registrar: registrar2, code: 'info-4444',
|
||||
# # name: 'Johnny Awesome', auth_info: 'password',
|
||||
# # address: Fabricate(:address), disclosure: Fabricate(:contact_disclosure, name: false))
|
||||
|
||||
# # xml = @epp_xml.info({ id: { value: @contact.code }, authInfo: { pw: { value: 'password' } } })
|
||||
# # response = epp_plain_request(xml, :xml, :registrar1)
|
||||
# # contact = response[:parsed].css('resData chkData')
|
||||
|
||||
# # expect(response[:result_code]).to eq('1000')
|
||||
# # expect(response[:msg]).to eq('Command completed successfully')
|
||||
# # expect(contact.css('chkData postalInfo name').first).to eq(nil)
|
||||
# # end
|
||||
|
||||
# # it 'discloses items to owner' do
|
||||
# # @contact = Fabricate(:contact, registrar: registrar1, code: 'info-4444', name: 'Johnny Awesome',
|
||||
# # auth_info: 'password',
|
||||
# # address: Fabricate(:address), disclosure: Fabricate(:contact_disclosure, name: false))
|
||||
|
||||
# # xml = @epp_xml.info({ id: { value: @contact.code } })
|
||||
# # response = epp_plain_request(xml, :xml, :registrar1)
|
||||
# # contact = response[:parsed].css('resData chkData')
|
||||
|
||||
# # expect(response[:result_code]).to eq('1000')
|
||||
# # expect(response[:msg]).to eq('Command completed successfully')
|
||||
# # expect(contact.css('name').first.text).to eq('Johnny Awesome')
|
||||
# # end
|
||||
|
||||
# # it 'doesn\'t disclose private elements' do
|
||||
# # Fabricate(:contact, code: 'info-4444', auth_info: '2fooBAR', registrar: registrar2,
|
||||
# # disclosure: Fabricate(:contact_disclosure, name: true, email: false, phone: false))
|
||||
|
||||
# # xml = @epp_xml.info({ id: { value: 'info-4444' }, authInfo: { pw: { value: '2fooBAR' } } })
|
||||
|
||||
# # response = epp_plain_request(xml, :xml, :registrar1)
|
||||
# # contact = response[:parsed].css('resData chkData')
|
||||
|
||||
# # expect(response[:result_code]).to eq('1000')
|
||||
|
||||
# # expect(contact.css('chkData phone')).to eq(contact.css('chkData disclose phone'))
|
||||
# # expect(contact.css('chkData phone').count).to eq(1)
|
||||
# # expect(contact.css('chkData email')).to eq(contact.css('chkData disclose email'))
|
||||
# # expect(contact.css('chkData email').count).to eq(1)
|
||||
# # expect(contact.css('postalInfo name').present?).to be(true)
|
||||
# # end
|
||||
# # end
|
||||
|
||||
# # it 'does not display unassociated object without password' do
|
||||
# # xml = @epp_xml.info(id: { value: @registrar1_contact.code })
|
||||
# # response = epp_plain_request(xml, :xml, :registrar2)
|
||||
# # expect(response[:result_code]).to eq('2003')
|
||||
# # expect(response[:msg]).to eq('Required parameter missing: pw')
|
||||
# # end
|
||||
|
||||
# # it 'does not display unassociated object with wrong password' do
|
||||
# # login_as :registrar2
|
||||
# # xml = @epp_xml.info(id: { value: @registrar1_contact.code },
|
||||
# # authInfo: { pw: { value: 'wrong-pw' } })
|
||||
# # response = epp_plain_request(xml, :xml)
|
||||
|
||||
# # response[:msg].should == 'Authentication error'
|
||||
# # response[:result_code].should == '2200'
|
||||
# # end
|
||||
# # end
|
||||
|
||||
# context 'renew command' do
|
||||
# it 'returns 2101-unimplemented command' do
|
||||
# response = epp_plain_request('contacts/renew.xml')
|
||||
|
||||
# response[:msg].should == 'Unimplemented command'
|
||||
# response[:result_code].should == '2101'
|
||||
# end
|
||||
# end
|
||||
# end
|
||||
# end
|
||||
require 'rails_helper'
|
||||
|
||||
describe 'EPP Contact', epp: true do
|
||||
before :all do
|
||||
create_settings
|
||||
create_disclosure_settings
|
||||
@registrar1 = Fabricate(:registrar1)
|
||||
@registrar2 = Fabricate(:registrar2)
|
||||
@epp_xml = EppXml::Contact.new(cl_trid: 'ABC-12345')
|
||||
|
||||
Fabricate(:api_user, username: 'registrar1', registrar: @registrar1)
|
||||
Fabricate(:api_user, username: 'registrar2', registrar: @registrar2)
|
||||
|
||||
login_as :registrar1
|
||||
|
||||
Contact.skip_callback(:create, :before, :generate_code)
|
||||
Contact.skip_callback(:create, :before, :generate_auth_info)
|
||||
|
||||
@contact = Fabricate(:contact, registrar: @registrar1)
|
||||
end
|
||||
|
||||
after :all do
|
||||
Contact.set_callback(:create, :before, :generate_code)
|
||||
Contact.set_callback(:create, :before, :generate_auth_info)
|
||||
end
|
||||
|
||||
context 'with valid user' do
|
||||
context 'create command' do
|
||||
def create_request(overwrites = {})
|
||||
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', attrs: { type: 'priv' } }
|
||||
}
|
||||
create_xml = @epp_xml.create(defaults.deep_merge(overwrites))
|
||||
epp_plain_request(create_xml, :xml)
|
||||
end
|
||||
|
||||
it 'fails if request xml is missing' do
|
||||
response = epp_plain_request(@epp_xml.create, :xml)
|
||||
response[:results][0][:msg].should ==
|
||||
'Required parameter missing: create > create > postalInfo > name'
|
||||
response[:results][1][:msg].should ==
|
||||
'Required parameter missing: create > create > postalInfo > addr > city'
|
||||
response[:results][2][:msg].should ==
|
||||
'Required parameter missing: create > create > postalInfo > addr > cc'
|
||||
response[:results][3][:msg].should ==
|
||||
'Required parameter missing: create > create > ident'
|
||||
response[:results][4][:msg].should ==
|
||||
'Required parameter missing: create > create > voice'
|
||||
response[:results][5][:msg].should ==
|
||||
'Required parameter missing: create > create > email'
|
||||
|
||||
response[:results][0][:result_code].should == '2003'
|
||||
response[:results][1][:result_code].should == '2003'
|
||||
response[:results][2][:result_code].should == '2003'
|
||||
response[:results][3][:result_code].should == '2003'
|
||||
response[:results][4][:result_code].should == '2003'
|
||||
response[:results][5][:result_code].should == '2003'
|
||||
|
||||
response[:results].count.should == 6
|
||||
end
|
||||
|
||||
it 'successfully creates a contact' do
|
||||
response = create_request
|
||||
|
||||
response[:msg].should == 'Command completed successfully'
|
||||
response[:result_code].should == '1000'
|
||||
|
||||
@contact = Contact.last
|
||||
|
||||
@contact.registrar.should == @registrar1
|
||||
@registrar1.api_users.should include(@contact.creator)
|
||||
@contact.ident.should == '37605030299'
|
||||
@contact.address.street.should == '123 Example'
|
||||
|
||||
log = ApiLog::EppLog.last
|
||||
log.request_command.should == 'create'
|
||||
log.request_object.should == 'contact'
|
||||
log.request_successful.should == true
|
||||
log.api_user_name.should == '1-api-registrar1'
|
||||
log.api_user_registrar.should == 'registrar1'
|
||||
end
|
||||
|
||||
it 'successfully saves ident type' do
|
||||
response = create_request(
|
||||
{ ident: { value: '1990-22-12', attrs: { type: 'birthday' } } }
|
||||
)
|
||||
|
||||
response[:msg].should == 'Command completed successfully'
|
||||
response[:result_code].should == '1000'
|
||||
|
||||
Contact.last.ident_type.should == 'birthday'
|
||||
end
|
||||
|
||||
it 'successfully adds registrar' do
|
||||
response = create_request
|
||||
|
||||
response[:msg].should == 'Command completed successfully'
|
||||
response[:result_code].should == '1000'
|
||||
|
||||
Contact.last.registrar.should == @registrar1
|
||||
end
|
||||
|
||||
it 'returns result data upon success' do
|
||||
response = create_request
|
||||
|
||||
response[:msg].should == 'Command completed successfully'
|
||||
response[:result_code].should == '1000'
|
||||
|
||||
id = response[:parsed].css('resData creData id').first
|
||||
cr_date = response[:parsed].css('resData creData crDate').first
|
||||
|
||||
id.text.length.should == 8
|
||||
# 5 seconds for what-ever weird lag reasons might happen
|
||||
cr_date.text.to_time.should be_within(5).of(Time.now)
|
||||
end
|
||||
end
|
||||
|
||||
context 'update command' do
|
||||
before :all do
|
||||
@contact =
|
||||
Fabricate(
|
||||
:contact,
|
||||
# created_by_id: 1,
|
||||
registrar: @registrar1,
|
||||
email: 'not_updated@test.test',
|
||||
code: 'sh8013',
|
||||
auth_info: 'password'
|
||||
)
|
||||
end
|
||||
|
||||
def update_request(overwrites = {})
|
||||
defaults = {
|
||||
id: { value: 'asd123123er' },
|
||||
authInfo: { pw: { value: 'password' } },
|
||||
chg: {
|
||||
postalInfo: {
|
||||
name: { value: 'John Doe Edited' }
|
||||
},
|
||||
voice: { value: '+372.7654321' },
|
||||
email: { value: 'edited@example.example' },
|
||||
disclose: {
|
||||
value: {
|
||||
voice: { value: '' },
|
||||
email: { value: '' }
|
||||
}, attrs: { flag: '0' }
|
||||
}
|
||||
}
|
||||
}
|
||||
update_xml = @epp_xml.update(defaults.deep_merge(overwrites))
|
||||
epp_plain_request(update_xml, :xml)
|
||||
end
|
||||
|
||||
it 'fails if request is invalid' do
|
||||
response = epp_plain_request(@epp_xml.update, :xml)
|
||||
|
||||
response[:results][0][:msg].should ==
|
||||
'Required parameter missing: add, rem or chg'
|
||||
response[:results][0][:result_code].should == '2003'
|
||||
response[:results][1][:msg].should ==
|
||||
'Required parameter missing: update > update > id'
|
||||
response[:results][1][:result_code].should == '2003'
|
||||
response[:results][2][:msg].should ==
|
||||
'Required parameter missing: update > update > authInfo > pw'
|
||||
response[:results][2][:result_code].should == '2003'
|
||||
response[:results].count.should == 3
|
||||
end
|
||||
|
||||
it 'returns error if obj doesnt exist' do
|
||||
response = update_request({ id: { value: 'not-exists' } })
|
||||
response[:msg].should == 'Object does not exist'
|
||||
response[:result_code].should == '2303'
|
||||
response[:results].count.should == 1
|
||||
end
|
||||
|
||||
it 'is succesful' do
|
||||
response = update_request({ id: { value: 'sh8013' } })
|
||||
|
||||
response[:msg].should == 'Command completed successfully'
|
||||
@contact.reload
|
||||
@contact.name.should == 'John Doe Edited'
|
||||
@contact.email.should == 'edited@example.example'
|
||||
end
|
||||
|
||||
it 'fails with wrong authentication info' do
|
||||
login_as :registrar2 do
|
||||
response = update_request({ id: { value: 'sh8013' } })
|
||||
response[:msg].should == 'Authorization error'
|
||||
response[:result_code].should == '2201'
|
||||
end
|
||||
end
|
||||
|
||||
it 'returns phone and email error' do
|
||||
response = update_request({
|
||||
id: { value: 'sh8013' },
|
||||
chg: {
|
||||
voice: { value: '123213' },
|
||||
email: { value: 'wrong' }
|
||||
}
|
||||
})
|
||||
|
||||
response[:results][0][:msg].should == 'Phone nr is invalid'
|
||||
response[:results][0][:result_code].should == '2005'
|
||||
response[:results][1][:msg].should == 'Email is invalid'
|
||||
response[:results][1][:result_code].should == '2005'
|
||||
end
|
||||
end
|
||||
|
||||
context 'delete command' do
|
||||
before do
|
||||
@contact = Fabricate(:contact, registrar: @registrar1)
|
||||
end
|
||||
|
||||
def delete_request(overwrites = {})
|
||||
defaults = {
|
||||
id: { value: @contact.code },
|
||||
authInfo: { pw: { value: @contact.auth_info } }
|
||||
}
|
||||
delete_xml = @epp_xml.delete(defaults.deep_merge(overwrites))
|
||||
epp_plain_request(delete_xml, :xml)
|
||||
end
|
||||
|
||||
it 'fails if request is invalid' do
|
||||
response = epp_plain_request(@epp_xml.delete, :xml)
|
||||
|
||||
response[:results][0][:msg].should ==
|
||||
'Required parameter missing: delete > delete > id'
|
||||
response[:results][0][:result_code].should == '2003'
|
||||
response[:results][1][:msg].should ==
|
||||
'Required parameter missing: delete > delete > authInfo > pw'
|
||||
response[:results][1][:result_code].should == '2003'
|
||||
response[:results].count.should == 2
|
||||
end
|
||||
|
||||
it 'returns error if obj doesnt exist' do
|
||||
response = delete_request({ id: { value: 'not-exists' } })
|
||||
response[:msg].should == 'Object does not exist'
|
||||
response[:result_code].should == '2303'
|
||||
response[:results].count.should == 1
|
||||
end
|
||||
|
||||
it 'deletes contact' do
|
||||
response = delete_request
|
||||
response[:msg].should == 'Command completed successfully'
|
||||
response[:result_code].should == '1000'
|
||||
response[:clTRID].should == 'ABC-12345'
|
||||
|
||||
Contact.find_by_id(@contact.id).should == nil
|
||||
end
|
||||
|
||||
it 'fails if contact has associated domain' do
|
||||
@domain = Fabricate(:domain, registrar: @registrar1, owner_contact: @contact)
|
||||
@domain.owner_contact.address.present?.should == true
|
||||
|
||||
response = delete_request
|
||||
response[:msg].should == 'Object association prohibits operation'
|
||||
response[:result_code].should == '2305'
|
||||
response[:results].count.should == 1
|
||||
|
||||
@domain.owner_contact.present?.should == true
|
||||
end
|
||||
|
||||
it 'fails with wrong authentication info' do
|
||||
login_as :registrar2 do
|
||||
response = delete_request
|
||||
response[:msg].should == 'Authorization error'
|
||||
response[:result_code].should == '2201'
|
||||
response[:results].count.should == 1
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context 'check command' do
|
||||
def check_request(overwrites = {})
|
||||
defaults = {
|
||||
id: { value: @contact.code },
|
||||
authInfo: { pw: { value: @contact.auth_info } }
|
||||
}
|
||||
xml = @epp_xml.check(defaults.deep_merge(overwrites))
|
||||
epp_plain_request(xml, :xml)
|
||||
end
|
||||
|
||||
it 'fails if request is invalid' do
|
||||
response = epp_plain_request(@epp_xml.check, :xml)
|
||||
|
||||
response[:results][0][:msg].should == 'Required parameter missing: check > check > id'
|
||||
response[:results][0][:result_code].should == '2003'
|
||||
response[:results].count.should == 1
|
||||
end
|
||||
|
||||
it 'returns info about contact availability' do
|
||||
Fabricate(:contact, code: 'check-1234')
|
||||
|
||||
response = epp_plain_request(check_multiple_contacts_xml, :xml)
|
||||
|
||||
response[:msg].should == 'Command completed successfully'
|
||||
response[:result_code].should == '1000'
|
||||
ids = response[:parsed].css('resData chkData id')
|
||||
|
||||
ids[0].attributes['avail'].text.should == '0'
|
||||
ids[1].attributes['avail'].text.should == '1'
|
||||
|
||||
ids[0].text.should == 'check-1234'
|
||||
ids[1].text.should == 'check-4321'
|
||||
end
|
||||
end
|
||||
|
||||
context 'info command' do
|
||||
before :all do
|
||||
@registrar1_contact = Fabricate(
|
||||
:contact, code: 'info-4444', registrar: @registrar1,
|
||||
name: 'Johnny Awesome', address: Fabricate(:address))
|
||||
end
|
||||
|
||||
def info_request(overwrites = {})
|
||||
defaults = {
|
||||
id: { value: @contact.code },
|
||||
authInfo: { pw: { value: @contact.auth_info } }
|
||||
}
|
||||
xml = @epp_xml.info(defaults.deep_merge(overwrites))
|
||||
epp_plain_request(xml, :xml)
|
||||
end
|
||||
|
||||
it 'fails if request invalid' do
|
||||
response = epp_plain_request(@epp_xml.info, :xml)
|
||||
response[:results][0][:msg].should ==
|
||||
'Required parameter missing: info > info > id'
|
||||
response[:results][0][:result_code].should == '2003'
|
||||
response[:results].count.should == 1
|
||||
end
|
||||
|
||||
it 'returns error when object does not exist' do
|
||||
response = info_request({ id: { value: 'no-contact' } })
|
||||
response[:msg].should == 'Object does not exist'
|
||||
response[:result_code].should == '2303'
|
||||
response[:results][0][:value].should == 'no-contact'
|
||||
response[:results].count.should == 1
|
||||
end
|
||||
|
||||
it 'return info about contact' do
|
||||
response = info_request({ id: { value: @registrar1_contact.code } })
|
||||
response[:msg].should == 'Command completed successfully'
|
||||
response[:result_code].should == '1000'
|
||||
|
||||
contact = response[:parsed].css('resData chkData')
|
||||
contact.css('name').first.text.should == 'Johnny Awesome'
|
||||
end
|
||||
|
||||
it 'returns no authorization error for wrong password when owner' do
|
||||
response = info_request({ authInfo: { pw: { value: 'wrong-pw' } } })
|
||||
|
||||
response[:msg].should == 'Command completed successfully'
|
||||
response[:result_code].should == '1000'
|
||||
response[:results].count.should == 1
|
||||
end
|
||||
|
||||
it 'returns no authorization error for wrong user but correct pw' do
|
||||
login_as :registrar2 do
|
||||
response = info_request
|
||||
|
||||
response[:msg].should == 'Command completed successfully'
|
||||
response[:result_code].should == '1000'
|
||||
response[:results].count.should == 1
|
||||
end
|
||||
end
|
||||
|
||||
it 'returns authorization error for wrong user and wrong pw' do
|
||||
login_as :registrar2 do
|
||||
response = info_request({ authInfo: { pw: { value: 'wrong-pw' } } })
|
||||
response[:msg].should == 'Authorization error'
|
||||
response[:result_code].should == '2201'
|
||||
response[:results].count.should == 1
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context 'renew command' do
|
||||
it 'returns 2101-unimplemented command' do
|
||||
response = epp_plain_request('contacts/renew.xml')
|
||||
|
||||
response[:msg].should == 'Unimplemented command'
|
||||
response[:result_code].should == '2101'
|
||||
end
|
||||
end
|
||||
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
|
||||
|
|
|
@ -206,8 +206,16 @@ describe 'EPP Domain', epp: true do
|
|||
it 'does not create domain without nameservers' do
|
||||
xml = domain_create_xml(ns: [])
|
||||
response = epp_plain_request(xml, :xml)
|
||||
response[:result_code].should == '2003'
|
||||
response[:msg].should == 'Required parameter missing: create > create > ns > hostAttr'
|
||||
|
||||
response[:results][0][:msg].should ==
|
||||
'Required parameter missing: create > create > ns'
|
||||
response[:results][0][:result_code].should == '2003'
|
||||
|
||||
response[:results][1][:msg].should ==
|
||||
'Required parameter missing: create > create > ns > hostAttr'
|
||||
response[:results][1][:result_code].should == '2003'
|
||||
|
||||
response[:results].count.should == 2
|
||||
end
|
||||
|
||||
it 'does not create domain with too many nameservers' do
|
||||
|
@ -294,8 +302,8 @@ describe 'EPP Domain', epp: true do
|
|||
xml = domain_create_xml(period_value: 365, period_unit: 'd')
|
||||
|
||||
response = epp_plain_request(xml, :xml)
|
||||
response[:result_code].should == '1000'
|
||||
response[:msg].should == 'Command completed successfully'
|
||||
response[:result_code].should == '1000'
|
||||
Domain.first.valid_to.should == Date.today + 1.year
|
||||
end
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue