diff --git a/app/controllers/concerns/epp/common.rb b/app/controllers/concerns/epp/common.rb index 1a1394822..0ab5a5dcb 100644 --- a/app/controllers/concerns/epp/common.rb +++ b/app/controllers/concerns/epp/common.rb @@ -14,6 +14,22 @@ module Epp::Common Nokogiri::XML(params[:frame]).remove_namespaces! end + def get_params_hash(path) + node_set = parsed_frame.css(path).children.select{ |x| x.element? && x.element_children.empty? } + + node_set.inject({}) do |hash, obj| + #convert to array if 1 or more attributes with same name + if hash[obj.name.to_sym] && !hash[obj.name.to_sym].is_a?(Array) + hash[obj.name.to_sym] = [hash[obj.name.to_sym]] + hash[obj.name.to_sym] << obj.text.strip + else + hash[obj.name.to_sym] = obj.text.strip + end + + hash + end + end + def epp_session EppSession.find_or_initialize_by(session_id: cookies['session']) end diff --git a/app/controllers/epp/commands_controller.rb b/app/controllers/epp/commands_controller.rb index 1d3152cdd..398a5aa65 100644 --- a/app/controllers/epp/commands_controller.rb +++ b/app/controllers/epp/commands_controller.rb @@ -1,9 +1,11 @@ class Epp::CommandsController < ApplicationController include Epp::Common include Epp::DomainsHelper + include Epp::ContactsHelper OBJECT_TYPES = { - 'http://www.nic.cz/xml/epp/domain-1.4 domain-1.4.xsd' => 'domain' + 'http://www.nic.cz/xml/epp/domain-1.4 domain-1.4.xsd' => 'domain', + 'http://www.nic.cz/xml/epp/contact-1.6 contact-1.6.xsd' => 'contact' } private diff --git a/app/helpers/epp/contacts_helper.rb b/app/helpers/epp/contacts_helper.rb new file mode 100644 index 000000000..ba2880531 --- /dev/null +++ b/app/helpers/epp/contacts_helper.rb @@ -0,0 +1,13 @@ +module Epp::ContactsHelper + def create_contact + ccp = contact_create_params + end + + ### HELPER METHODS ### + + def contact_create_params + { + addr: get_params_hash('epp command create create postalInfo addr') + } + end +end diff --git a/app/views/epp/contacts/create.xml.builder b/app/views/epp/contacts/create.xml.builder new file mode 100644 index 000000000..cd65bfbca --- /dev/null +++ b/app/views/epp/contacts/create.xml.builder @@ -0,0 +1,16 @@ +xml.epp_head do + xml.response do + xml.result('code' => '1000') do + xml.msg 'Command completed successfully' + end + + xml.resData do + xml.tag!('contact:creData', '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:id', @id) + xml.tag!('contact:crDate', @crDate) + end + end + + xml << render('/epp/shared/trID') + end +end diff --git a/spec/epp/contact_spec.rb b/spec/epp/contact_spec.rb new file mode 100644 index 000000000..4208f8e1e --- /dev/null +++ b/spec/epp/contact_spec.rb @@ -0,0 +1,18 @@ +require 'rails_helper' + +describe 'EPP Contact', epp: true do + let(:server) { Epp::Server.new({server: 'localhost', tag: 'test', password: 'test', port: 701}) } + + context 'with valid user' do + before(:each) { Fabricate(:epp_user) } + + # incomplete + it 'creates a contact' do + response = epp_request('contacts/create.xml') + expect(response[:result_code]).to eq('1000') + expect(response[:msg]).to eq('Command completed successfully') + expect(response[:clTRID]).to eq('ABC-12345') + end + + end +end diff --git a/spec/epp/requests/contacts/create.xml b/spec/epp/requests/contacts/create.xml new file mode 100644 index 000000000..8dd05d831 --- /dev/null +++ b/spec/epp/requests/contacts/create.xml @@ -0,0 +1,34 @@ + + + + + + sh8013 + + John Doe + Example Inc. + + 123 Example Dr. + Suite 100 + Dulles + VA + 20166-6503 + US + + + +1.7035555555 + +1.7035555556 + jdoe@example.com + + 2fooBAR + + + + + + + + ABC-12345 + +