Add messages and bump epp-xml

This commit is contained in:
Martin Lensment 2014-11-06 10:31:38 +02:00
parent be319509ca
commit ef632e0ce1
11 changed files with 138 additions and 43 deletions

View file

@ -85,7 +85,7 @@ group :development, :test do
gem 'epp', '~> 1.4.0' gem 'epp', '~> 1.4.0'
# EPP XMLs # EPP XMLs
gem 'epp-xml', '~> 0.5.0' gem 'epp-xml', '~> 0.7.0'
# Replacement for fixtures # Replacement for fixtures
gem 'fabrication', '~> 2.11.3' gem 'fabrication', '~> 2.11.3'

View file

@ -93,7 +93,7 @@ GEM
epp (1.4.0) epp (1.4.0)
hpricot hpricot
libxml-ruby libxml-ruby
epp-xml (0.5.0) epp-xml (0.7.0)
activesupport (~> 4.1) activesupport (~> 4.1)
builder (~> 3.2) builder (~> 3.2)
equalizer (0.0.9) equalizer (0.0.9)
@ -362,7 +362,7 @@ DEPENDENCIES
database_cleaner (~> 1.3.0) database_cleaner (~> 1.3.0)
devise (~> 3.3.0) devise (~> 3.3.0)
epp (~> 1.4.0) epp (~> 1.4.0)
epp-xml (~> 0.5.0) epp-xml (~> 0.7.0)
fabrication (~> 2.11.3) fabrication (~> 2.11.3)
faker (~> 1.3.0) faker (~> 1.3.0)
guard (~> 2.6.1) guard (~> 2.6.1)

3
app/models/message.rb Normal file
View file

@ -0,0 +1,3 @@
class Message < ActiveRecord::Base
belongs_to :registrar
end

View file

@ -4,6 +4,7 @@ class Registrar < ActiveRecord::Base
has_many :contacts, dependent: :restrict_with_error has_many :contacts, dependent: :restrict_with_error
has_many :epp_users, dependent: :restrict_with_error has_many :epp_users, dependent: :restrict_with_error
has_many :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, :address, :country, presence: true
validates :name, :reg_no, uniqueness: true validates :name, :reg_no, uniqueness: true

View file

@ -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

View file

@ -11,7 +11,7 @@
# #
# It's strongly recommended that you check this file into your version control system. # 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 # These are extensions that must be enabled in order to support this database
enable_extension "plpgsql" enable_extension "plpgsql"
@ -199,6 +199,15 @@ ActiveRecord::Schema.define(version: 20141015135742) do
t.datetime "updated_at" t.datetime "updated_at"
end 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| create_table "nameserver_versions", force: true do |t|
t.string "item_type", null: false t.string "item_type", null: false
t.integer "item_id", null: false t.integer "item_id", null: false

View file

