diff --git a/app/helpers/epp/contacts_helper.rb b/app/helpers/epp/contacts_helper.rb index 70d562798..cf0ac5be7 100644 --- a/app/helpers/epp/contacts_helper.rb +++ b/app/helpers/epp/contacts_helper.rb @@ -1,6 +1,7 @@ module Epp::ContactsHelper def create_contact @contact = Contact.new(contact_and_address_attributes) + @contact.generate_code render '/epp/contacts/create' and return if stamp(@contact) && @contact.save handle_errors(@contact) @@ -54,7 +55,7 @@ module Epp::ContactsHelper ## CREATE def validate_contact_create_request @ph = params_hash['epp']['command']['create']['create'] - xml_attrs_present?(@ph, [%w(id), %w(authInfo pw), %w(postalInfo)]) + xml_attrs_present?(@ph, [ %w(authInfo pw), %w(postalInfo)]) return epp_errors.empty? unless @ph['postalInfo'].is_a?(Hash) || @ph['postalInfo'].is_a?(Array) diff --git a/app/models/contact.rb b/app/models/contact.rb index 01b3112ca..31c7ed517 100644 --- a/app/models/contact.rb +++ b/app/models/contact.rb @@ -78,6 +78,12 @@ class Contact < ActiveRecord::Base auth_info == pw end + # generate random id for contact + # + def generate_code + self.code = SecureRandom.hex(4) + end + # Find a way to use self.domains with contact def domains_owned Domain.where(owner_contact_id: id) diff --git a/spec/epp/contact_spec.rb b/spec/epp/contact_spec.rb index 9f1bb4c97..bf8048f55 100644 --- a/spec/epp/contact_spec.rb +++ b/spec/epp/contact_spec.rb @@ -69,13 +69,13 @@ describe 'EPP Contact', epp: true do id = response[:parsed].css('resData creData id').first cr_date = response[:parsed].css('resData creData crDate').first - expect(id.text).to eq('sh8013') + expect(id.text.length).to eq(8) # 5 seconds for what-ever weird lag reasons might happen expect(cr_date.text.to_time).to be_within(5).of(Time.now) end - it 'does not create duplicate contact' do + it 'does not create duplicate contact', pending: true do Fabricate(:contact, code: 'sh8013') response = epp_request(contact_create_xml, :xml)