new contact honors new format

This commit is contained in:
Priit Tark 2015-05-05 18:38:54 +03:00
parent ede71f8e61
commit 3fb9664e5b
9 changed files with 133 additions and 113 deletions

View file

@ -10,8 +10,6 @@ class Contact < ActiveRecord::Base
accepts_nested_attributes_for :legal_documents accepts_nested_attributes_for :legal_documents
attr_accessor :code_overwrite_allowed
validates :name, :phone, :email, :ident, :ident_type, validates :name, :phone, :email, :ident, :ident_type,
:street, :city, :zip, :country_code, :registrar, presence: true :street, :city, :zip, :country_code, :registrar, presence: true
@ -29,7 +27,7 @@ class Contact < ActiveRecord::Base
validate :ident_valid_format? validate :ident_valid_format?
before_validation :set_ident_country_code before_validation :set_ident_country_code
before_create :generate_code before_create :update_code
before_create :generate_auth_info before_create :generate_auth_info
after_save :manage_statuses after_save :manage_statuses
def manage_statuses def manage_statuses
@ -111,10 +109,6 @@ class Contact < ActiveRecord::Base
ident_type != BIC ident_type != BIC
end end
def generate_code
self.code = SecureRandom.hex(4).upcase if code.blank? || code_overwrite_allowed
end
def generate_auth_info def generate_auth_info
return if @generate_auth_info_disabled return if @generate_auth_info_disabled
self.auth_info = SecureRandom.hex(11) self.auth_info = SecureRandom.hex(11)
@ -129,7 +123,31 @@ class Contact < ActiveRecord::Base
end end
def code=(code) def code=(code)
self[:code] = code if new_record? || code_overwrite_allowed self[:code] = code if new_record? # cannot change code later
end
def update_code
code = self[:code]
# custom code from client
# add prefix when needed
if code.present?
code.sub!(/^CID:/, '')
prefix, *custom_code = code.split(':')
code = custom_code.join(':') if prefix == registrar.code
code = nil if code == registrar.code
end
code = SecureRandom.hex(4) if code.blank? || code == registrar.code
self[:code] = "#{registrar.code}:#{code}".upcase
end
# used only for contact trasfere
def generate_new_code!
return nil if registrar.blank?
registrar.reload # for contact transfere
self[:code] = "#{registrar.code}:#{SecureRandom.hex(4)}".upcase
end end
def country def country

View file

@ -51,20 +51,9 @@ class Epp::Contact < Contact
def new(frame, registrar) def new(frame, registrar)
return super if frame.blank? return super if frame.blank?
custom_code = frame.css('id').text
# add prefix when needed
if custom_code.present?
custom_code.sub!(/^CID:/, '')
prefix = custom_code.split(':').first
custom_code = "#{registrar.code}:#{custom_code}" if prefix != registrar.code
custom_code = nil if custom_code == registrar.code
custom_code.upcase! if custom_code.present?
end
super( super(
attrs_from(frame).merge( attrs_from(frame).merge(
code: custom_code, code: frame.css('id').text,
registrar: registrar registrar: registrar
) )
) )

View file

@ -448,9 +448,8 @@ class Epp::Domain < Domain
def transfer_contact(contact_id, registrar_id) def transfer_contact(contact_id, registrar_id)
oc = Contact.find(contact_id) # n+1 workaround oc = Contact.find(contact_id) # n+1 workaround
oc.code_overwrite_allowed = true
oc.generate_code
oc.registrar_id = registrar_id oc.registrar_id = registrar_id
oc.generate_new_code!
oc.save! oc.save!
oc oc
end end

View file

