From 58176b3cfa95aff42aefc71d1e1c471227f5360d Mon Sep 17 00:00:00 2001 From: Priit Tark Date: Mon, 9 Mar 2015 16:30:34 +0200 Subject: [PATCH] Ident now in extension section --- app/controllers/epp/contacts_controller.rb | 3 +- app/models/epp/contact.rb | 29 ++++++---- doc/epp/contact.md | 24 ++++----- spec/epp/contact_spec.rb | 61 +++++++++++++++++----- 4 files changed, 81 insertions(+), 36 deletions(-) diff --git a/app/controllers/epp/contacts_controller.rb b/app/controllers/epp/contacts_controller.rb index bb7f89986..85abb8b81 100644 --- a/app/controllers/epp/contacts_controller.rb +++ b/app/controllers/epp/contacts_controller.rb @@ -90,7 +90,7 @@ class Epp::ContactsController < EppController @prefix = 'create > create >' requires( 'postalInfo > name', 'postalInfo > addr > city', - 'postalInfo > addr > cc', 'ident', 'voice', 'email' + 'postalInfo > addr > cc', 'voice', 'email' ) ident = params[:parsed_frame].css('ident') if ident.present? && ident.text != 'birthday' && ident.attr('cc').blank? @@ -100,6 +100,7 @@ class Epp::ContactsController < EppController } end @prefix = nil + requires 'extension > extdata > ident' end def validate_update diff --git a/app/models/epp/contact.rb b/app/models/epp/contact.rb index d9df7f2ae..0f51b02c0 100644 --- a/app/models/epp/contact.rb +++ b/app/models/epp/contact.rb @@ -18,13 +18,6 @@ class Epp::Contact < Contact at[:fax] = f.css('fax').text if f.css('fax').present? at[:phone] = f.css('voice').text if f.css('voice').present? at[:auth_info] = f.css('authInfo pw').text if f.css('authInfo pw').present? - - if f.css('ident').present? && f.css('ident').attr('type').present? - at[:ident] = f.css('ident').text - at[:ident_type] = f.css('ident').attr('type').try(:text) - at[:ident_country_code] = f.css('ident').attr('cc').try(:text) - end - at[:address_attributes] = {}.with_indifferent_access sat = at[:address_attributes] sat[:city] = f.css('postalInfo addr city').text if f.css('postalInfo addr city').present? @@ -38,7 +31,7 @@ class Epp::Contact < Contact if legal_frame.present? at[:legal_documents_attributes] = legal_document_attrs(legal_frame) end - + at.merge!(ident_attrs(f.css('ident').first)) at end # rubocop: enable Metrics/MethodLength @@ -63,10 +56,27 @@ class Epp::Contact < Contact ) end + def ident_attrs(ident_frame) + return {} if ident_frame.blank? + return {} if ident_frame.try('text').blank? + return {} if ident_frame.attr('type').blank? + return {} if ident_frame.attr('cc').blank? + + { + ident: ident_frame.text, + ident_type: ident_frame.attr('type'), + ident_country_code: ident_frame.attr('cc') + } + end + def legal_document_attrs(legal_frame) + return [] if legal_frame.blank? + return [] if legal_frame.try('text').blank? + return [] if legal_frame.attr('type').blank? + [{ body: legal_frame.text, - document_type: legal_frame['type'] + document_type: legal_frame.attr('type') }] end end @@ -93,6 +103,7 @@ class Epp::Contact < Contact return super if frame.blank? at = {}.with_indifferent_access at.deep_merge!(self.class.attrs_from(frame.css('chg'))) + at.merge!(self.class.ident_attrs(frame.css('ident').first)) legal_frame = frame.css('legalDocument').first at[:legal_documents_attributes] = self.class.legal_document_attrs(legal_frame) diff --git a/doc/epp/contact.md b/doc/epp/contact.md index db136c0db..f6b8ed8eb 100644 --- a/doc/epp/contact.md +++ b/doc/epp/contact.md @@ -25,14 +25,14 @@ Contact Mapping protocol short version: 1 Country code, 2 letters uppercase, in ISO_3166-1 alpha 2 1 Phone number in format \+ddd.d+ 1 E-mail - 1 Contact identificator + 1 + 1 Attribute: xmlns:eis="urn:ee:eis:xml:epp:eis-1.0" + 1 Contact identificator Attribute: type="bic/priv/birthday" "bic" # Business registry code "priv" # National idendtification number "birthday" # Birthday date in format in DD-MM-YYYY - 1 - 1 Attribute: xmlns:eis="urn:ee:eis:xml:epp:eis-1.0" - 1 Base64 encoded document + 0-1 Base64 encoded document Attribute: type="pdf/bdoc/ddoc/zip/rar/gz/tar/7z" [EXAMPLE REQUEST AND RESPONSE](/doc/epp-examples.md#epp-contact-with-valid-user-create-command-successfully-creates-a-contact) @@ -56,15 +56,15 @@ Contact Mapping protocol short version: 0-1 Country code, 2 letters uppercase, in ISO_3166-1 alpha 2 0-1 Phone number in format \+ddd.d+ 0-1 E-mail - 0-1 Contact identificator - Attribute: type="bic/priv/birthday" - "bic" # Business registry code - "priv" # National idendtification number - "birthday" # Birthday date in format in DD-MM-YYYY 0-1 Required if registrar is not the owner of the contact. 1 Contact password. Attribute: roid="String" 0-1 0-1 Attribute: xmlns:eis="urn:ee:eis:xml:epp:eis-1.0" + 0-1 Contact identificator + Attribute: type="bic/priv/birthday" + "bic" # Business registry code + "priv" # National idendtification number + "birthday" # Birthday date in format in DD-MM-YYYY 0-1 Base64 encoded document. Attribute: type="pdf/bdoc/ddoc/zip/rar/gz/tar/7z" @@ -80,9 +80,9 @@ Contact Mapping protocol short version: 1 Contact id 0-1 Required if registrar is not the owner of the contact. 1 Contact password. Attribute: roid="String" - 1 - 1 Attribute: xmlns:eis="urn:ee:eis:xml:epp:eis-1.0" - 1 Base64 encoded document. + 0-1 + 0-1 Attribute: xmlns:eis="urn:ee:eis:xml:epp:eis-1.0" + 0-1 Base64 encoded document. Attribute: type="pdf/bdoc/ddoc/zip/rar/gz/tar/7z" 0-1 Client transaction id diff --git a/spec/epp/contact_spec.rb b/spec/epp/contact_spec.rb index ff8b66bdf..a52b547b5 100644 --- a/spec/epp/contact_spec.rb +++ b/spec/epp/contact_spec.rb @@ -15,17 +15,23 @@ describe 'EPP Contact', epp: true do @contact = Fabricate(:contact, registrar: @registrar1) - @legal_document = { + @extension = { legalDocument: { value: 'JVBERi0xLjQKJcOkw7zDtsOfCjIgMCBvYmoKPDwvTGVuZ3RoIDMgMCBSL0Zp==', attrs: { type: 'pdf' } + }, + ident: { + value: '37605030299', + attrs: { type: 'priv', cc: 'EE' } } } end context 'with valid user' do context 'create command' do - def create_request(overwrites = {}) + def create_request(overwrites = {}, extension = {}) + extension = @extension if extension.blank? + defaults = { postalInfo: { name: { value: 'John Doe' }, @@ -36,10 +42,9 @@ describe 'EPP Contact', epp: true do } }, voice: { value: '+372.1234567' }, - email: { value: 'test@example.example' }, - ident: { value: '37605030299', attrs: { type: 'priv', cc: 'EE' } } + email: { value: 'test@example.example' } } - create_xml = @epp_xml.create(defaults.deep_merge(overwrites), @legal_document) + create_xml = @epp_xml.create(defaults.deep_merge(overwrites), extension) epp_plain_request(create_xml, :xml) end @@ -52,11 +57,11 @@ describe 'EPP Contact', epp: true do response[:results][2][:msg].should == 'Required parameter missing: create > create > postalInfo > addr > cc [cc]' response[:results][3][:msg].should == - 'Required parameter missing: create > create > ident [ident]' - response[:results][4][:msg].should == 'Required parameter missing: create > create > voice [voice]' - response[:results][5][:msg].should == + response[:results][4][:msg].should == 'Required parameter missing: create > create > email [email]' + response[:results][5][:msg].should == + 'Required parameter missing: extension > extdata > ident [ident]' response[:results][0][:result_code].should == '2003' response[:results][1][:result_code].should == '2003' @@ -91,9 +96,17 @@ describe 'EPP Contact', epp: true do end it 'successfully saves ident type' do - response = create_request( - { ident: { value: '1990-22-12', attrs: { type: 'birthday' } } } - ) + extension = { + legalDocument: { + value: 'JVBERi0xLjQKJcOkw7zDtsOfCjIgMCBvYmoKPDwvTGVuZ3RoIDMgMCBSL0Zp==', + attrs: { type: 'pdf' } + }, + ident: { + value: '1990-22-12', + attrs: { type: 'birthday', cc: 'US' } + } + } + response = create_request({}, extension) response[:msg].should == 'Command completed successfully' response[:result_code].should == '1000' @@ -147,7 +160,9 @@ describe 'EPP Contact', epp: true do ) end - def update_request(overwrites = {}) + def update_request(overwrites = {}, extension = {}) + extension = @extension if extension.blank? + defaults = { id: { value: 'asd123123er' }, authInfo: { pw: { value: 'password' } }, @@ -165,7 +180,7 @@ describe 'EPP Contact', epp: true do } } } - update_xml = @epp_xml.update(defaults.deep_merge(overwrites), @legal_document) + update_xml = @epp_xml.update(defaults.deep_merge(overwrites), extension) epp_plain_request(update_xml, :xml) end @@ -236,6 +251,24 @@ describe 'EPP Contact', epp: true do @contact.reload.code.should == 'sh8013' end + + it 'should update ident' do + extension = { + legalDocument: { + value: 'JVBERi0xLjQKJcOkw7zDtsOfCjIgMCBvYmoKPDwvTGVuZ3RoIDMgMCBSL0Zp==', + attrs: { type: 'pdf' } + }, + ident: { + value: '1990-22-12', + attrs: { type: 'birthday', cc: 'US' } + } + } + response = update_request({ id: { value: 'sh8013' } }, extension) + response[:msg].should == 'Command completed successfully' + response[:result_code].should == '1000' + + Contact.find_by(code: 'sh8013').ident_type.should == 'birthday' + end end context 'delete command' do @@ -248,7 +281,7 @@ describe 'EPP Contact', epp: true do id: { value: @contact.code }, authInfo: { pw: { value: @contact.auth_info } } } - delete_xml = @epp_xml.delete(defaults.deep_merge(overwrites), @legal_document) + delete_xml = @epp_xml.delete(defaults.deep_merge(overwrites), @extension) epp_plain_request(delete_xml, :xml) end