@ -17,7 +17,7 @@ describe 'EPP Domain', epp: true do
it 'returns error if contact does not exists' do it 'returns error if contact does not exists' do
Fabricate(:contact, code: 'jd1234') 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][:result_code]).to eq('2303')
expect(response[:results][0][:msg]).to eq('Contact was not found') expect(response[:results][0][:msg]).to eq('Contact was not found')
@ -38,7 +38,7 @@ describe 'EPP Domain', epp: true do
end end
it 'can not see other registrar domains' do 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[:result_code]).to eq('2302')
expect(response[:msg]).to eq('Domain exists but belongs to other registrar') expect(response[:msg]).to eq('Domain exists but belongs to other registrar')
end end
@ -179,7 +179,7 @@ describe 'EPP Domain', epp: true do
end end
it 'creates a domain' do it 'creates a domain' do
response = epp_request(EppXml::Domain.create, :xml) response = epp_request(domain_create_xml, :xml)
d = Domain.first d = Domain.first
expect(response[:result_code]).to eq('1000') expect(response[:result_code]).to eq('1000')
@ -215,7 +215,7 @@ describe 'EPP Domain', epp: true do
end end
it 'creates ria.ee with valid ds record' do it 'creates ria.ee with valid ds record' do
xml = EppXml::Domain.create({ xml = domain_create_xml({
name: { value: 'ria.ee' } name: { value: 'ria.ee' }
}, { }, {
_anonymus: [ _anonymus: [
@ -241,7 +241,7 @@ describe 'EPP Domain', epp: true do
end end
it 'validates nameserver ipv4 when in same zone as domain' do it 'validates nameserver ipv4 when in same zone as domain' do
xml = EppXml::Domain.create({ xml = domain_create_xml({
ns: [ ns: [
{ hostObj: { value: 'ns1.example.ee' } }, { hostObj: { value: 'ns1.example.ee' } },
{ hostObj: { value: 'ns2.example.ee' } } { hostObj: { value: 'ns2.example.ee' } }
@ -254,8 +254,8 @@ describe 'EPP Domain', epp: true do
end end
it 'does not create duplicate domain' do it 'does not create duplicate domain' do
epp_request(EppXml::Domain.create, :xml) epp_request(domain_create_xml, :xml)
response = epp_request(EppXml::Domain.create, :xml) response = epp_request(domain_create_xml, :xml)
expect(response[:result_code]).to eq('2302') expect(response[:result_code]).to eq('2302')
expect(response[:msg]).to eq('Domain name already exists') expect(response[:msg]).to eq('Domain name already exists')
expect(response[:clTRID]).to eq('ABC-12345') expect(response[:clTRID]).to eq('ABC-12345')
@ -264,7 +264,7 @@ describe 'EPP Domain', epp: true do
it 'does not create reserved domain' do it 'does not create reserved domain' do
Fabricate(:reserved_domain) Fabricate(:reserved_domain)
xml = EppXml::Domain.create(name: { value: '1162.ee' }) xml = domain_create_xml(name: { value: '1162.ee' })
response = epp_request(xml, :xml) response = epp_request(xml, :xml)
expect(response[:result_code]).to eq('2302') expect(response[:result_code]).to eq('2302')
@ -273,7 +273,7 @@ describe 'EPP Domain', epp: true do
end end
it 'does not create domain without contacts and registrant' do 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) response = epp_request(xml, :xml)
expect(response[:results][0][:result_code]).to eq('2003') expect(response[:results][0][:result_code]).to eq('2003')
@ -281,7 +281,7 @@ describe 'EPP Domain', epp: true do
end end
it 'does not create domain without nameservers' do it 'does not create domain without nameservers' do
xml = EppXml::Domain.create(ns: []) xml = domain_create_xml(ns: [])
response = epp_request(xml, :xml) response = epp_request(xml, :xml)
expect(response[:result_code]).to eq('2003') expect(response[:result_code]).to eq('2003')
expect(response[:msg]).to eq('Required parameter missing: ns') 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 it 'does not create domain with too many nameservers' do
nameservers = [] nameservers = []
14.times { |i| nameservers << { hostObj: { value: "ns#{i}.example.net" } } } 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) response = epp_request(xml, :xml)
expect(response[:result_code]).to eq('2004') expect(response[:result_code]).to eq('2004')
@ -298,7 +298,7 @@ describe 'EPP Domain', epp: true do
end end
it 'returns error when invalid nameservers are present' do it 'returns error when invalid nameservers are present' do
xml = EppXml::Domain.create({ xml = domain_create_xml({
ns: [ ns: [
{ hostObj: { value: 'invalid1-' } }, { hostObj: { value: 'invalid1-' } },
{ hostObj: { value: '-invalid2' } } { hostObj: { value: '-invalid2' } }
@ -332,7 +332,7 @@ describe 'EPP Domain', epp: true do
end end
it 'creates a domain with period in days' do 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) response = epp_request(xml, :xml)
expect(response[:result_code]).to eq('1000') expect(response[:result_code]).to eq('1000')
@ -341,7 +341,7 @@ describe 'EPP Domain', epp: true do
end end
it 'does not create a domain with invalid period' do it 'does not create a domain with invalid period' do
xml = EppXml::Domain.create({ xml = domain_create_xml({
period: { value: '367', attrs: { unit: 'd' } } period: { value: '367', attrs: { unit: 'd' } }
}) })
@ -352,7 +352,7 @@ describe 'EPP Domain', epp: true do
end end
it 'creates a domain with multiple dnskeys' do it 'creates a domain with multiple dnskeys' do
xml = EppXml::Domain.create({}, { xml = domain_create_xml({}, {
_anonymus: [ _anonymus: [
{ keyData: { { keyData: {
flags: { value: '257' }, flags: { value: '257' },
@ -402,7 +402,7 @@ describe 'EPP Domain', epp: true do
it 'does not create a domain when dnskeys are invalid' do it 'does not create a domain when dnskeys are invalid' do
xml = EppXml::Domain.create({}, { xml = domain_create_xml({}, {
_anonymus: [ _anonymus: [
{ keyData: { { keyData: {
flags: { value: '250' }, flags: { value: '250' },
@ -454,7 +454,7 @@ describe 'EPP Domain', epp: true do
end end
it 'does not create a domain with two identical dnskeys' do it 'does not create a domain with two identical dnskeys' do
xml = EppXml::Domain.create({}, { xml = domain_create_xml({}, {
_anonymus: [ _anonymus: [
{ keyData: { { keyData: {
flags: { value: '257' }, flags: { value: '257' },
@ -483,7 +483,7 @@ describe 'EPP Domain', epp: true do
it 'validated dnskeys count' do it 'validated dnskeys count' do
Setting.dnskeys_max_count = 1 Setting.dnskeys_max_count = 1
xml = EppXml::Domain.create({}, { xml = domain_create_xml({}, {
_anonymus: [ _anonymus: [
{ keyData: { { keyData: {
flags: { value: '257' }, flags: { value: '257' },
@ -509,7 +509,7 @@ describe 'EPP Domain', epp: true do
end end
it 'creates domain with ds data' do it 'creates domain with ds data' do
xml = EppXml::Domain.create({}, { xml = domain_create_xml({}, {
_anonymus: [ _anonymus: [
{ dsData: { { dsData: {
keyTag: { value: '12345' }, keyTag: { value: '12345' },
@ -535,7 +535,7 @@ describe 'EPP Domain', epp: true do
end end
it 'creates domain with ds data with key' do it 'creates domain with ds data with key' do
xml = EppXml::Domain.create({}, { xml = domain_create_xml({}, {
_anonymus: [ _anonymus: [
{ dsData: { { dsData: {
keyTag: { value: '12345' }, keyTag: { value: '12345' },
@ -569,7 +569,7 @@ describe 'EPP Domain', epp: true do
it 'prohibits dsData with key' do it 'prohibits dsData with key' do
Setting.ds_data_with_key_allowed = false Setting.ds_data_with_key_allowed = false
xml = EppXml::Domain.create({}, { xml = domain_create_xml({}, {
_anonymus: [ _anonymus: [
{ dsData: { { dsData: {
keyTag: { value: '12345' }, keyTag: { value: '12345' },
@ -594,7 +594,7 @@ describe 'EPP Domain', epp: true do
it 'prohibits dsData' do it 'prohibits dsData' do
Setting.ds_data_allowed = false Setting.ds_data_allowed = false
xml = EppXml::Domain.create({}, { xml = domain_create_xml({}, {
_anonymus: [ _anonymus: [
{ dsData: { { dsData: {
keyTag: { value: '12345' }, keyTag: { value: '12345' },
@ -619,7 +619,7 @@ describe 'EPP Domain', epp: true do
it 'prohibits keyData' do it 'prohibits keyData' do
Setting.key_data_allowed = false Setting.key_data_allowed = false
xml = EppXml::Domain.create({}, { xml = domain_create_xml({}, {
_anonymus: [ _anonymus: [
keyData: { keyData: {
flags: { value: '0' }, flags: { value: '0' },
@ -643,7 +643,7 @@ describe 'EPP Domain', epp: true do
end end
it 'creates a domain with contacts' do it 'creates a domain with contacts' do
xml = EppXml::Domain.create({ xml = domain_create_xml({
_anonymus: [ _anonymus: [
{ contact: { value: 'sh8013', attrs: { type: 'admin' } } } { contact: { value: 'sh8013', attrs: { type: 'admin' } } }
] ]
@ -662,7 +662,7 @@ describe 'EPP Domain', epp: true do
end end
it 'does not create a domain without admin contact' do it 'does not create a domain without admin contact' do
xml = EppXml::Domain.create({ xml = domain_create_xml({
_anonymus: [ _anonymus: [
{ contact: { value: 'sh8013', attrs: { type: 'tech' } } } { contact: { value: 'sh8013', attrs: { type: 'tech' } } }
] ]
@ -724,7 +724,7 @@ describe 'EPP Domain', epp: true do
end end
it 'sets ok status by default' do 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') inf_data = response[:parsed].css('resData infData')
expect(inf_data.css('status').first[:s]).to eq('ok') expect(inf_data.css('status').first[:s]).to eq('ok')
end end
@ -758,7 +758,7 @@ describe 'EPP Domain', epp: true do
d.save d.save
xml = EppXml::Domain.info(name: { value: 'Example.ee' }) xml = domain_info_xml(name: { value: 'Example.ee' })
response = epp_request(xml, :xml) response = epp_request(xml, :xml)
expect(response[:results][0][:result_code]).to eq('1000') expect(response[:results][0][:result_code]).to eq('1000')
@ -812,20 +812,20 @@ describe 'EPP Domain', epp: true do
d.touch d.touch
response = epp_request(EppXml::Domain.info, :xml) response = epp_request(domain_info_xml, :xml)
inf_data = response[:parsed].css('resData infData') inf_data = response[:parsed].css('resData infData')
expect(inf_data.css('upDate').text).to eq(d.updated_at.to_time.utc.to_s) expect(inf_data.css('upDate').text).to eq(d.updated_at.to_time.utc.to_s)
end end
it 'returns error when domain can not be found' do 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][:result_code]).to eq('2303')
expect(response[:results][0][:msg]).to eq('Domain not found') expect(response[:results][0][:msg]).to eq('Domain not found')
end end
it 'updates domain and adds objects', pending: true do it 'updates domain and adds objects', pending: true do
xml = EppXml::Domain.update({ xml = domain_update_xml({
add: [ add: [
{ {
ns: [ ns: [
@ -908,7 +908,7 @@ describe 'EPP Domain', epp: true do
it 'updates a domain and removes objects' do it 'updates a domain and removes objects' do
Fabricate(:contact, code: 'mak21') Fabricate(:contact, code: 'mak21')
xml = EppXml::Domain.update({ xml = domain_update_xml({
add: [ add: [
{ {
ns: [ ns: [
@ -946,7 +946,7 @@ describe 'EPP Domain', epp: true do
d = Domain.last d = Domain.last
expect(d.dnskeys.count).to eq(2) expect(d.dnskeys.count).to eq(2)
xml = EppXml::Domain.update({ xml = domain_update_xml({
rem: [ rem: [
{ {
ns: [ ns: [
@ -997,7 +997,7 @@ describe 'EPP Domain', epp: true do
it 'does not add duplicate objects to domain' do it 'does not add duplicate objects to domain' do
Fabricate(:contact, code: 'mak21') Fabricate(:contact, code: 'mak21')
xml = EppXml::Domain.update({ xml = domain_update_xml({
add: [ add: [
ns: [ ns: [
{ hostObj: { value: 'ns1.example.com' } } { 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') expect(response[:results][0][:result_code]).to eq('1000')
d = Domain.last d = Domain.last
@ -1033,7 +1033,7 @@ describe 'EPP Domain', epp: true do
end end
it 'does not assign invalid status to domain' do it 'does not assign invalid status to domain' do
xml = EppXml::Domain.update({ xml = domain_update_xml({
add: [ add: [
status: { value: '', attrs: { s: 'invalidStatus' } } status: { value: '', attrs: { s: 'invalidStatus' } }
] ]
@ -1064,7 +1064,7 @@ describe 'EPP Domain', epp: true do
end end
it 'checks a domain' do 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[:result_code]).to eq('1000')
expect(response[:msg]).to eq('Command completed successfully') 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) 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 domain = response[:parsed].css('resData chkData cd').first
name = domain.css('name').first name = domain.css('name').first
reason = domain.css('reason').first reason = domain.css('reason').first
@ -1085,7 +1085,7 @@ describe 'EPP Domain', epp: true do
end end
it 'checks multiple domains' do it 'checks multiple domains' do
xml = EppXml::Domain.check({ xml = domain_check_xml({
_anonymus: [ _anonymus: [
{ name: { value: 'one.ee' } }, { name: { value: 'one.ee' } },
{ name: { value: 'two.ee' } }, { name: { value: 'two.ee' } },
@ -1107,7 +1107,7 @@ describe 'EPP Domain', epp: true do
end end
it 'checks invalid format domain' do it 'checks invalid format domain' do
xml = EppXml::Domain.check({ xml = domain_check_xml({
_anonymus: [ _anonymus: [
{ name: { value: 'one.ee' } }, { name: { value: 'one.ee' } },
{ name: { value: 'notcorrectdomain' } } { name: { value: 'notcorrectdomain' } }

View file

@ -0,0 +1,5 @@
require 'rails_helper'
describe Message do
it { should belong_to(:registrar) }
end

View file

@ -5,4 +5,5 @@ describe Registrar do
it { should have_many(:domains) } it { should have_many(:domains) }
it { should have_many(:epp_users) } it { should have_many(:epp_users) }
it { should have_many(:users) } it { should have_many(:users) }
it { should have_many(:messages) }
end end

View file

@ -52,6 +52,70 @@ module Epp
### REQUEST TEMPLATES ### ### 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') def domain_transfer_xml(xml_params = {}, op = 'query')
defaults = { defaults = {
name: { value: 'example.ee' }, name: { value: 'example.ee' },