From ef632e0ce1b748d28eafe1f06aae0ab55c6dbcd6 Mon Sep 17 00:00:00 2001 From: Martin Lensment Date: Thu, 6 Nov 2014 10:31:38 +0200 Subject: [PATCH] Add messages and bump epp-xml --- Gemfile | 2 +- Gemfile.lock | 4 +- app/models/concerns/.keep | 0 app/models/message.rb | 3 + app/models/registrar.rb | 1 + db/migrate/20141105150721_create_messages.rb | 12 +++ db/schema.rb | 11 ++- spec/epp/domain_spec.rb | 78 ++++++++++---------- spec/models/message_spec.rb | 5 ++ spec/models/registrar_spec.rb | 1 + spec/support/epp.rb | 64 ++++++++++++++++ 11 files changed, 138 insertions(+), 43 deletions(-) delete mode 100644 app/models/concerns/.keep create mode 100644 app/models/message.rb create mode 100644 db/migrate/20141105150721_create_messages.rb create mode 100644 spec/models/message_spec.rb diff --git a/Gemfile b/Gemfile index 14966fc54..0b8ad7ffa 100644 --- a/Gemfile +++ b/Gemfile @@ -85,7 +85,7 @@ group :development, :test do gem 'epp', '~> 1.4.0' # EPP XMLs - gem 'epp-xml', '~> 0.5.0' + gem 'epp-xml', '~> 0.7.0' # Replacement for fixtures gem 'fabrication', '~> 2.11.3' diff --git a/Gemfile.lock b/Gemfile.lock index 29fcbaf66..9921e1367 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -93,7 +93,7 @@ GEM epp (1.4.0) hpricot libxml-ruby - epp-xml (0.5.0) + epp-xml (0.7.0) activesupport (~> 4.1) builder (~> 3.2) equalizer (0.0.9) @@ -362,7 +362,7 @@ DEPENDENCIES database_cleaner (~> 1.3.0) devise (~> 3.3.0) epp (~> 1.4.0) - epp-xml (~> 0.5.0) + epp-xml (~> 0.7.0) fabrication (~> 2.11.3) faker (~> 1.3.0) guard (~> 2.6.1) diff --git a/app/models/concerns/.keep b/app/models/concerns/.keep deleted file mode 100644 index e69de29bb..000000000 diff --git a/app/models/message.rb b/app/models/message.rb new file mode 100644 index 000000000..af4e73270 --- /dev/null +++ b/app/models/message.rb @@ -0,0 +1,3 @@ +class Message < ActiveRecord::Base + belongs_to :registrar +end diff --git a/app/models/registrar.rb b/app/models/registrar.rb index 72398d878..cc2c089a0 100644 --- a/app/models/registrar.rb +++ b/app/models/registrar.rb @@ -4,6 +4,7 @@ class Registrar < ActiveRecord::Base has_many :contacts, dependent: :restrict_with_error has_many :epp_users, dependent: :restrict_with_error has_many :users, dependent: :restrict_with_error + has_many :messages validates :name, :reg_no, :address, :country, presence: true validates :name, :reg_no, uniqueness: true diff --git a/db/migrate/20141105150721_create_messages.rb b/db/migrate/20141105150721_create_messages.rb new file mode 100644 index 000000000..985ce51fd --- /dev/null +++ b/db/migrate/20141105150721_create_messages.rb @@ -0,0 +1,12 @@ +class CreateMessages < ActiveRecord::Migration + def change + create_table :messages do |t| + t.integer :registrar_id + t.string :body + t.string :object_type + t.string :object + + t.timestamps + end + end +end diff --git a/db/schema.rb b/db/schema.rb index 09125780b..856d8ac41 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20141015135742) do +ActiveRecord::Schema.define(version: 20141105150721) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -199,6 +199,15 @@ ActiveRecord::Schema.define(version: 20141015135742) do t.datetime "updated_at" end + create_table "messages", force: true do |t| + t.integer "registrar_id" + t.string "body" + t.string "object_type" + t.string "object" + t.datetime "created_at" + t.datetime "updated_at" + end + create_table "nameserver_versions", force: true do |t| t.string "item_type", null: false t.integer "item_id", null: false diff --git a/spec/epp/domain_spec.rb b/spec/epp/domain_spec.rb index 25b758f50..4a35a5885 100644 --- a/spec/epp/domain_spec.rb +++ b/spec/epp/domain_spec.rb @@ -17,7 +17,7 @@ describe 'EPP Domain', epp: true do it 'returns error if contact does not exists' do Fabricate(:contact, code: 'jd1234') - response = epp_request(EppXml::Domain.create, :xml) + response = epp_request(domain_create_xml, :xml) expect(response[:results][0][:result_code]).to eq('2303') expect(response[:results][0][:msg]).to eq('Contact was not found') @@ -38,7 +38,7 @@ describe 'EPP Domain', epp: true do end it 'can not see other registrar domains' do - response = epp_request(EppXml::Domain.info, :xml, :elkdata) + response = epp_request(domain_info_xml, :xml, :elkdata) expect(response[:result_code]).to eq('2302') expect(response[:msg]).to eq('Domain exists but belongs to other registrar') end @@ -179,7 +179,7 @@ describe 'EPP Domain', epp: true do end it 'creates a domain' do - response = epp_request(EppXml::Domain.create, :xml) + response = epp_request(domain_create_xml, :xml) d = Domain.first expect(response[:result_code]).to eq('1000') @@ -215,7 +215,7 @@ describe 'EPP Domain', epp: true do end it 'creates ria.ee with valid ds record' do - xml = EppXml::Domain.create({ + xml = domain_create_xml({ name: { value: 'ria.ee' } }, { _anonymus: [ @@ -241,7 +241,7 @@ describe 'EPP Domain', epp: true do end it 'validates nameserver ipv4 when in same zone as domain' do - xml = EppXml::Domain.create({ + xml = domain_create_xml({ ns: [ { hostObj: { value: 'ns1.example.ee' } }, { hostObj: { value: 'ns2.example.ee' } } @@ -254,8 +254,8 @@ describe 'EPP Domain', epp: true do end it 'does not create duplicate domain' do - epp_request(EppXml::Domain.create, :xml) - response = epp_request(EppXml::Domain.create, :xml) + epp_request(domain_create_xml, :xml) + response = epp_request(domain_create_xml, :xml) expect(response[:result_code]).to eq('2302') expect(response[:msg]).to eq('Domain name already exists') expect(response[:clTRID]).to eq('ABC-12345') @@ -264,7 +264,7 @@ describe 'EPP Domain', epp: true do it 'does not create reserved domain' do Fabricate(:reserved_domain) - xml = EppXml::Domain.create(name: { value: '1162.ee' }) + xml = domain_create_xml(name: { value: '1162.ee' }) response = epp_request(xml, :xml) expect(response[:result_code]).to eq('2302') @@ -273,7 +273,7 @@ describe 'EPP Domain', epp: true do end it 'does not create domain without contacts and registrant' do - xml = EppXml::Domain.create(contacts: [], registrant: false) + xml = domain_create_xml(contacts: [], registrant: false) response = epp_request(xml, :xml) expect(response[:results][0][:result_code]).to eq('2003') @@ -281,7 +281,7 @@ describe 'EPP Domain', epp: true do end it 'does not create domain without nameservers' do - xml = EppXml::Domain.create(ns: []) + xml = domain_create_xml(ns: []) response = epp_request(xml, :xml) expect(response[:result_code]).to eq('2003') expect(response[:msg]).to eq('Required parameter missing: ns') @@ -290,7 +290,7 @@ describe 'EPP Domain', epp: true do it 'does not create domain with too many nameservers' do nameservers = [] 14.times { |i| nameservers << { hostObj: { value: "ns#{i}.example.net" } } } - xml = EppXml::Domain.create(ns: nameservers) + xml = domain_create_xml(ns: nameservers) response = epp_request(xml, :xml) expect(response[:result_code]).to eq('2004') @@ -298,7 +298,7 @@ describe 'EPP Domain', epp: true do end it 'returns error when invalid nameservers are present' do - xml = EppXml::Domain.create({ + xml = domain_create_xml({ ns: [ { hostObj: { value: 'invalid1-' } }, { hostObj: { value: '-invalid2' } } @@ -332,7 +332,7 @@ describe 'EPP Domain', epp: true do end it 'creates a domain with period in days' do - xml = EppXml::Domain.create(period_value: 365, period_unit: 'd') + xml = domain_create_xml(period_value: 365, period_unit: 'd') response = epp_request(xml, :xml) expect(response[:result_code]).to eq('1000') @@ -341,7 +341,7 @@ describe 'EPP Domain', epp: true do end it 'does not create a domain with invalid period' do - xml = EppXml::Domain.create({ + xml = domain_create_xml({ period: { value: '367', attrs: { unit: 'd' } } }) @@ -352,7 +352,7 @@ describe 'EPP Domain', epp: true do end it 'creates a domain with multiple dnskeys' do - xml = EppXml::Domain.create({}, { + xml = domain_create_xml({}, { _anonymus: [ { keyData: { flags: { value: '257' }, @@ -402,7 +402,7 @@ describe 'EPP Domain', epp: true do it 'does not create a domain when dnskeys are invalid' do - xml = EppXml::Domain.create({}, { + xml = domain_create_xml({}, { _anonymus: [ { keyData: { flags: { value: '250' }, @@ -454,7 +454,7 @@ describe 'EPP Domain', epp: true do end it 'does not create a domain with two identical dnskeys' do - xml = EppXml::Domain.create({}, { + xml = domain_create_xml({}, { _anonymus: [ { keyData: { flags: { value: '257' }, @@ -483,7 +483,7 @@ describe 'EPP Domain', epp: true do it 'validated dnskeys count' do Setting.dnskeys_max_count = 1 - xml = EppXml::Domain.create({}, { + xml = domain_create_xml({}, { _anonymus: [ { keyData: { flags: { value: '257' }, @@ -509,7 +509,7 @@ describe 'EPP Domain', epp: true do end it 'creates domain with ds data' do - xml = EppXml::Domain.create({}, { + xml = domain_create_xml({}, { _anonymus: [ { dsData: { keyTag: { value: '12345' }, @@ -535,7 +535,7 @@ describe 'EPP Domain', epp: true do end it 'creates domain with ds data with key' do - xml = EppXml::Domain.create({}, { + xml = domain_create_xml({}, { _anonymus: [ { dsData: { keyTag: { value: '12345' }, @@ -569,7 +569,7 @@ describe 'EPP Domain', epp: true do it 'prohibits dsData with key' do Setting.ds_data_with_key_allowed = false - xml = EppXml::Domain.create({}, { + xml = domain_create_xml({}, { _anonymus: [ { dsData: { keyTag: { value: '12345' }, @@ -594,7 +594,7 @@ describe 'EPP Domain', epp: true do it 'prohibits dsData' do Setting.ds_data_allowed = false - xml = EppXml::Domain.create({}, { + xml = domain_create_xml({}, { _anonymus: [ { dsData: { keyTag: { value: '12345' }, @@ -619,7 +619,7 @@ describe 'EPP Domain', epp: true do it 'prohibits keyData' do Setting.key_data_allowed = false - xml = EppXml::Domain.create({}, { + xml = domain_create_xml({}, { _anonymus: [ keyData: { flags: { value: '0' }, @@ -643,7 +643,7 @@ describe 'EPP Domain', epp: true do end it 'creates a domain with contacts' do - xml = EppXml::Domain.create({ + xml = domain_create_xml({ _anonymus: [ { contact: { value: 'sh8013', attrs: { type: 'admin' } } } ] @@ -662,7 +662,7 @@ describe 'EPP Domain', epp: true do end it 'does not create a domain without admin contact' do - xml = EppXml::Domain.create({ + xml = domain_create_xml({ _anonymus: [ { contact: { value: 'sh8013', attrs: { type: 'tech' } } } ] @@ -724,7 +724,7 @@ describe 'EPP Domain', epp: true do end it 'sets ok status by default' do - response = epp_request(EppXml::Domain.info, :xml) + response = epp_request(domain_info_xml, :xml) inf_data = response[:parsed].css('resData infData') expect(inf_data.css('status').first[:s]).to eq('ok') end @@ -758,7 +758,7 @@ describe 'EPP Domain', epp: true do d.save - xml = EppXml::Domain.info(name: { value: 'Example.ee' }) + xml = domain_info_xml(name: { value: 'Example.ee' }) response = epp_request(xml, :xml) expect(response[:results][0][:result_code]).to eq('1000') @@ -812,20 +812,20 @@ describe 'EPP Domain', epp: true do d.touch - response = epp_request(EppXml::Domain.info, :xml) + response = epp_request(domain_info_xml, :xml) inf_data = response[:parsed].css('resData infData') expect(inf_data.css('upDate').text).to eq(d.updated_at.to_time.utc.to_s) end it 'returns error when domain can not be found' do - response = epp_request(EppXml::Domain.info(name: { value: 'test.ee' }), :xml) + response = epp_request(domain_info_xml(name: { value: 'test.ee' }), :xml) expect(response[:results][0][:result_code]).to eq('2303') expect(response[:results][0][:msg]).to eq('Domain not found') end it 'updates domain and adds objects', pending: true do - xml = EppXml::Domain.update({ + xml = domain_update_xml({ add: [ { ns: [ @@ -908,7 +908,7 @@ describe 'EPP Domain', epp: true do it 'updates a domain and removes objects' do Fabricate(:contact, code: 'mak21') - xml = EppXml::Domain.update({ + xml = domain_update_xml({ add: [ { ns: [ @@ -946,7 +946,7 @@ describe 'EPP Domain', epp: true do d = Domain.last expect(d.dnskeys.count).to eq(2) - xml = EppXml::Domain.update({ + xml = domain_update_xml({ rem: [ { ns: [ @@ -997,7 +997,7 @@ describe 'EPP Domain', epp: true do it 'does not add duplicate objects to domain' do Fabricate(:contact, code: 'mak21') - xml = EppXml::Domain.update({ + xml = domain_update_xml({ add: [ ns: [ { hostObj: { value: 'ns1.example.com' } } @@ -1023,7 +1023,7 @@ describe 'EPP Domain', epp: true do ] } - response = epp_request(EppXml::Domain.update(xml_params), :xml) + response = epp_request(domain_update_xml(xml_params), :xml) expect(response[:results][0][:result_code]).to eq('1000') d = Domain.last @@ -1033,7 +1033,7 @@ describe 'EPP Domain', epp: true do end it 'does not assign invalid status to domain' do - xml = EppXml::Domain.update({ + xml = domain_update_xml({ add: [ status: { value: '', attrs: { s: 'invalidStatus' } } ] @@ -1064,7 +1064,7 @@ describe 'EPP Domain', epp: true do end it 'checks a domain' do - response = epp_request(EppXml::Domain.check, :xml) + response = epp_request(domain_check_xml, :xml) expect(response[:result_code]).to eq('1000') expect(response[:msg]).to eq('Command completed successfully') @@ -1074,7 +1074,7 @@ describe 'EPP Domain', epp: true do Fabricate(:domain, name: 'example.ee', registrar: zone) - response = epp_request(EppXml::Domain.check, :xml) + response = epp_request(domain_check_xml, :xml) domain = response[:parsed].css('resData chkData cd').first name = domain.css('name').first reason = domain.css('reason').first @@ -1085,7 +1085,7 @@ describe 'EPP Domain', epp: true do end it 'checks multiple domains' do - xml = EppXml::Domain.check({ + xml = domain_check_xml({ _anonymus: [ { name: { value: 'one.ee' } }, { name: { value: 'two.ee' } }, @@ -1107,7 +1107,7 @@ describe 'EPP Domain', epp: true do end it 'checks invalid format domain' do - xml = EppXml::Domain.check({ + xml = domain_check_xml({ _anonymus: [ { name: { value: 'one.ee' } }, { name: { value: 'notcorrectdomain' } } diff --git a/spec/models/message_spec.rb b/spec/models/message_spec.rb new file mode 100644 index 000000000..0ff0e4d92 --- /dev/null +++ b/spec/models/message_spec.rb @@ -0,0 +1,5 @@ +require 'rails_helper' + +describe Message do + it { should belong_to(:registrar) } +end diff --git a/spec/models/registrar_spec.rb b/spec/models/registrar_spec.rb index 196857582..dc7f0922c 100644 --- a/spec/models/registrar_spec.rb +++ b/spec/models/registrar_spec.rb @@ -5,4 +5,5 @@ describe Registrar do it { should have_many(:domains) } it { should have_many(:epp_users) } it { should have_many(:users) } + it { should have_many(:messages) } end diff --git a/spec/support/epp.rb b/spec/support/epp.rb index 8708db24e..3c482d97a 100644 --- a/spec/support/epp.rb +++ b/spec/support/epp.rb @@ -52,6 +52,70 @@ module Epp ### REQUEST TEMPLATES ### + def domain_info_xml(xml_params = {}) + defaults = { + name: { value: 'example.ee', attrs: { hosts: 'all' } }, + authInfo: { + pw: { value: '2fooBAR' } + } + } + + xml_params = defaults.deep_merge(xml_params) + EppXml::Domain.info(xml_params) + end + + def domain_create_xml(xml_params = {}, dnssec_params = {}) + defaults = { + name: { value: 'example.ee' }, + period: { value: '1', attrs: { unit: 'y' } }, + ns: [ + { hostObj: { value: 'ns1.example.net' } }, + { hostObj: { value: 'ns2.example.net' } } + ], + registrant: { value: 'jd1234' }, + _anonymus: [ + { contact: { value: 'sh8013', attrs: { type: 'admin' } } }, + { contact: { value: 'sh8013', attrs: { type: 'tech' } } }, + { contact: { value: 'sh801333', attrs: { type: 'tech' } } } + ] + } + + xml_params = defaults.deep_merge(xml_params) + + dnssec_defaults = { + _anonymus: [ + { keyData: { + flags: { value: '257' }, + protocol: { value: '3' }, + alg: { value: '5' }, + pubKey: { value: 'AwEAAddt2AkLfYGKgiEZB5SmIF8EvrjxNMH6HtxWEA4RJ9Ao6LCWheg8' } + } + }] + } + + dnssec_params = dnssec_defaults.deep_merge(dnssec_params) if dnssec_params != false + EppXml::Domain.create(xml_params, dnssec_params) + end + + def domain_update_xml(xml_params = {}, dnssec_params = false) + defaults = { + name: { value: 'example.ee' } + } + + xml_params = defaults.deep_merge(xml_params) + EppXml::Domain.update(xml_params, dnssec_params) + end + + def domain_check_xml(xml_params = {}) + defaults = { + _anonymus: [ + { name: { value: 'example.ee' } } + ] + } + xml_params = defaults.deep_merge(xml_params) + EppXml::Domain.check(xml_params) + end + def domain_transfer_xml(xml_params = {}, op = 'query') defaults = { name: { value: 'example.ee' },