diff --git a/app/models/contact.rb b/app/models/contact.rb index ce36d9676..17924149e 100644 --- a/app/models/contact.rb +++ b/app/models/contact.rb @@ -10,8 +10,6 @@ class Contact < ActiveRecord::Base accepts_nested_attributes_for :legal_documents - attr_accessor :code_overwrite_allowed - validates :name, :phone, :email, :ident, :ident_type, :street, :city, :zip, :country_code, :registrar, presence: true @@ -29,7 +27,7 @@ class Contact < ActiveRecord::Base validate :ident_valid_format? before_validation :set_ident_country_code - before_create :generate_code + before_create :update_code before_create :generate_auth_info after_save :manage_statuses def manage_statuses @@ -111,10 +109,6 @@ class Contact < ActiveRecord::Base ident_type != BIC end - def generate_code - self.code = SecureRandom.hex(4).upcase if code.blank? || code_overwrite_allowed - end - def generate_auth_info return if @generate_auth_info_disabled self.auth_info = SecureRandom.hex(11) @@ -129,7 +123,31 @@ class Contact < ActiveRecord::Base end 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 def country diff --git a/app/models/epp/contact.rb b/app/models/epp/contact.rb index dd3a06f51..ea3e33eaf 100644 --- a/app/models/epp/contact.rb +++ b/app/models/epp/contact.rb @@ -51,20 +51,9 @@ class Epp::Contact < Contact def new(frame, registrar) 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( attrs_from(frame).merge( - code: custom_code, + code: frame.css('id').text, registrar: registrar ) ) diff --git a/app/models/epp/domain.rb b/app/models/epp/domain.rb index ccdb38436..0942abf5a 100644 --- a/app/models/epp/domain.rb +++ b/app/models/epp/domain.rb @@ -448,9 +448,8 @@ class Epp::Domain < Domain def transfer_contact(contact_id, registrar_id) oc = Contact.find(contact_id) # n+1 workaround - oc.code_overwrite_allowed = true - oc.generate_code oc.registrar_id = registrar_id + oc.generate_new_code! oc.save! oc end diff --git a/spec/epp/contact_spec.rb b/spec/epp/contact_spec.rb index a66dffa4c..f7a814740 100644 --- a/spec/epp/contact_spec.rb +++ b/spec/epp/contact_spec.rb @@ -137,7 +137,7 @@ describe 'EPP Contact', epp: true do id = response[:parsed].css('resData creData id').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 cr_date.text.to_time.should be_within(5).of(Time.zone.now) end @@ -201,7 +201,7 @@ describe 'EPP Contact', epp: true do response[:msg].should == 'Command completed successfully' response[:result_code].should == '1000' - Contact.last.code.match(':').should == nil + Contact.last.code.should =~ /FIRST0:..../ end it 'should generate server id when id is empty' do @@ -248,7 +248,7 @@ describe 'EPP Contact', epp: true do :contact, registrar: @registrar1, email: 'not_updated@test.test', - code: 'SH8013' + code: 'FIRST0:SH8013' ) end @@ -296,9 +296,10 @@ describe 'EPP Contact', epp: true do end it 'is succesful' do - response = update_request({ id: { value: 'SH8013' } }) + response = update_request({ id: { value: 'FIRST0:SH8013' } }) response[:msg].should == 'Command completed successfully' + @contact.reload @contact.name.should == 'John Doe Edited' @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 without_password = { - id: { value: 'SH8013' }, + id: { value: 'FIRST0:SH8013' }, chg: { postalInfo: { name: { value: 'John Doe Edited' } @@ -323,7 +324,7 @@ describe 'EPP Contact', epp: true do it 'should update other contact with correct password' 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[:result_code].should == '1000' end @@ -332,7 +333,7 @@ describe 'EPP Contact', epp: true do it 'should not update other contact without password' do login_as :registrar2 do without_password = { - id: { value: 'SH8013' }, + id: { value: 'FIRST0:SH8013' }, chg: { postalInfo: { name: { value: 'John Doe Edited' } @@ -350,7 +351,7 @@ describe 'EPP Contact', epp: true do it 'returns phone and email error' do response = update_request({ - id: { value: 'SH8013' }, + id: { value: 'FIRST0:SH8013' }, chg: { voice: { value: '123213' }, email: { value: 'wrong' } @@ -365,7 +366,7 @@ describe 'EPP Contact', epp: true do it 'should not update code with custom string' do response = update_request( - id: { value: 'SH8013' }, + id: { value: 'FIRST0:SH8013' }, chg: { id: { value: 'notpossibletoupdate' } } @@ -374,7 +375,7 @@ describe 'EPP Contact', epp: true do response[:msg].should == 'Object does not exist' response[:result_code].should == '2303' - @contact.reload.code.should == 'SH8013' + @contact.reload.code.should == 'FIRST0:SH8013' end it 'should update ident' do @@ -388,16 +389,16 @@ describe 'EPP Contact', epp: true do 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[:result_code].should == '1000' - Contact.find_by(code: 'SH8013').ident_type.should == 'birthday' + Contact.find_by(code: 'FIRST0:SH8013').ident_type.should == 'birthday' end it 'should return parameter value policy errror for org update' do response = update_request({ - id: { value: 'SH8013' }, + id: { value: 'FIRST0:SH8013' }, chg: { 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]' 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 it 'should return parameter value policy errror for fax update' do response = update_request({ - id: { value: 'SH8013' }, + id: { value: 'FIRST0:SH8013' }, chg: { 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]' response[:result_code].should == '2306' - Contact.find_by(code: 'SH8013').fax.should == nil + Contact.find_by(code: 'FIRST0:SH8013').fax.should == nil end it 'does not allow to edit statuses if policy forbids it' do Setting.client_status_editing_enabled = false xml = @epp_xml.update({ - id: { value: 'SH8013' }, + id: { value: 'FIRST0:SH8013' }, add: [{ _anonymus: [ { 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 xml = @epp_xml.update({ - id: { value: 'SH8013' }, + id: { value: 'FIRST0:SH8013' }, authInfo: { pw: { value: 'password' } }, add: { 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][:result_code].should == '1000' - contact = Contact.find_by(code: 'SH8013') + contact = Contact.find_by(code: 'FIRST0:SH8013') contact.phone.should == '+372.11111111' 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 xml = @epp_xml.update({ - id: { value: 'SH8013' }, + id: { value: 'FIRST0:SH8013' }, authInfo: { pw: { value: 'password' } }, add: { voice: { value: '' } @@ -478,12 +479,12 @@ describe 'EPP Contact', epp: true do response = epp_plain_request(xml, :xml) response[:results][0][:msg].should == 'Required parameter missing - phone [phone]' 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 it 'should honor chg value over add value when both changes same attribute' do xml = @epp_xml.update({ - id: { value: 'SH8013' }, + id: { value: 'FIRST0:SH8013' }, authInfo: { pw: { value: 'password' } }, chg: { 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][:result_code].should == '1000' - contact = Contact.find_by(code: 'SH8013') + contact = Contact.find_by(code: 'FIRST0:SH8013') contact.phone.should == '+372.2222222222222' 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 xml = @epp_xml.update({ - id: { value: 'SH8013' }, + id: { value: 'FIRST0:SH8013' }, authInfo: { pw: { value: 'password' } }, rem: { 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][:result_code].should == '2003' - contact = Contact.find_by(code: 'SH8013') + contact = Contact.find_by(code: 'FIRST0:SH8013') contact.phone.should == '+372.7654321' end it 'should not allow to remove required attribute' do xml = @epp_xml.update({ - id: { value: 'SH8013' }, + id: { value: 'FIRST0:SH8013' }, authInfo: { pw: { value: 'password' } }, rem: { 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][:result_code].should == '2003' - contact = Contact.find_by(code: 'SH8013') + contact = Contact.find_by(code: 'FIRST0:SH8013') contact.phone.should == '+372.7654321' end it 'should honor add over rem' do xml = @epp_xml.update({ - id: { value: 'SH8013' }, + id: { value: 'FIRST0:SH8013' }, authInfo: { pw: { value: 'password' } }, rem: { 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][:result_code].should == '1000' - contact = Contact.find_by(code: 'SH8013') + contact = Contact.find_by(code: 'FIRST0:SH8013') contact.phone.should == '+372.3333333' 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 xml = @epp_xml.update({ - id: { value: 'SH8013' }, + id: { value: 'FIRST0:SH8013' }, authInfo: { pw: { value: 'password' } }, rem: { 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][:result_code].should == '1000' - contact = Contact.find_by(code: 'SH8013') + contact = Contact.find_by(code: 'FIRST0:SH8013') contact.phone.should == '+372.44444444' 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 xml = @epp_xml.update({ - id: { value: 'SH8013' }, + id: { value: 'FIRST0:SH8013' }, authInfo: { pw: { value: 'password' } }, chg: { 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][:result_code].should == '1000' - contact = Contact.find_by(code: 'SH8013') + contact = Contact.find_by(code: 'FIRST0:SH8013') contact.phone.should == '+372.666666' 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 xml = @epp_xml.update({ - id: { value: 'SH8013' }, + id: { value: 'FIRST0:SH8013' }, authInfo: { pw: { value: 'password' } }, rem: { 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][:result_code].should == '1000' - contact = Contact.find_by(code: 'SH8013') + contact = Contact.find_by(code: 'FIRST0:SH8013') contact.auth_info.should == 'password' end it 'should return general policy error when removing org' do xml = @epp_xml.update({ - id: { value: 'SH8013' }, + id: { value: 'FIRST0:SH8013' }, authInfo: { pw: { value: 'password' } }, rem: { postalInfo: { org: { value: 'not important' } } @@ -640,7 +641,7 @@ describe 'EPP Contact', epp: true do it 'should return error when removing street' do xml = @epp_xml.update({ - id: { value: 'SH8013' }, + id: { value: 'FIRST0:SH8013' }, authInfo: { pw: { value: 'password' } }, rem: { postalInfo: { @@ -774,7 +775,8 @@ describe 'EPP Contact', epp: true do end 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) @@ -785,7 +787,7 @@ describe 'EPP Contact', epp: true do ids[0].attributes['avail'].text.should == '0' 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' end end @@ -852,10 +854,10 @@ describe 'EPP Contact', epp: true do end it 'should honor new contact code format' do - @registrar1_contact = Fabricate(:contact, code: 'REGISTRAR1:TEST:CUSTOM:CODE') - @registrar1_contact.code.should == 'REGISTRAR1:TEST:CUSTOM:CODE' + @registrar1_contact = Fabricate(:contact, code: 'FIXED: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[:result_code].should == '1000' @@ -927,7 +929,7 @@ describe 'EPP Contact', epp: true do - check-1234 + FIXED:CHECK-1234 check-4321 diff --git a/spec/epp/domain_spec.rb b/spec/epp/domain_spec.rb index c7dd22f6a..9aace945f 100644 --- a/spec/epp/domain_spec.rb +++ b/spec/epp/domain_spec.rb @@ -10,10 +10,10 @@ describe 'EPP Domain', epp: true do login_as :registrar1 - Fabricate(:contact, code: 'citizen_1234') - Fabricate(:contact, code: 'sh8013') - Fabricate(:contact, code: 'sh801333') - Fabricate(:contact, code: 'juridical_1234', ident_type: 'bic') + Fabricate(:contact, code: 'FIXED:CITIZEN_1234') + Fabricate(:contact, code: 'FIXED:SH8013') + Fabricate(:contact, code: 'FIXED:SH801333') + Fabricate(:contact, code: 'FIXED:JURIDICAL_1234', ident_type: 'bic') Fabricate(:reserved_domain) @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 response = epp_plain_request(domain_create_xml({ - registrant: { value: 'citizen_1234' }, + registrant: { value: 'FIXED:CITIZEN_1234' }, _anonymus: [ - { contact: { value: 'citizen_1234', attrs: { type: 'admin' } } }, + { contact: { value: 'FIXED:CITIZEN_1234', attrs: { type: 'admin' } } }, { contact: { value: 'sh1111', 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 it 'creates a domain with contacts' do xml = domain_create_xml({ - registrant: { value: 'juridical_1234' }, + registrant: { value: 'FIXED:JURIDICAL_1234' }, _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 tech_contact = Domain.last.tech_contacts.first - tech_contact.code.should == 'juridical_1234' + tech_contact.code.should == 'FIXED:JURIDICAL_1234' end it 'does not create a domain without admin contact' do domain_count = Domain.count domain_contact_count = DomainContact.count xml = domain_create_xml({ - registrant: { value: 'juridical_1234' }, + registrant: { value: 'FIXED:JURIDICAL_1234' }, _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 xml = domain_create_xml({ - registrant: { value: 'juridical_1234' }, + registrant: { value: 'FIXED:JURIDICAL_1234' }, _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 = { name: { value: domain.name }, chg: [ - registrant: { value: 'citizen_1234' } + registrant: { value: 'FIXED:CITIZEN_1234' } ] } @@ -1374,7 +1374,7 @@ describe 'EPP Domain', epp: true do d = Domain.last - d.registrant_code.should == 'citizen_1234' + d.registrant_code.should == 'FIXED:CITIZEN_1234' d.auth_info.should == existing_pw end @@ -1397,7 +1397,7 @@ describe 'EPP Domain', epp: true do ] }, _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: '', attrs: { s: 'clientUpdateProhibited' } } } ] @@ -1426,7 +1426,7 @@ describe 'EPP Domain', epp: true do response[:results][0][:result_code].should == '2303' 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[: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.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 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][: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]' if response[:results][3][:value] == 'clientHold' @@ -1543,7 +1543,7 @@ describe 'EPP Domain', epp: true do ] }, _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: '', attrs: { s: 'clientUpdateProhibited' } } } ] @@ -1588,7 +1588,7 @@ describe 'EPP Domain', epp: true do ] }, _anonymus: [ - { contact: { value: 'citizen_1234', attrs: { type: 'tech' } } }, + { contact: { value: 'FIXED:CITIZEN_1234', attrs: { type: 'tech' } } }, { 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.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 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][: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][:msg].should == 'Status was not found' @@ -1688,7 +1688,7 @@ describe 'EPP Domain', epp: true do xml_params = { name: { value: domain.name }, chg: [ - registrant: { value: 'citizen_1234' } + registrant: { value: 'FIXED:CITIZEN_1234' } ] } diff --git a/spec/fabricators/contact_fabricator.rb b/spec/fabricators/contact_fabricator.rb index 68289d77c..0ce9fbd53 100644 --- a/spec/fabricators/contact_fabricator.rb +++ b/spec/fabricators/contact_fabricator.rb @@ -1,5 +1,5 @@ Fabricator(:contact) do - registrar { Fabricate(:registrar) } + registrar { Registrar.find_by_code('FIXED') } code { sequence(:code) { |i| "SH#{Faker::Number.number(8)}#{i}" } } auth_info 'password' name { sequence(:name) { |i| "#{Faker::Name.name}#{i}" } } diff --git a/spec/models/contact_spec.rb b/spec/models/contact_spec.rb index 4b0ad7473..d0553bc8e 100644 --- a/spec/models/contact_spec.rb +++ b/spec/models/contact_spec.rb @@ -174,6 +174,10 @@ describe Contact do contact.statuses.map(&:value).should == %w(ok) end + it 'should have code' do + @contact.code.should =~ /FIXED:..../ + end + it 'should have linked status when domain is created' do # @admin_domain_contact = Fabricate(:admin_domain_contact) # @domain = Fabricate(:domain, admin_domain_contacts: [@admin_domain_contact]) @@ -211,16 +215,17 @@ describe Contact do context 'with callbacks' do before :all do # Ensure callbacks are not taken out from other specs - Contact.set_callback(:create, :before, :generate_code) Contact.set_callback(:create, :before, :generate_auth_info) end context 'after create' do it 'should not generate a new code when code is present' do - @contact = Fabricate.build(:contact, code: '123asd', auth_info: 'qwe321') - @contact.code.should == '123asd' + @contact = Fabricate.build(:contact, + code: 'FIXED:new-code', + auth_info: 'qwe321') + @contact.code.should == 'FIXED:new-code' # still new record @contact.save.should == true - @contact.code.should == '123asd' + @contact.code.should == 'FIXED:NEW-CODE' end it 'should generate a new password' do @@ -262,15 +267,17 @@ describe Contact do context 'after update' 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.code.should == '123asd' + @contact.code.should == 'FIXED:123ASD' @auth_info = @contact.auth_info end it 'should not generate new code' do @contact.update_attributes(name: 'qevciherot23') - @contact.code.should == '123asd' + @contact.code.should == 'FIXED:123ASD' end it 'should not generate new auth_info' do diff --git a/spec/rails_helper.rb b/spec/rails_helper.rb index eca52cf12..1ef1f9159 100644 --- a/spec/rails_helper.rb +++ b/spec/rails_helper.rb @@ -46,6 +46,10 @@ def create_settings Setting.tech_contacts_max_count = 10 Setting.client_side_status_editing_enabled = true + + @fixed_registrar = + Registrar.find_by_name('fixed registrar') || + Fabricate(:registrar, name: 'fixed registrar', code: 'FIXED') end 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.template = File.read('spec/requests/repp_doc_template.md.erb') end + diff --git a/spec/support/epp.rb b/spec/support/epp.rb index c5d02cccd..052074ca0 100644 --- a/spec/support/epp.rb +++ b/spec/support/epp.rb @@ -150,11 +150,11 @@ module Epp } } ], - registrant: { value: 'citizen_1234' }, + registrant: { value: 'FIXED:CITIZEN_1234' }, _anonymus: [ - { contact: { value: 'sh8013', attrs: { type: 'admin' } } }, - { contact: { value: 'sh8013', attrs: { type: 'tech' } } }, - { contact: { value: 'sh801333', attrs: { type: 'tech' } } } + { contact: { value: 'FIXED:SH8013', attrs: { type: 'admin' } } }, + { contact: { value: 'FIXED:SH8013', 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: [ - { contact: { value: 'sh8013', attrs: { type: 'admin' } } }, - { contact: { value: 'sh8013', attrs: { type: 'tech' } } }, - { contact: { value: 'sh801333', attrs: { type: 'tech' } } } + { contact: { value: 'FIXED:SH8013', attrs: { type: 'admin' } } }, + { contact: { value: 'FIXED:SH8013', 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: [ - { contact: { value: 'sh8013', attrs: { type: 'admin' } } }, - { contact: { value: 'sh8013', attrs: { type: 'tech' } } }, - { contact: { value: 'sh801333', attrs: { type: 'tech' } } } + { contact: { value: 'FIXED:SH8013', attrs: { type: 'admin' } } }, + { contact: { value: 'FIXED:SH8013', attrs: { type: 'tech' } } }, + { contact: { value: 'FIXED:SH801333', attrs: { type: 'tech' } } } ], authInfo: { pw: { @@ -288,11 +288,11 @@ module Epp } } ], - registrant: { value: 'citizen_1234' }, + registrant: { value: 'FIXED:CITIZEN_1234' }, _anonymus: [ - { contact: { value: 'sh8013', attrs: { type: 'admin' } } }, - { contact: { value: 'sh8013', attrs: { type: 'tech' } } }, - { contact: { value: 'sh801333', attrs: { type: 'tech' } } } + { contact: { value: 'FIXED:SH8013', attrs: { type: 'admin' } } }, + { contact: { value: 'FIXED:SH8013', attrs: { type: 'tech' } } }, + { contact: { value: 'FIXED:SH801333', attrs: { type: 'tech' } } } ], authInfo: { pw: {