Allow changing auth info on contact update #2833

This commit is contained in:
Martin Lensment 2015-08-13 14:20:39 +03:00
parent ba5d1b8e4d
commit 2598b4aa2f
5 changed files with 40 additions and 24 deletions

View file

@ -60,7 +60,7 @@ class Epp::ContactsController < EppController
def find_contact
code = params[:parsed_frame].css('id').text.strip.upcase
@contact = Epp::Contact.find_by_epp_code(code)
if @contact.blank?

View file

@ -244,9 +244,9 @@ class Contact < ActiveRecord::Base
@generate_auth_info_disabled = true
end
def auth_info=(pw)
self[:auth_info] = pw if new_record?
end
# def auth_info=(pw)
# self[:auth_info] = pw if new_record?
# end
def code=(code)
self[:code] = code if new_record? # cannot change code later

View file

@ -26,8 +26,8 @@ class Epp::Contact < Contact
f = frame
at = {}.with_indifferent_access
if rem
at[:name] = nil if f.css('postalInfo name').present?
at[:org_name] = nil if f.css('postalInfo org').present?
at[:name] = nil if f.css('postalInfo name').present?
at[:org_name] = nil if f.css('postalInfo org').present?
at[:email] = nil if f.css('email').present?
at[:fax] = nil if f.css('fax').present?
at[:phone] = nil if f.css('voice').present?
@ -37,8 +37,8 @@ class Epp::Contact < Contact
at[:state] = nil if f.css('postalInfo addr sp').present?
at[:country_code] = nil if f.css('postalInfo addr cc').present?
else
at[:name] = f.css('postalInfo name').text if f.css('postalInfo name').present?
at[:org_name] = f.css('postalInfo org').text if f.css('postalInfo org').present?
at[:name] = f.css('postalInfo name').text if f.css('postalInfo name').present?
at[:org_name] = f.css('postalInfo org').text if f.css('postalInfo org').present?
at[:email] = f.css('email').text if f.css('email').present?
at[:fax] = f.css('fax').text if f.css('fax').present?
at[:phone] = f.css('voice').text if f.css('voice').present?
@ -47,12 +47,12 @@ class Epp::Contact < Contact
at[:street] = f.css('postalInfo addr street').text if f.css('postalInfo addr street').present?
at[:state] = f.css('postalInfo addr sp').text if f.css('postalInfo addr sp').present?
at[:country_code] = f.css('postalInfo addr cc').text if f.css('postalInfo addr cc').present?
at[:auth_info] = f.css('authInfo pw').text if f.css('authInfo pw').present?
at[:auth_info] = f.css('authInfo pw').text if f.css('authInfo pw').present?
end
legal_frame = f.css('legalDocument').first
if legal_frame.present?
at[:legal_documents_attributes] = legal_document_attrs(legal_frame)
at[:legal_documents_attributes] = legal_document_attrs(legal_frame)
end
at.merge!(ident_attrs(f.css('ident').first))
at
@ -154,7 +154,7 @@ class Epp::Contact < Contact
at.deep_merge!(self.class.attrs_from(frame.css('add')))
at.deep_merge!(self.class.attrs_from(frame.css('chg')))
legal_frame = frame.css('legalDocument').first
at[:legal_documents_attributes] = self.class.legal_document_attrs(legal_frame)
at[:legal_documents_attributes] = self.class.legal_document_attrs(legal_frame)
self.deliver_emails = true # turn on email delivery for epp
super(at)
end

View file

@ -515,6 +515,22 @@ describe 'EPP Contact', epp: true do
Setting.client_status_editing_enabled = true
end
it 'should update auth info' do
xml = @epp_xml.update({
id: { value: 'FIRST0:SH8013' },
chg: {
authInfo: { pw: { value: 'newpassword' } }
}
})
puts Nokogiri xml
response = epp_plain_request(xml, :xml)
response[:results][0][:msg].should == 'Command completed successfully'
response[:results][0][:result_code].should == '1000'
contact = Contact.find_by(code: 'FIRST0:SH8013')
contact.auth_info.should == 'newpassword'
end
it 'should add value voice value' do
xml = @epp_xml.update({
id: { value: 'FIRST0:SH8013' },

View file

@ -34,7 +34,7 @@ describe Contact do
"City is missing",
"Country code is missing",
"Street is missing",
"Zip is missing"
"Zip is missing"
])
end
@ -78,7 +78,7 @@ describe Contact do
@contact.ident_country_code = 'INVALID'
@contact.valid?
@contact.errors[:ident].should ==
@contact.errors[:ident].should ==
['Ident country code is not valid, should be in ISO_3166-1 alpha 2 format']
end
@ -171,7 +171,7 @@ describe Contact do
it 'should not remove ok status after save' do
@contact.statuses.should == %w(ok)
@contact.save
@contact.save
@contact.statuses.should == %w(ok)
end
@ -296,8 +296,8 @@ describe Contact do
context 'after create' do
it 'should not generate a new code when code is present' do
@contact = Fabricate.build(:contact,
code: 'FIXED:new-code',
@contact = Fabricate.build(:contact,
code: 'FIXED:new-code',
auth_info: 'qwe321')
@contact.code.should == 'FIXED:new-code' # still new record
@contact.save.should == true
@ -305,15 +305,15 @@ describe Contact do
end
it 'should not allaw to use same code' do
@contact = Fabricate.build(:contact,
code: 'FIXED:new-code',
@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 == 'FIXED:NEW-CODE'
@contact = Fabricate.build(:contact,
code: 'FIXED:new-code',
@contact = Fabricate.build(:contact,
code: 'FIXED:new-code',
auth_info: 'qwe321')
@contact.code.should == 'FIXED:new-code' # still new record
@contact.valid?
@ -321,10 +321,10 @@ describe Contact do
end
it 'should generate a new password' do
@contact = Fabricate.build(:contact, code: '123asd', auth_info: 'qwe321')
@contact.auth_info.should == 'qwe321'
@contact = Fabricate.build(:contact, code: '123asd', auth_info: nil)
@contact.auth_info.should == nil
@contact.save.should == true
@contact.auth_info.should_not == 'qwe321'
@contact.auth_info.should_not be_nil
end
it 'should not allow same code' do
@ -359,7 +359,7 @@ describe Contact do
context 'after update' do
before :all do
@contact = Fabricate.build(:contact,
@contact = Fabricate.build(:contact,
code: '123asd',
auth_info: 'qwe321')
@contact.save