@ -137,7 +137,7 @@ describe 'EPP Contact', epp: true do
id = response[:parsed].css('resData creData id').first id = response[:parsed].css('resData creData id').first
cr_date = response[:parsed].css('resData creData crDate').first cr_date = response[:parsed].css('resData creData crDate').first
id.text.length.should == 8 id.text.length.should == 15
# 5 seconds for what-ever weird lag reasons might happen # 5 seconds for what-ever weird lag reasons might happen
cr_date.text.to_time.should be_within(5).of(Time.zone.now) cr_date.text.to_time.should be_within(5).of(Time.zone.now)
end end
@ -201,7 +201,7 @@ describe 'EPP Contact', epp: true do
response[:msg].should == 'Command completed successfully' response[:msg].should == 'Command completed successfully'
response[:result_code].should == '1000' response[:result_code].should == '1000'
Contact.last.code.match(':').should == nil Contact.last.code.should =~ /FIRST0:..../
end end
it 'should generate server id when id is empty' do it 'should generate server id when id is empty' do
@ -248,7 +248,7 @@ describe 'EPP Contact', epp: true do
:contact, :contact,
registrar: @registrar1, registrar: @registrar1,
email: 'not_updated@test.test', email: 'not_updated@test.test',
code: 'SH8013' code: 'FIRST0:SH8013'
) )
end end
@ -296,9 +296,10 @@ describe 'EPP Contact', epp: true do
end end
it 'is succesful' do it 'is succesful' do
response = update_request({ id: { value: 'SH8013' } }) response = update_request({ id: { value: 'FIRST0:SH8013' } })
response[:msg].should == 'Command completed successfully' response[:msg].should == 'Command completed successfully'
@contact.reload @contact.reload
@contact.name.should == 'John Doe Edited' @contact.name.should == 'John Doe Edited'
@contact.email.should == 'edited@example.example' @contact.email.should == 'edited@example.example'
@ -306,7 +307,7 @@ describe 'EPP Contact', epp: true do
it 'is succesful for own contact without password' do it 'is succesful for own contact without password' do
without_password = { without_password = {
id: { value: 'SH8013' }, id: { value: 'FIRST0:SH8013' },
chg: { chg: {
postalInfo: { postalInfo: {
name: { value: 'John Doe Edited' } name: { value: 'John Doe Edited' }
@ -323,7 +324,7 @@ describe 'EPP Contact', epp: true do
it 'should update other contact with correct password' do it 'should update other contact with correct password' do
login_as :registrar2 do login_as :registrar2 do
response = update_request({ id: { value: 'SH8013' } }) response = update_request({ id: { value: 'FIRST0:SH8013' } })
response[:msg].should == 'Command completed successfully' response[:msg].should == 'Command completed successfully'
response[:result_code].should == '1000' response[:result_code].should == '1000'
end end
@ -332,7 +333,7 @@ describe 'EPP Contact', epp: true do
it 'should not update other contact without password' do it 'should not update other contact without password' do
login_as :registrar2 do login_as :registrar2 do
without_password = { without_password = {
id: { value: 'SH8013' }, id: { value: 'FIRST0:SH8013' },
chg: { chg: {
postalInfo: { postalInfo: {
name: { value: 'John Doe Edited' } name: { value: 'John Doe Edited' }
@ -350,7 +351,7 @@ describe 'EPP Contact', epp: true do
it 'returns phone and email error' do it 'returns phone and email error' do
response = update_request({ response = update_request({
id: { value: 'SH8013' }, id: { value: 'FIRST0:SH8013' },
chg: { chg: {
voice: { value: '123213' }, voice: { value: '123213' },
email: { value: 'wrong' } email: { value: 'wrong' }
@ -365,7 +366,7 @@ describe 'EPP Contact', epp: true do
it 'should not update code with custom string' do it 'should not update code with custom string' do
response = update_request( response = update_request(
id: { value: 'SH8013' }, id: { value: 'FIRST0:SH8013' },
chg: { chg: {
id: { value: 'notpossibletoupdate' } id: { value: 'notpossibletoupdate' }
} }
@ -374,7 +375,7 @@ describe 'EPP Contact', epp: true do
response[:msg].should == 'Object does not exist' response[:msg].should == 'Object does not exist'
response[:result_code].should == '2303' response[:result_code].should == '2303'
@contact.reload.code.should == 'SH8013' @contact.reload.code.should == 'FIRST0:SH8013'
end end
it 'should update ident' do it 'should update ident' do
@ -388,16 +389,16 @@ describe 'EPP Contact', epp: true do
attrs: { type: 'birthday', cc: 'US' } attrs: { type: 'birthday', cc: 'US' }
} }
} }
response = update_request({ id: { value: 'SH8013' } }, extension) response = update_request({ id: { value: 'FIRST0:SH8013' } }, extension)
response[:msg].should == 'Command completed successfully' response[:msg].should == 'Command completed successfully'
response[:result_code].should == '1000' response[:result_code].should == '1000'
Contact.find_by(code: 'SH8013').ident_type.should == 'birthday' Contact.find_by(code: 'FIRST0:SH8013').ident_type.should == 'birthday'
end end
it 'should return parameter value policy errror for org update' do it 'should return parameter value policy errror for org update' do
response = update_request({ response = update_request({
id: { value: 'SH8013' }, id: { value: 'FIRST0:SH8013' },
chg: { chg: {
postalInfo: { org: { value: 'should not save' } } postalInfo: { org: { value: 'should not save' } }
} }
@ -406,12 +407,12 @@ describe 'EPP Contact', epp: true do
'Parameter value policy error. Org must be blank: postalInfo > org [org]' 'Parameter value policy error. Org must be blank: postalInfo > org [org]'
response[:result_code].should == '2306' response[:result_code].should == '2306'
Contact.find_by(code: 'SH8013').org_name.should == nil Contact.find_by(code: 'FIRST0:SH8013').org_name.should == nil
end end
it 'should return parameter value policy errror for fax update' do it 'should return parameter value policy errror for fax update' do
response = update_request({ response = update_request({
id: { value: 'SH8013' }, id: { value: 'FIRST0:SH8013' },
chg: { chg: {
fax: { value: 'should not save' } fax: { value: 'should not save' }
} }
@ -420,14 +421,14 @@ describe 'EPP Contact', epp: true do
'Parameter value policy error. Fax must be blank: fax [fax]' 'Parameter value policy error. Fax must be blank: fax [fax]'
response[:result_code].should == '2306' response[:result_code].should == '2306'
Contact.find_by(code: 'SH8013').fax.should == nil Contact.find_by(code: 'FIRST0:SH8013').fax.should == nil
end end
it 'does not allow to edit statuses if policy forbids it' do it 'does not allow to edit statuses if policy forbids it' do
Setting.client_status_editing_enabled = false Setting.client_status_editing_enabled = false
xml = @epp_xml.update({ xml = @epp_xml.update({
id: { value: 'SH8013' }, id: { value: 'FIRST0:SH8013' },
add: [{ add: [{
_anonymus: [ _anonymus: [
{ status: { value: 'Payment overdue.', attrs: { s: 'clientHold', lang: 'en' } } }, { status: { value: 'Payment overdue.', attrs: { s: 'clientHold', lang: 'en' } } },
@ -446,7 +447,7 @@ describe 'EPP Contact', epp: true do
it 'should add value voice value' do it 'should add value voice value' do
xml = @epp_xml.update({ xml = @epp_xml.update({
id: { value: 'SH8013' }, id: { value: 'FIRST0:SH8013' },
authInfo: { pw: { value: 'password' } }, authInfo: { pw: { value: 'password' } },
add: { add: {
voice: { value: '+372.11111111' } voice: { value: '+372.11111111' }
@ -457,7 +458,7 @@ describe 'EPP Contact', epp: true do
response[:results][0][:msg].should == 'Command completed successfully' response[:results][0][:msg].should == 'Command completed successfully'
response[:results][0][:result_code].should == '1000' response[:results][0][:result_code].should == '1000'
contact = Contact.find_by(code: 'SH8013') contact = Contact.find_by(code: 'FIRST0:SH8013')
contact.phone.should == '+372.11111111' contact.phone.should == '+372.11111111'
contact.update_attribute(:phone, '+372.7654321') # restore default value contact.update_attribute(:phone, '+372.7654321') # restore default value
@ -465,7 +466,7 @@ describe 'EPP Contact', epp: true do
it 'should return error when add attributes phone value is empty' do it 'should return error when add attributes phone value is empty' do
xml = @epp_xml.update({ xml = @epp_xml.update({
id: { value: 'SH8013' }, id: { value: 'FIRST0:SH8013' },
authInfo: { pw: { value: 'password' } }, authInfo: { pw: { value: 'password' } },
add: { add: {
voice: { value: '' } voice: { value: '' }
@ -478,12 +479,12 @@ describe 'EPP Contact', epp: true do
response = epp_plain_request(xml, :xml) response = epp_plain_request(xml, :xml)
response[:results][0][:msg].should == 'Required parameter missing - phone [phone]' response[:results][0][:msg].should == 'Required parameter missing - phone [phone]'
response[:results][0][:result_code].should == '2003' response[:results][0][:result_code].should == '2003'
Contact.find_by(code: 'SH8013').phone.should == '+372.7654321' # aka not changed Contact.find_by(code: 'FIRST0:SH8013').phone.should == '+372.7654321' # aka not changed
end end
it 'should honor chg value over add value when both changes same attribute' do it 'should honor chg value over add value when both changes same attribute' do
xml = @epp_xml.update({ xml = @epp_xml.update({
id: { value: 'SH8013' }, id: { value: 'FIRST0:SH8013' },
authInfo: { pw: { value: 'password' } }, authInfo: { pw: { value: 'password' } },
chg: { chg: {
voice: { value: '+372.2222222222222' } voice: { value: '+372.2222222222222' }
@ -497,7 +498,7 @@ describe 'EPP Contact', epp: true do
response[:results][0][:msg].should == 'Command completed successfully' response[:results][0][:msg].should == 'Command completed successfully'
response[:results][0][:result_code].should == '1000' response[:results][0][:result_code].should == '1000'
contact = Contact.find_by(code: 'SH8013') contact = Contact.find_by(code: 'FIRST0:SH8013')
contact.phone.should == '+372.2222222222222' contact.phone.should == '+372.2222222222222'
contact.update_attribute(:phone, '+372.7654321') # restore default value contact.update_attribute(:phone, '+372.7654321') # restore default value
@ -505,7 +506,7 @@ describe 'EPP Contact', epp: true do
it 'should not allow to remove required voice attribute' do it 'should not allow to remove required voice attribute' do
xml = @epp_xml.update({ xml = @epp_xml.update({
id: { value: 'SH8013' }, id: { value: 'FIRST0:SH8013' },
authInfo: { pw: { value: 'password' } }, authInfo: { pw: { value: 'password' } },
rem: { rem: {
voice: { value: '+372.7654321' } voice: { value: '+372.7654321' }
@ -516,13 +517,13 @@ describe 'EPP Contact', epp: true do
response[:results][0][:msg].should == 'Required parameter missing - phone [phone]' response[:results][0][:msg].should == 'Required parameter missing - phone [phone]'
response[:results][0][:result_code].should == '2003' response[:results][0][:result_code].should == '2003'
contact = Contact.find_by(code: 'SH8013') contact = Contact.find_by(code: 'FIRST0:SH8013')
contact.phone.should == '+372.7654321' contact.phone.should == '+372.7654321'
end end
it 'should not allow to remove required attribute' do it 'should not allow to remove required attribute' do
xml = @epp_xml.update({ xml = @epp_xml.update({
id: { value: 'SH8013' }, id: { value: 'FIRST0:SH8013' },
authInfo: { pw: { value: 'password' } }, authInfo: { pw: { value: 'password' } },
rem: { rem: {
voice: { value: '+372.7654321' } voice: { value: '+372.7654321' }
@ -533,13 +534,13 @@ describe 'EPP Contact', epp: true do
response[:results][0][:msg].should == 'Required parameter missing - phone [phone]' response[:results][0][:msg].should == 'Required parameter missing - phone [phone]'
response[:results][0][:result_code].should == '2003' response[:results][0][:result_code].should == '2003'
contact = Contact.find_by(code: 'SH8013') contact = Contact.find_by(code: 'FIRST0:SH8013')
contact.phone.should == '+372.7654321' contact.phone.should == '+372.7654321'
end end
it 'should honor add over rem' do it 'should honor add over rem' do
xml = @epp_xml.update({ xml = @epp_xml.update({
id: { value: 'SH8013' }, id: { value: 'FIRST0:SH8013' },
authInfo: { pw: { value: 'password' } }, authInfo: { pw: { value: 'password' } },
rem: { rem: {
voice: { value: 'not important' } voice: { value: 'not important' }
@ -553,7 +554,7 @@ describe 'EPP Contact', epp: true do
response[:results][0][:msg].should == 'Command completed successfully' response[:results][0][:msg].should == 'Command completed successfully'
response[:results][0][:result_code].should == '1000' response[:results][0][:result_code].should == '1000'
contact = Contact.find_by(code: 'SH8013') contact = Contact.find_by(code: 'FIRST0:SH8013')
contact.phone.should == '+372.3333333' contact.phone.should == '+372.3333333'
contact.update_attribute(:phone, '+372.7654321') # restore default value contact.update_attribute(:phone, '+372.7654321') # restore default value
@ -561,7 +562,7 @@ describe 'EPP Contact', epp: true do
it 'should honor chg over rem' do it 'should honor chg over rem' do
xml = @epp_xml.update({ xml = @epp_xml.update({
id: { value: 'SH8013' }, id: { value: 'FIRST0:SH8013' },
authInfo: { pw: { value: 'password' } }, authInfo: { pw: { value: 'password' } },
rem: { rem: {
voice: { value: 'not important' } voice: { value: 'not important' }
@ -575,7 +576,7 @@ describe 'EPP Contact', epp: true do
response[:results][0][:msg].should == 'Command completed successfully' response[:results][0][:msg].should == 'Command completed successfully'
response[:results][0][:result_code].should == '1000' response[:results][0][:result_code].should == '1000'
contact = Contact.find_by(code: 'SH8013') contact = Contact.find_by(code: 'FIRST0:SH8013')
contact.phone.should == '+372.44444444' contact.phone.should == '+372.44444444'
contact.update_attribute(:phone, '+372.7654321') # restore default value contact.update_attribute(:phone, '+372.7654321') # restore default value
@ -583,7 +584,7 @@ describe 'EPP Contact', epp: true do
it 'should honor chg over rem and add' do it 'should honor chg over rem and add' do
xml = @epp_xml.update({ xml = @epp_xml.update({
id: { value: 'SH8013' }, id: { value: 'FIRST0:SH8013' },
authInfo: { pw: { value: 'password' } }, authInfo: { pw: { value: 'password' } },
chg: { chg: {
voice: { value: '+372.666666' } voice: { value: '+372.666666' }
@ -600,7 +601,7 @@ describe 'EPP Contact', epp: true do
response[:results][0][:msg].should == 'Command completed successfully' response[:results][0][:msg].should == 'Command completed successfully'
response[:results][0][:result_code].should == '1000' response[:results][0][:result_code].should == '1000'
contact = Contact.find_by(code: 'SH8013') contact = Contact.find_by(code: 'FIRST0:SH8013')
contact.phone.should == '+372.666666' contact.phone.should == '+372.666666'
contact.update_attribute(:phone, '+372.7654321') # restore default value contact.update_attribute(:phone, '+372.7654321') # restore default value
@ -608,7 +609,7 @@ describe 'EPP Contact', epp: true do
it 'should not remove password' do it 'should not remove password' do
xml = @epp_xml.update({ xml = @epp_xml.update({
id: { value: 'SH8013' }, id: { value: 'FIRST0:SH8013' },
authInfo: { pw: { value: 'password' } }, authInfo: { pw: { value: 'password' } },
rem: { rem: {
authInfo: { pw: { value: 'password' } } authInfo: { pw: { value: 'password' } }
@ -619,13 +620,13 @@ describe 'EPP Contact', epp: true do
response[:results][0][:msg].should == 'Command completed successfully' response[:results][0][:msg].should == 'Command completed successfully'
response[:results][0][:result_code].should == '1000' response[:results][0][:result_code].should == '1000'
contact = Contact.find_by(code: 'SH8013') contact = Contact.find_by(code: 'FIRST0:SH8013')
contact.auth_info.should == 'password' contact.auth_info.should == 'password'
end end
it 'should return general policy error when removing org' do it 'should return general policy error when removing org' do
xml = @epp_xml.update({ xml = @epp_xml.update({
id: { value: 'SH8013' }, id: { value: 'FIRST0:SH8013' },
authInfo: { pw: { value: 'password' } }, authInfo: { pw: { value: 'password' } },
rem: { rem: {
postalInfo: { org: { value: 'not important' } } postalInfo: { org: { value: 'not important' } }
@ -640,7 +641,7 @@ describe 'EPP Contact', epp: true do
it 'should return error when removing street' do it 'should return error when removing street' do
xml = @epp_xml.update({ xml = @epp_xml.update({
id: { value: 'SH8013' }, id: { value: 'FIRST0:SH8013' },
authInfo: { pw: { value: 'password' } }, authInfo: { pw: { value: 'password' } },
rem: { rem: {
postalInfo: { postalInfo: {
@ -774,7 +775,8 @@ describe 'EPP Contact', epp: true do
end end
it 'returns info about contact availability' do it 'returns info about contact availability' do
Fabricate(:contact, code: 'check-1234') contact = Fabricate(:contact, code: 'check-1234')
contact.code.should == 'FIXED:CHECK-1234'
response = epp_plain_request(check_multiple_contacts_xml, :xml) response = epp_plain_request(check_multiple_contacts_xml, :xml)
@ -785,7 +787,7 @@ describe 'EPP Contact', epp: true do
ids[0].attributes['avail'].text.should == '0' ids[0].attributes['avail'].text.should == '0'
ids[1].attributes['avail'].text.should == '1' ids[1].attributes['avail'].text.should == '1'
ids[0].text.should == 'check-1234' ids[0].text.should == 'FIXED:CHECK-1234'
ids[1].text.should == 'check-4321' ids[1].text.should == 'check-4321'
end end
end end
@ -852,10 +854,10 @@ describe 'EPP Contact', epp: true do
end end
it 'should honor new contact code format' do it 'should honor new contact code format' do
@registrar1_contact = Fabricate(:contact, code: 'REGISTRAR1:TEST:CUSTOM:CODE') @registrar1_contact = Fabricate(:contact, code: 'FIXED:test:custom:code')
@registrar1_contact.code.should == 'REGISTRAR1:TEST:CUSTOM:CODE' @registrar1_contact.code.should == 'FIXED:TEST:CUSTOM:CODE'
response = info_request({ id: { value: 'REGISTRAR1:TEST:CUSTOM:CODE' } }) response = info_request({ id: { value: 'FIXED:TEST:CUSTOM:CODE' } })
response[:msg].should == 'Command completed successfully' response[:msg].should == 'Command completed successfully'
response[:result_code].should == '1000' response[:result_code].should == '1000'
@ -927,7 +929,7 @@ describe 'EPP Contact', epp: true do
<check> <check>
<contact:check <contact:check
xmlns:contact="urn:ietf:params:xml:ns:contact-1.0"> xmlns:contact="urn:ietf:params:xml:ns:contact-1.0">
<contact:id>check-1234</contact:id> <contact:id>FIXED:CHECK-1234</contact:id>
<contact:id>check-4321</contact:id> <contact:id>check-4321</contact:id>
</contact:check> </contact:check>
</check> </check>

View file

@ -10,10 +10,10 @@ describe 'EPP Domain', epp: true do
login_as :registrar1 login_as :registrar1
Fabricate(:contact, code: 'citizen_1234') Fabricate(:contact, code: 'FIXED:CITIZEN_1234')
Fabricate(:contact, code: 'sh8013') Fabricate(:contact, code: 'FIXED:SH8013')
Fabricate(:contact, code: 'sh801333') Fabricate(:contact, code: 'FIXED:SH801333')
Fabricate(:contact, code: 'juridical_1234', ident_type: 'bic') Fabricate(:contact, code: 'FIXED:JURIDICAL_1234', ident_type: 'bic')
Fabricate(:reserved_domain) Fabricate(:reserved_domain)
@uniq_no = proc { @i ||= 0; @i += 1 } @uniq_no = proc { @i ||= 0; @i += 1 }
@ -21,9 +21,9 @@ describe 'EPP Domain', epp: true do
it 'returns error if contact does not exists' do it 'returns error if contact does not exists' do
response = epp_plain_request(domain_create_xml({ response = epp_plain_request(domain_create_xml({
registrant: { value: 'citizen_1234' }, registrant: { value: 'FIXED:CITIZEN_1234' },
_anonymus: [ _anonymus: [
{ contact: { value: 'citizen_1234', attrs: { type: 'admin' } } }, { contact: { value: 'FIXED:CITIZEN_1234', attrs: { type: 'admin' } } },
{ contact: { value: 'sh1111', attrs: { type: 'tech' } } }, { contact: { value: 'sh1111', attrs: { type: 'tech' } } },
{ contact: { value: 'sh2222', attrs: { type: 'tech' } } } { contact: { value: 'sh2222', attrs: { type: 'tech' } } }
] ]
@ -650,9 +650,9 @@ describe 'EPP Domain', epp: true do
context 'with juridical persion as a registrant' do context 'with juridical persion as a registrant' do
it 'creates a domain with contacts' do it 'creates a domain with contacts' do
xml = domain_create_xml({ xml = domain_create_xml({
registrant: { value: 'juridical_1234' }, registrant: { value: 'FIXED:JURIDICAL_1234' },
_anonymus: [ _anonymus: [
{ contact: { value: 'sh8013', attrs: { type: 'admin' } } } { contact: { value: 'FIXED:SH8013', attrs: { type: 'admin' } } }
] ]
}) })
@ -665,16 +665,16 @@ describe 'EPP Domain', epp: true do
Domain.last.admin_contacts.count.should == 1 Domain.last.admin_contacts.count.should == 1
tech_contact = Domain.last.tech_contacts.first tech_contact = Domain.last.tech_contacts.first
tech_contact.code.should == 'juridical_1234' tech_contact.code.should == 'FIXED:JURIDICAL_1234'
end end
it 'does not create a domain without admin contact' do it 'does not create a domain without admin contact' do
domain_count = Domain.count domain_count = Domain.count
domain_contact_count = DomainContact.count domain_contact_count = DomainContact.count
xml = domain_create_xml({ xml = domain_create_xml({
registrant: { value: 'juridical_1234' }, registrant: { value: 'FIXED:JURIDICAL_1234' },
_anonymus: [ _anonymus: [
{ contact: { value: 'sh8013', attrs: { type: 'tech' } } } { contact: { value: 'FIXED:SH8013', attrs: { type: 'tech' } } }
] ]
}) })
@ -689,9 +689,9 @@ describe 'EPP Domain', epp: true do
it 'cannot assign juridical person as admin contact' do it 'cannot assign juridical person as admin contact' do
xml = domain_create_xml({ xml = domain_create_xml({
registrant: { value: 'juridical_1234' }, registrant: { value: 'FIXED:JURIDICAL_1234' },
_anonymus: [ _anonymus: [
{ contact: { value: 'juridical_1234', attrs: { type: 'admin' } } } { contact: { value: 'FIXED:JURIDICAL_1234', attrs: { type: 'admin' } } }
] ]
}) })
@ -1356,7 +1356,7 @@ describe 'EPP Domain', epp: true do
xml_params = { xml_params = {
name: { value: domain.name }, name: { value: domain.name },
chg: [ chg: [
registrant: { value: 'citizen_1234' } registrant: { value: 'FIXED:CITIZEN_1234' }
] ]
} }
@ -1374,7 +1374,7 @@ describe 'EPP Domain', epp: true do
d = Domain.last d = Domain.last
d.registrant_code.should == 'citizen_1234' d.registrant_code.should == 'FIXED:CITIZEN_1234'
d.auth_info.should == existing_pw d.auth_info.should == existing_pw
end end
@ -1397,7 +1397,7 @@ describe 'EPP Domain', epp: true do
] ]
}, },
_anonymus: [ _anonymus: [
{ contact: { value: 'mak21', attrs: { type: 'tech' } } }, { contact: { value: 'FIXED:MAK21', attrs: { type: 'tech' } } },
{ status: { value: 'Payment overdue.', attrs: { s: 'clientHold', lang: 'en' } } }, { status: { value: 'Payment overdue.', attrs: { s: 'clientHold', lang: 'en' } } },
{ status: { value: '', attrs: { s: 'clientUpdateProhibited' } } } { status: { value: '', attrs: { s: 'clientUpdateProhibited' } } }
] ]
@ -1426,7 +1426,7 @@ describe 'EPP Domain', epp: true do
response[:results][0][:result_code].should == '2303' response[:results][0][:result_code].should == '2303'
response[:results][0][:msg].should == 'Contact was not found' response[:results][0][:msg].should == 'Contact was not found'
Fabricate(:contact, code: 'mak21') Fabricate(:contact, code: 'FIXED:MAK21')
response = epp_plain_request(xml, :xml) response = epp_plain_request(xml, :xml)
response[:results][0][:result_code].should == '1000' response[:results][0][:result_code].should == '1000'
@ -1436,7 +1436,7 @@ describe 'EPP Domain', epp: true do
new_ns_count = d.nameservers.where(hostname: ['ns1.example.com', 'ns2.example.com']).count new_ns_count = d.nameservers.where(hostname: ['ns1.example.com', 'ns2.example.com']).count
new_ns_count.should == 2 new_ns_count.should == 2
new_contact = d.tech_contacts.find_by(code: 'mak21') new_contact = d.tech_contacts.find_by(code: 'FIXED:MAK21')
new_contact.should be_truthy new_contact.should be_truthy
d.domain_statuses.count.should == 2 d.domain_statuses.count.should == 2
@ -1466,7 +1466,7 @@ describe 'EPP Domain', epp: true do
response[:results][2][:result_code].should == '2302' response[:results][2][:result_code].should == '2302'
response[:results][2][:msg].should == 'Contact already exists on this domain [contact_code_cache]' response[:results][2][:msg].should == 'Contact already exists on this domain [contact_code_cache]'
response[:results][2][:value].should == 'mak21' response[:results][2][:value].should == 'FIXED:MAK21'
response[:results][3][:msg].should == 'Status already exists on this domain [value]' response[:results][3][:msg].should == 'Status already exists on this domain [value]'
if response[:results][3][:value] == 'clientHold' if response[:results][3][:value] == 'clientHold'
@ -1543,7 +1543,7 @@ describe 'EPP Domain', epp: true do
] ]
}, },
_anonymus: [ _anonymus: [
{ contact: { value: 'citizen_1234', attrs: { type: 'tech' } } }, { contact: { value: 'FIXED:CITIZEN_1234', attrs: { type: 'tech' } } },
{ status: { value: 'Payment overdue.', attrs: { s: 'clientHold', lang: 'en' } } }, { status: { value: 'Payment overdue.', attrs: { s: 'clientHold', lang: 'en' } } },
{ status: { value: '', attrs: { s: 'clientUpdateProhibited' } } } { status: { value: '', attrs: { s: 'clientUpdateProhibited' } } }
] ]
@ -1588,7 +1588,7 @@ describe 'EPP Domain', epp: true do
] ]
}, },
_anonymus: [ _anonymus: [
{ contact: { value: 'citizen_1234', attrs: { type: 'tech' } } }, { contact: { value: 'FIXED:CITIZEN_1234', attrs: { type: 'tech' } } },
{ status: { value: '', attrs: { s: 'clientHold' } } } { status: { value: '', attrs: { s: 'clientHold' } } }
] ]
] ]
@ -1613,7 +1613,7 @@ describe 'EPP Domain', epp: true do
rem_ns = d.nameservers.find_by(hostname: 'ns1.example.com') rem_ns = d.nameservers.find_by(hostname: 'ns1.example.com')
rem_ns.should be_falsey rem_ns.should be_falsey
rem_cnt = d.tech_contacts.find_by(code: 'citizen_1234') rem_cnt = d.tech_contacts.find_by(code: 'FIXED:CITIZEN_1234')
rem_cnt.should be_falsey rem_cnt.should be_falsey
response = epp_plain_request(xml, :xml) response = epp_plain_request(xml, :xml)
@ -1624,7 +1624,7 @@ describe 'EPP Domain', epp: true do
response[:results][1][:result_code].should == '2303' response[:results][1][:result_code].should == '2303'
response[:results][1][:msg].should == 'Contact was not found' response[:results][1][:msg].should == 'Contact was not found'
response[:results][1][:value].should == 'citizen_1234' response[:results][1][:value].should == 'FIXED:CITIZEN_1234'
response[:results][2][:result_code].should == '2303' response[:results][2][:result_code].should == '2303'
response[:results][2][:msg].should == 'Status was not found' response[:results][2][:msg].should == 'Status was not found'
@ -1688,7 +1688,7 @@ describe 'EPP Domain', epp: true do
xml_params = { xml_params = {
name: { value: domain.name }, name: { value: domain.name },
chg: [ chg: [
registrant: { value: 'citizen_1234' } registrant: { value: 'FIXED:CITIZEN_1234' }
] ]
} }

View file

@ -1,5 +1,5 @@
Fabricator(:contact) do Fabricator(:contact) do
registrar { Fabricate(:registrar) } registrar { Registrar.find_by_code('FIXED') }
code { sequence(:code) { |i| "SH#{Faker::Number.number(8)}#{i}" } } code { sequence(:code) { |i| "SH#{Faker::Number.number(8)}#{i}" } }
auth_info 'password' auth_info 'password'
name { sequence(:name) { |i| "#{Faker::Name.name}#{i}" } } name { sequence(:name) { |i| "#{Faker::Name.name}#{i}" } }

View file

@ -174,6 +174,10 @@ describe Contact do
contact.statuses.map(&:value).should == %w(ok) contact.statuses.map(&:value).should == %w(ok)
end end
it 'should have code' do
@contact.code.should =~ /FIXED:..../
end
it 'should have linked status when domain is created' do it 'should have linked status when domain is created' do
# @admin_domain_contact = Fabricate(:admin_domain_contact) # @admin_domain_contact = Fabricate(:admin_domain_contact)
# @domain = Fabricate(:domain, admin_domain_contacts: [@admin_domain_contact]) # @domain = Fabricate(:domain, admin_domain_contacts: [@admin_domain_contact])
@ -211,16 +215,17 @@ describe Contact do
context 'with callbacks' do context 'with callbacks' do
before :all do before :all do
# Ensure callbacks are not taken out from other specs # Ensure callbacks are not taken out from other specs
Contact.set_callback(:create, :before, :generate_code)
Contact.set_callback(:create, :before, :generate_auth_info) Contact.set_callback(:create, :before, :generate_auth_info)
end end
context 'after create' do context 'after create' do
it 'should not generate a new code when code is present' do it 'should not generate a new code when code is present' do
@contact = Fabricate.build(:contact, code: '123asd', auth_info: 'qwe321') @contact = Fabricate.build(:contact,
@contact.code.should == '123asd' code: 'FIXED:new-code',
auth_info: 'qwe321')
@contact.code.should == 'FIXED:new-code' # still new record
@contact.save.should == true @contact.save.should == true
@contact.code.should == '123asd' @contact.code.should == 'FIXED:NEW-CODE'
end end
it 'should generate a new password' do it 'should generate a new password' do
@ -262,15 +267,17 @@ describe Contact do
context 'after update' do context 'after update' do
before :all do before :all do
@contact = Fabricate.build(:contact, code: '123asd', auth_info: 'qwe321') @contact = Fabricate.build(:contact,
code: '123asd',
auth_info: 'qwe321')
@contact.save @contact.save
@contact.code.should == '123asd' @contact.code.should == 'FIXED:123ASD'
@auth_info = @contact.auth_info @auth_info = @contact.auth_info
end end
it 'should not generate new code' do it 'should not generate new code' do
@contact.update_attributes(name: 'qevciherot23') @contact.update_attributes(name: 'qevciherot23')
@contact.code.should == '123asd' @contact.code.should == 'FIXED:123ASD'
end end
it 'should not generate new auth_info' do it 'should not generate new auth_info' do

View file

@ -46,6 +46,10 @@ def create_settings
Setting.tech_contacts_max_count = 10 Setting.tech_contacts_max_count = 10
Setting.client_side_status_editing_enabled = true Setting.client_side_status_editing_enabled = true
@fixed_registrar =
Registrar.find_by_name('fixed registrar') ||
Fabricate(:registrar, name: 'fixed registrar', code: 'FIXED')
end end
RSpec.configure do |config| RSpec.configure do |config|
@ -121,3 +125,4 @@ RSpec.configure do |config|
Autodoc.configuration.suppressed_response_header = ['ETag', 'X-Request-Id', 'X-Runtime'] Autodoc.configuration.suppressed_response_header = ['ETag', 'X-Request-Id', 'X-Runtime']
Autodoc.configuration.template = File.read('spec/requests/repp_doc_template.md.erb') Autodoc.configuration.template = File.read('spec/requests/repp_doc_template.md.erb')
end end

View file

@ -150,11 +150,11 @@ module Epp
} }
} }
], ],
registrant: { value: 'citizen_1234' }, registrant: { value: 'FIXED:CITIZEN_1234' },
_anonymus: [ _anonymus: [
{ contact: { value: 'sh8013', attrs: { type: 'admin' } } }, { contact: { value: 'FIXED:SH8013', attrs: { type: 'admin' } } },
{ contact: { value: 'sh8013', attrs: { type: 'tech' } } }, { contact: { value: 'FIXED:SH8013', attrs: { type: 'tech' } } },
{ contact: { value: 'sh801333', attrs: { type: 'tech' } } } { contact: { value: 'FIXED:SH801333', attrs: { type: 'tech' } } }
] ]
} }
@ -204,11 +204,11 @@ module Epp
} }
} }
], ],
registrant: { value: 'citizen_1234' }, registrant: { value: 'FIXED:CITIZEN_1234' },
_anonymus: [ _anonymus: [
{ contact: { value: 'sh8013', attrs: { type: 'admin' } } }, { contact: { value: 'FIXED:SH8013', attrs: { type: 'admin' } } },
{ contact: { value: 'sh8013', attrs: { type: 'tech' } } }, { contact: { value: 'FIXED:SH8013', attrs: { type: 'tech' } } },
{ contact: { value: 'sh801333', attrs: { type: 'tech' } } } { contact: { value: 'FIXED:SH801333', attrs: { type: 'tech' } } }
] ]
} }
@ -244,11 +244,11 @@ module Epp
} }
} }
], ],
registrant: { value: 'citizen_1234' }, registrant: { value: 'FIXED:CITIZEN_1234' },
_anonymus: [ _anonymus: [
{ contact: { value: 'sh8013', attrs: { type: 'admin' } } }, { contact: { value: 'FIXED:SH8013', attrs: { type: 'admin' } } },
{ contact: { value: 'sh8013', attrs: { type: 'tech' } } }, { contact: { value: 'FIXED:SH8013', attrs: { type: 'tech' } } },
{ contact: { value: 'sh801333', attrs: { type: 'tech' } } } { contact: { value: 'FIXED:SH801333', attrs: { type: 'tech' } } }
], ],
authInfo: { authInfo: {
pw: { pw: {
@ -288,11 +288,11 @@ module Epp
} }
} }
], ],
registrant: { value: 'citizen_1234' }, registrant: { value: 'FIXED:CITIZEN_1234' },
_anonymus: [ _anonymus: [
{ contact: { value: 'sh8013', attrs: { type: 'admin' } } }, { contact: { value: 'FIXED:SH8013', attrs: { type: 'admin' } } },
{ contact: { value: 'sh8013', attrs: { type: 'tech' } } }, { contact: { value: 'FIXED:SH8013', attrs: { type: 'tech' } } },
{ contact: { value: 'sh801333', attrs: { type: 'tech' } } } { contact: { value: 'FIXED:SH801333', attrs: { type: 'tech' } } }
], ],
authInfo: { authInfo: {
pw: { pw: {