mirror of
https://github.com/internetee/registry.git
synced 2025-05-17 17:59:47 +02:00
Add messages and bump epp-xml
This commit is contained in:
parent
be319509ca
commit
ef632e0ce1
11 changed files with 138 additions and 43 deletions
2
Gemfile
2
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'
|
||||
|
|
|
@ -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)
|
||||
|
|
3
app/models/message.rb
Normal file
3
app/models/message.rb
Normal file
|
@ -0,0 +1,3 @@
|
|||
class Message < ActiveRecord::Base
|
||||
belongs_to :registrar
|
||||
end
|
|
@ -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
|
||||
|
|
12
db/migrate/20141105150721_create_messages.rb
Normal file
12
db/migrate/20141105150721_create_messages.rb
Normal 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
|
11
db/schema.rb
11
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
|
||||
|
|
|
@ -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' } }
|
||||
|
|
5
spec/models/message_spec.rb
Normal file
5
spec/models/message_spec.rb
Normal file
|
@ -0,0 +1,5 @@
|
|||
require 'rails_helper'
|
||||
|
||||
describe Message do
|
||||
it { should belong_to(:registrar) }
|
||||
end
|
|
@ -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
|
||||
|
|
|
@ -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' },
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue