From 8a1a634f37a2037c6bf786367930212cc0d3904d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andres=20Keskk=C3=BCla?= Date: Thu, 31 Jul 2014 12:45:38 +0300 Subject: [PATCH] Basic info_contact command --- app/helpers/epp/contacts_helper.rb | 16 +++++++-- app/views/epp/contacts/info.xml.builder | 33 +++++++++++++++++++ .../20140731073300_add_org_name_to_contact.rb | 5 +++ db/schema.rb | 1 + spec/epp/contact_spec.rb | 22 +++++++++---- spec/epp/requests/contacts/info.xml | 2 +- spec/fabricators/address_fabricator.rb | 5 +++ spec/fabricators/contact_fabricator.rb | 1 + 8 files changed, 75 insertions(+), 10 deletions(-) create mode 100644 app/views/epp/contacts/info.xml.builder create mode 100644 db/migrate/20140731073300_add_org_name_to_contact.rb create mode 100644 spec/fabricators/address_fabricator.rb diff --git a/app/helpers/epp/contacts_helper.rb b/app/helpers/epp/contacts_helper.rb index 47e1ef291..5cc0fbb3e 100644 --- a/app/helpers/epp/contacts_helper.rb +++ b/app/helpers/epp/contacts_helper.rb @@ -8,7 +8,8 @@ module Epp::ContactsHelper code: ph[:id], phone: ph[:voice], ident: ph[:ident], - email: ph[:email] + email: ph[:email], + org_name: ph[:postalInfo][:org] ) end @contact.name = ph[:postalInfo][:name] @@ -53,8 +54,17 @@ module Epp::ContactsHelper end def info_contact - epp_errors << { code: '2101', msg: 'Unimplemented command' } - render 'epp/error' + #TODO add data missing from contacts/info builder ( marked with 'if false' in said view ) + current_epp_user + ph = params_hash['epp']['command']['info']['info'] + + @contact = Contact.where(code: ph[:id]).first + if @contact + render '/epp/contacts/info' + else + epp_errors << { code: '2303', msg: 'Object does not exist' } + render 'epp/error' + end end private diff --git a/app/views/epp/contacts/info.xml.builder b/app/views/epp/contacts/info.xml.builder new file mode 100644 index 000000000..b42b9bada --- /dev/null +++ b/app/views/epp/contacts/info.xml.builder @@ -0,0 +1,33 @@ +xml.epp_head do + xml.response do + xml.result('code' => '1000') do + xml.msg 'Command completed successfully' + end + + xml.resData do + xml.tag!('contact:chkData', 'xmlns:contact' => 'http://www.nic.cz/xml/epp/contact-1.6', + 'xsi:schemaLocation' => 'http://www.nic.cz/xml/epp/contact-1.6 contact-1.6.xsd') do + xml.tag!('contact:name', @contact.name) + xml.tag!('contact:org', @contact.org_name) + xml.tag!('contact:addr') do + xml.tag!('contact:street', @contact.addresses.first.street) + xml.tag!('contact:street', @contact.addresses.first.city) + end + xml.tag!('contact:voice', @contact.phone) + xml.tag!('contact:fax', @contact.fax) + xml.tag!('contact:email', @contact.email) + xml.tag!('contact:clID', @current_epp_user.username) if @current_epp_user + xml.tag!('contact:crID', '123') if false + xml.tag!('contact:crDate', @contact.created_at) + xml.tag!('contact:upID', '123') if false + xml.tag!('contact:upDate', @contact.updated_at) unless @contact.updated_at == @contact.created_at + xml.tag!('contact:trDate', '123') if false + xml.tag!('contact:authInfo', '123') if false + xml.tag!('contact:disclose', '123') if false + + end + end + + xml << render('/epp/shared/trID') + end +end diff --git a/db/migrate/20140731073300_add_org_name_to_contact.rb b/db/migrate/20140731073300_add_org_name_to_contact.rb new file mode 100644 index 000000000..34e6eca25 --- /dev/null +++ b/db/migrate/20140731073300_add_org_name_to_contact.rb @@ -0,0 +1,5 @@ +class AddOrgNameToContact < ActiveRecord::Migration + def change + add_column :contacts, :org_name, :string + end +end diff --git a/db/schema.rb b/db/schema.rb index c027debbb..b1093033e 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -38,6 +38,7 @@ ActiveRecord::Schema.define(version: 20140731081816) do t.datetime "updated_at" t.string "ident" t.string "ident_type" + t.string "org_name" end create_table "countries", force: true do |t| diff --git a/spec/epp/contact_spec.rb b/spec/epp/contact_spec.rb index 921b0bafd..8eb092057 100644 --- a/spec/epp/contact_spec.rb +++ b/spec/epp/contact_spec.rb @@ -14,6 +14,7 @@ describe 'EPP Contact', epp: true do expect(response[:clTRID]).to eq('ABC-12345') expect(Contact.count).to eq(1) + expect(Contact.first.org_name).to eq('Example Inc.') end it 'updates a contact with same ident' do @@ -56,14 +57,23 @@ describe 'EPP Contact', epp: true do end - #TODO replace after implementing info commad for contact - it 'returns error unimplemented command on info_contact' do - Fabricate(:contact) + it 'returns error when object does not exist' do response = epp_request('contacts/info.xml') - expect(response[:result_code]).to eq('2101') - expect(response[:msg]).to eq('Unimplemented command') + expect(response[:result_code]).to eq('2303') + expect(response[:msg]).to eq('Object does not exist') end - end + it 'returns info about contact' do + contact = Fabricate(:contact, :name => "Johnny Awesome") + Fabricate(:address) + response = epp_request('contacts/info.xml') + contact_res = response[:parsed].css('resData chkData') + + expect(response[:result_code]).to eq('1000') + expect(response[:msg]).to eq('Command completed successfully') + expect(contact_res.css('name').first.text).to eq('Johnny Awesome') + + end + end end diff --git a/spec/epp/requests/contacts/info.xml b/spec/epp/requests/contacts/info.xml index ec655ff99..ec7fc1d2a 100644 --- a/spec/epp/requests/contacts/info.xml +++ b/spec/epp/requests/contacts/info.xml @@ -4,7 +4,7 @@ - sh8013 + sh8913 2fooBAR diff --git a/spec/fabricators/address_fabricator.rb b/spec/fabricators/address_fabricator.rb new file mode 100644 index 000000000..77ab56d34 --- /dev/null +++ b/spec/fabricators/address_fabricator.rb @@ -0,0 +1,5 @@ +Fabricator(:address) do + city Faker::Address.city + street Faker::Address.street_name + zip Faker::Address.zip +end diff --git a/spec/fabricators/contact_fabricator.rb b/spec/fabricators/contact_fabricator.rb index 38b842113..4510a3632 100644 --- a/spec/fabricators/contact_fabricator.rb +++ b/spec/fabricators/contact_fabricator.rb @@ -5,4 +5,5 @@ Fabricator(:contact) do ident '37605030299' code 'sh8913' ident_type 'op' + addresses(count: 2) end