Merge branch 'master' of github.com:internetee/registry

This commit is contained in:
Andres Keskküla 2014-11-03 15:34:26 +02:00
commit c685b6f4b2
12 changed files with 82 additions and 362 deletions

View file

@ -89,7 +89,7 @@ group :development, :test do
gem 'epp', '~> 1.4.0' gem 'epp', '~> 1.4.0'
# EPP XMLs # EPP XMLs
gem 'epp-xml', git: 'git@github.com:gitlabeu/epp-xml.git' # TODO: get this from rubygems gem 'epp-xml', '~> 0.3.0'
# Replacement for fixtures # Replacement for fixtures
gem 'fabrication', '~> 2.11.3' gem 'fabrication', '~> 2.11.3'

View file

@ -1,11 +1,3 @@
GIT
remote: git@github.com:gitlabeu/epp-xml.git
revision: bd353d79764ba10ce189add76dfd2f4672649175
specs:
epp-xml (0.0.1)
activesupport (~> 4.1, >= 4.1.4)
builder (~> 3.2, >= 3.2.2)
GEM GEM
remote: https://rubygems.org/ remote: https://rubygems.org/
specs: specs:
@ -101,6 +93,9 @@ GEM
epp (1.4.0) epp (1.4.0)
hpricot hpricot
libxml-ruby libxml-ruby
epp-xml (0.3.0)
activesupport (~> 4.1)
builder (~> 3.2)
equalizer (0.0.9) equalizer (0.0.9)
erubis (2.7.0) erubis (2.7.0)
execjs (2.2.1) execjs (2.2.1)
@ -370,7 +365,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! epp-xml (~> 0.3.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)

View file

@ -51,10 +51,10 @@ module Epp::DomainsHelper
handle_errors(@domain) and return unless @domain handle_errors(@domain) and return unless @domain
@domain.parse_and_attach_domain_dependencies(parsed_frame.css('add'))
@domain.parse_and_attach_ds_data(parsed_frame.css('extension add'))
@domain.parse_and_detach_domain_dependencies(parsed_frame.css('rem')) @domain.parse_and_detach_domain_dependencies(parsed_frame.css('rem'))
@domain.parse_and_detach_ds_data(parsed_frame.css('extension rem')) @domain.parse_and_detach_ds_data(parsed_frame.css('extension rem'))
@domain.parse_and_attach_domain_dependencies(parsed_frame.css('add'))
@domain.parse_and_attach_ds_data(parsed_frame.css('extension add'))
@domain.parse_and_update_domain_dependencies(parsed_frame.css('chg')) @domain.parse_and_update_domain_dependencies(parsed_frame.css('chg'))
if @domain.errors.any? if @domain.errors.any?
@ -112,11 +112,14 @@ module Epp::DomainsHelper
end end
def domain_create_params def domain_create_params
name = parsed_frame.css('name').text
period = parsed_frame.css('period').text
{ {
name: @ph[:name], name: name,
registrar_id: current_epp_user.registrar.try(:id), registrar_id: current_epp_user.registrar.try(:id),
registered_at: Time.now, registered_at: Time.now,
period: (@ph[:period].to_i == 0) ? 1 : @ph[:period].to_i, period: (period.to_i == 0) ? 1 : period.to_i,
period_unit: Epp::EppDomain.parse_period_unit_from_frame(parsed_frame) || 'y' period_unit: Epp::EppDomain.parse_period_unit_from_frame(parsed_frame) || 'y'
} }
end end
@ -167,13 +170,14 @@ module Epp::DomainsHelper
## SHARED ## SHARED
def find_domain(secure = { secure: true }) def find_domain(secure = { secure: true })
domain = Epp::EppDomain.find_by(name: @ph[:name].strip.downcase) domain_name = parsed_frame.css('name').text.strip.downcase
domain = Epp::EppDomain.find_by(name: domain_name)
unless domain unless domain
epp_errors << { epp_errors << {
code: '2303', code: '2303',
msg: I18n.t('errors.messages.epp_domain_not_found'), msg: I18n.t('errors.messages.epp_domain_not_found'),
value: { obj: 'name', val: @ph[:name].strip.downcase } value: { obj: 'name', val: domain_name }
} }
return nil return nil
end end

View file

@ -39,6 +39,9 @@ class Epp::EppDomain < Domain
} }
] ]
], ],
'2005' => [
[:name_dirty, :invalid, { obj: 'name', val: name_dirty }]
],
'2201' => [ '2201' => [
[:auth_info, :wrong_pw] [:auth_info, :wrong_pw]
] ]
@ -168,7 +171,6 @@ class Epp::EppDomain < Domain
to_delete << nameserver to_delete << nameserver
end end
end end
nameservers.delete(to_delete) nameservers.delete(to_delete)
end end
@ -236,7 +238,6 @@ class Epp::EppDomain < Domain
def detach_dnskeys(dnssec_data) def detach_dnskeys(dnssec_data)
return false unless validate_dnssec_data(dnssec_data) return false unless validate_dnssec_data(dnssec_data)
to_delete = [] to_delete = []
dnssec_data[:ds_data].each do |x| dnssec_data[:ds_data].each do |x|
ds = dnskeys.where(ds_key_tag: x[:ds_key_tag]) ds = dnskeys.where(ds_key_tag: x[:ds_key_tag])
@ -247,7 +248,6 @@ class Epp::EppDomain < Domain
end end
end end
to_delete = []
dnssec_data[:key_data].each do |x| dnssec_data[:key_data].each do |x|
ds = dnskeys.where(public_key: x[:public_key]) ds = dnskeys.where(public_key: x[:public_key])
if ds.blank? if ds.blank?
@ -389,11 +389,13 @@ class Epp::EppDomain < Domain
def parse_nameservers_from_frame(parsed_frame) def parse_nameservers_from_frame(parsed_frame)
res = [] res = []
parsed_frame.css('hostAttr').each do |x| parsed_frame.css('hostAttr').each do |x|
res << { host_attr = {
hostname: x.css('hostName').first.try(:text), hostname: x.css('hostName').first.try(:text),
ipv4: x.css('hostAddr[ip="v4"]').first.try(:text), ipv4: x.css('hostAddr[ip="v4"]').first.try(:text),
ipv6: x.css('hostAddr[ip="v6"]').first.try(:text) ipv6: x.css('hostAddr[ip="v6"]').first.try(:text)
} }
res << host_attr.delete_if { |_k, v| v.blank? }
end end
parsed_frame.css('hostObj').each do |x| parsed_frame.css('hostObj').each do |x|

View file

@ -2,7 +2,7 @@
begin begin
load File.expand_path('../spring', __FILE__) load File.expand_path('../spring', __FILE__)
rescue LoadError rescue LoadError
puts 'no spring' 'no spring'
end end
APP_PATH = File.expand_path('../../config/application', __FILE__) APP_PATH = File.expand_path('../../config/application', __FILE__)
require_relative '../config/boot' require_relative '../config/boot'

View file

@ -2,7 +2,7 @@
begin begin
load File.expand_path('../spring', __FILE__) load File.expand_path('../spring', __FILE__)
rescue LoadError rescue LoadError
puts 'no spring' 'no spring'
end end
require_relative '../config/boot' require_relative '../config/boot'
require 'rake' require 'rake'

View file

@ -27,7 +27,7 @@ RAILS_ENV=test bundle exec rake db:seed
RAILS_ENV=test bundle exec rake assets:precompile RAILS_ENV=test bundle exec rake assets:precompile
echo "GIT_LAST_COMMITS" echo "GIT_LAST_COMMITS"
git log origin/master -n 10 --pretty=oneline | sed -r '/^.{40} Merge branch/d' | sed -r 's/^.{40}/Latest: /' git log --pretty='%s (%cn, %cr)' --abbrev-commit --graph --decorate -n 20 --no-color
echo "END_OF_GIT_LAST_COMMITS" echo "END_OF_GIT_LAST_COMMITS"
echo "RUBOCOP_RESULTS" echo "RUBOCOP_RESULTS"

View file

@ -10,46 +10,46 @@ Country.where(name: 'Estonia', iso: 'EE').first_or_create!
Country.where(name: 'Latvia', iso: 'LV').first_or_create! Country.where(name: 'Latvia', iso: 'LV').first_or_create!
zone = Registrar.where( zone = Registrar.where(
name: 'Zone Media OÜ', name: 'Registrar First AS',
reg_no: '10577829', reg_no: '10300220',
address: 'Lõõtsa 2, Tallinna linn, Harju maakond, 11415', address: 'Pärnu mnt 2, Tallinna linn, Harju maakond, 11415',
country: Country.first country: Country.first
).first_or_create ).first_or_create
EppUser.where( EppUser.where(
username: 'zone', username: 'registrar1',
password: 'ghyt9e4fu', password: 'test1',
active: true, active: true,
registrar: zone registrar: zone
).first_or_create ).first_or_create
elkdata = Registrar.where( elkdata = Registrar.where(
name: 'Elkdata OÜ', name: 'Registrar Second AS',
reg_no: '10510593', reg_no: '10529229',
address: 'Tondi 51-10, 11316 Tallinn', address: 'Vabaduse pst 32, 11316 Tallinn',
country: Country.first country: Country.first
).first_or_create ).first_or_create
EppUser.where( EppUser.where(
username: 'elkdata', username: 'registrar2',
password: '8932iods', password: 'test2',
active: true, active: true,
registrar: elkdata registrar: elkdata
).first_or_create ).first_or_create
User.where( User.where(
username: 'gitlab', username: 'user1',
password: '12345', password: 'test1',
email: 'enquiries@gitlab.eu', email: 'user1@example.ee',
admin: true, admin: true,
identity_code: '37810013855', identity_code: '37810013855',
country: Country.where(name: 'Estonia').first country: Country.where(name: 'Estonia').first
).first_or_create ).first_or_create
User.where( User.where(
username: 'zone', username: 'user2',
password: '54321', password: 'test2',
email: 'info-info@zone.ee', email: 'user2@example.ee',
admin: false, admin: false,
identity_code: '37810010085', identity_code: '37810010085',
registrar_id: zone.id, registrar_id: zone.id,
@ -57,9 +57,9 @@ User.where(
).first_or_create ).first_or_create
User.where( User.where(
username: 'elkdata', username: 'user3',
password: '32154', password: 'test3',
email: 'info-info@elkdata.ee', email: 'user3@example.ee',
admin: false, admin: false,
identity_code: '37810010727', identity_code: '37810010727',
registrar_id: elkdata.id, registrar_id: elkdata.id,

View file

@ -217,7 +217,7 @@ describe 'EPP Domain', epp: true do
xml = EppXml::Domain.create({ xml = EppXml::Domain.create({
name: { value: 'ria.ee' } name: { value: 'ria.ee' }
}, { }, {
_other: [ _anonymus: [
{ keyData: { { keyData: {
flags: { value: '257' }, flags: { value: '257' },
protocol: { value: '3' }, protocol: { value: '3' },
@ -352,7 +352,7 @@ describe 'EPP Domain', epp: true do
it 'creates a domain with multiple dnskeys' do it 'creates a domain with multiple dnskeys' do
xml = EppXml::Domain.create({}, { xml = EppXml::Domain.create({}, {
_other: [ _anonymus: [
{ keyData: { { keyData: {
flags: { value: '257' }, flags: { value: '257' },
protocol: { value: '3' }, protocol: { value: '3' },
@ -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 = EppXml::Domain.create({}, {
_other: [ _anonymus: [
{ keyData: { { keyData: {
flags: { value: '250' }, flags: { value: '250' },
protocol: { value: '4' }, protocol: { value: '4' },
@ -454,7 +454,7 @@ describe 'EPP Domain', epp: true do
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 = EppXml::Domain.create({}, {
_other: [ _anonymus: [
{ keyData: { { keyData: {
flags: { value: '257' }, flags: { value: '257' },
protocol: { value: '3' }, protocol: { value: '3' },
@ -483,7 +483,7 @@ describe 'EPP Domain', epp: true do
Setting.dnskeys_max_count = 1 Setting.dnskeys_max_count = 1
xml = EppXml::Domain.create({}, { xml = EppXml::Domain.create({}, {
_other: [ _anonymus: [
{ keyData: { { keyData: {
flags: { value: '257' }, flags: { value: '257' },
protocol: { value: '3' }, protocol: { value: '3' },
@ -509,7 +509,7 @@ describe 'EPP Domain', epp: true do
it 'creates domain with ds data' do it 'creates domain with ds data' do
xml = EppXml::Domain.create({}, { xml = EppXml::Domain.create({}, {
_other: [ _anonymus: [
{ dsData: { { dsData: {
keyTag: { value: '12345' }, keyTag: { value: '12345' },
alg: { value: '3' }, alg: { value: '3' },
@ -535,7 +535,7 @@ describe 'EPP Domain', epp: true do
it 'creates domain with ds data with key' do it 'creates domain with ds data with key' do
xml = EppXml::Domain.create({}, { xml = EppXml::Domain.create({}, {
_other: [ _anonymus: [
{ dsData: { { dsData: {
keyTag: { value: '12345' }, keyTag: { value: '12345' },
alg: { value: '3' }, alg: { value: '3' },
@ -569,7 +569,7 @@ describe 'EPP Domain', epp: true do
Setting.ds_data_with_key_allowed = false Setting.ds_data_with_key_allowed = false
xml = EppXml::Domain.create({}, { xml = EppXml::Domain.create({}, {
_other: [ _anonymus: [
{ dsData: { { dsData: {
keyTag: { value: '12345' }, keyTag: { value: '12345' },
alg: { value: '3' }, alg: { value: '3' },
@ -594,7 +594,7 @@ describe 'EPP Domain', epp: true do
Setting.ds_data_allowed = false Setting.ds_data_allowed = false
xml = EppXml::Domain.create({}, { xml = EppXml::Domain.create({}, {
_other: [ _anonymus: [
{ dsData: { { dsData: {
keyTag: { value: '12345' }, keyTag: { value: '12345' },
alg: { value: '3' }, alg: { value: '3' },
@ -619,7 +619,7 @@ describe 'EPP Domain', epp: true do
Setting.key_data_allowed = false Setting.key_data_allowed = false
xml = EppXml::Domain.create({}, { xml = EppXml::Domain.create({}, {
_other: [ _anonymus: [
keyData: { keyData: {
flags: { value: '0' }, flags: { value: '0' },
protocol: { value: '3' }, protocol: { value: '3' },
@ -643,7 +643,7 @@ describe 'EPP Domain', epp: true do
it 'creates a domain with contacts' do it 'creates a domain with contacts' do
xml = EppXml::Domain.create({ xml = EppXml::Domain.create({
_other: [ _anonymus: [
{ contact: { value: 'sh8013', attrs: { type: 'admin' } } } { contact: { value: 'sh8013', attrs: { type: 'admin' } } }
] ]
}) })
@ -662,7 +662,7 @@ describe 'EPP Domain', epp: true do
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 = EppXml::Domain.create({
_other: [ _anonymus: [
{ contact: { value: 'sh8013', attrs: { type: 'tech' } } } { contact: { value: 'sh8013', attrs: { type: 'tech' } } }
] ]
}) })
@ -810,7 +810,7 @@ describe 'EPP Domain', epp: true do
end end
it 'updates domain and adds objects', pending: true do it 'updates domain and adds objects', pending: true do
xml = domain_update_xml({ xml = EppXml::Domain.update({
add: [ add: [
{ {
ns: [ ns: [
@ -818,7 +818,7 @@ describe 'EPP Domain', epp: true do
{ hostObj: { value: 'ns2.example.com' } } { hostObj: { value: 'ns2.example.com' } }
] ]
}, },
_other: [ _anonymus: [
{ contact: { value: 'mak21', attrs: { type: 'tech' } } }, { contact: { value: 'mak21', attrs: { type: 'tech' } } },
{ status: { value: 'Payment overdue.', attrs: { s: 'clientHold', lang: 'en' } } }, { status: { value: 'Payment overdue.', attrs: { s: 'clientHold', lang: 'en' } } },
{ status: { value: '', attrs: { s: 'clientUpdateProhibited' } } } { status: { value: '', attrs: { s: 'clientUpdateProhibited' } } }
@ -893,7 +893,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 = domain_update_xml({ xml = EppXml::Domain.update({
add: [ add: [
{ {
ns: [ ns: [
@ -901,7 +901,7 @@ describe 'EPP Domain', epp: true do
{ hostObj: { value: 'ns2.example.com' } } { hostObj: { value: 'ns2.example.com' } }
] ]
}, },
_other: [ _anonymus: [
{ contact: { value: 'mak21', attrs: { type: 'tech' } } }, { contact: { value: 'mak21', attrs: { type: 'tech' } } },
{ status: { value: 'Payment overdue.', attrs: { s: 'clientHold', lang: 'en' } } }, { status: { value: 'Payment overdue.', attrs: { s: 'clientHold', lang: 'en' } } },
{ status: { value: '', attrs: { s: 'clientUpdateProhibited' } } } { status: { value: '', attrs: { s: 'clientUpdateProhibited' } } }
@ -931,14 +931,14 @@ 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 = domain_update_xml({ xml = EppXml::Domain.update({
rem: [ rem: [
{ {
ns: [ ns: [
{ hostObj: { value: 'ns1.example.com' } } { hostObj: { value: 'ns1.example.com' } }
] ]
}, },
_other: [ _anonymus: [
{ contact: { value: 'mak21', attrs: { type: 'tech' } } }, { contact: { value: 'mak21', attrs: { type: 'tech' } } },
{ status: { value: '', attrs: { s: 'clientHold' } } } { status: { value: '', attrs: { s: 'clientHold' } } }
] ]
@ -982,7 +982,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 = domain_update_xml({ xml = EppXml::Domain.update({
add: [ add: [
ns: [ ns: [
{ hostObj: { value: 'ns1.example.com' } } { hostObj: { value: 'ns1.example.com' } }
@ -1008,7 +1008,7 @@ describe 'EPP Domain', epp: true do
] ]
} }
response = epp_request(domain_update_xml(xml_params), :xml) response = epp_request(EppXml::Domain.update(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
@ -1018,7 +1018,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 = domain_update_xml({ xml = EppXml::Domain.update({
add: [ add: [
status: { value: '', attrs: { s: 'invalidStatus' } } status: { value: '', attrs: { s: 'invalidStatus' } }
] ]
@ -1032,7 +1032,7 @@ describe 'EPP Domain', epp: true do
it 'deletes domain' do it 'deletes domain' do
expect(DomainContact.count).to eq(2) expect(DomainContact.count).to eq(2)
response = epp_request(domain_delete_xml, :xml) response = epp_request(EppXml::Domain.delete(name: { value: 'example.ee' }), :xml)
expect(response[:result_code]).to eq('1000') expect(response[:result_code]).to eq('1000')
expect(Domain.first).to eq(nil) expect(Domain.first).to eq(nil)
@ -1042,14 +1042,14 @@ describe 'EPP Domain', epp: true do
it 'does not delete domain with specific status' do it 'does not delete domain with specific status' do
d = Domain.first d = Domain.first
d.domain_statuses.create(value: DomainStatus::CLIENT_DELETE_PROHIBITED) d.domain_statuses.create(value: DomainStatus::CLIENT_DELETE_PROHIBITED)
response = epp_request(domain_delete_xml, :xml) response = epp_request(EppXml::Domain.delete(name: { value: 'example.ee' }), :xml)
expect(response[:result_code]).to eq('2304') expect(response[:result_code]).to eq('2304')
expect(response[:msg]).to eq('Domain status prohibits operation') expect(response[:msg]).to eq('Domain status prohibits operation')
end end
end end
it 'checks a domain' do it 'checks a domain' do
response = epp_request(domain_check_xml, :xml) response = epp_request(EppXml::Domain.check, :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')
@ -1059,7 +1059,7 @@ describe 'EPP Domain', epp: true do
Fabricate(:domain, name: 'example.ee', registrar: zone) Fabricate(:domain, name: 'example.ee', registrar: zone)
response = epp_request(domain_check_xml, :xml) response = epp_request(EppXml::Domain.check, :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
@ -1070,7 +1070,13 @@ describe 'EPP Domain', epp: true do
end end
it 'checks multiple domains' do it 'checks multiple domains' do
xml = domain_check_xml(names: ['one.ee', 'two.ee', 'three.ee']) xml = EppXml::Domain.check({
_anonymus: [
{ name: { value: 'one.ee' } },
{ name: { value: 'two.ee' } },
{ name: { value: 'three.ee' } }
]
})
response = epp_request(xml, :xml) response = epp_request(xml, :xml)
expect(response[:result_code]).to eq('1000') expect(response[:result_code]).to eq('1000')
@ -1086,7 +1092,12 @@ describe 'EPP Domain', epp: true do
end end
it 'checks invalid format domain' do it 'checks invalid format domain' do
xml = domain_check_xml(names: ['one.ee', 'notcorrectdomain']) xml = EppXml::Domain.check({
_anonymus: [
{ name: { value: 'one.ee' } },
{ name: { value: 'notcorrectdomain' } }
]
})
response = epp_request(xml, :xml) response = epp_request(xml, :xml)
expect(response[:result_code]).to eq('1000') expect(response[:result_code]).to eq('1000')

View file

@ -2,44 +2,6 @@ require 'rails_helper'
describe 'EPP Helper', epp: true do describe 'EPP Helper', epp: true do
context 'in context of Domain' do context 'in context of Domain' do
it 'generates valid check xml' do
expected = Nokogiri::XML('<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<epp xmlns="urn:ietf:params:xml:ns:epp-1.0">
<command>
<check>
<domain:check
xmlns:domain="urn:ietf:params:xml:ns:domain-1.0">
<domain:name>example.ee</domain:name>
</domain:check>
</check>
<clTRID>ABC-12345</clTRID>
</command>
</epp>
').to_s.squish
generated = Nokogiri::XML(domain_check_xml).to_s.squish
expect(generated).to eq(expected)
expected = Nokogiri::XML('<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<epp xmlns="urn:ietf:params:xml:ns:epp-1.0">
<command>
<check>
<domain:check
xmlns:domain="urn:ietf:params:xml:ns:domain-1.0">
<domain:name>example.ee</domain:name>
<domain:name>example2.ee</domain:name>
<domain:name>example3.ee</domain:name>
</domain:check>
</check>
<clTRID>ABC-12345</clTRID>
</command>
</epp>
').to_s.squish
generated = Nokogiri::XML(domain_check_xml(names: ['example.ee', 'example2.ee', 'example3.ee'])).to_s.squish
expect(generated).to eq(expected)
end
it 'generates valid renew xml' do it 'generates valid renew xml' do
expected = Nokogiri::XML('<?xml version="1.0" encoding="UTF-8" standalone="no"?> expected = Nokogiri::XML('<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<epp xmlns="urn:ietf:params:xml:ns:epp-1.0"> <epp xmlns="urn:ietf:params:xml:ns:epp-1.0">
@ -81,158 +43,6 @@ describe 'EPP Helper', epp: true do
expect(generated).to eq(expected) expect(generated).to eq(expected)
end end
it 'generates valid update xml' do
# Detailed update
expected = Nokogiri::XML('<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<epp xmlns="urn:ietf:params:xml:ns:epp-1.0">
<command>
<update>
<domain:update
xmlns:domain="urn:ietf:params:xml:ns:domain-1.0">
<domain:name>example.ee</domain:name>
<domain:add>
<domain:ns>
<domain:hostObj>ns2.example.com</domain:hostObj>
</domain:ns>
<domain:contact type="tech">mak21</domain:contact>
<domain:status s="clientUpdateProhibited"/>
<domain:status s="clientHold"
lang="en">Payment overdue.</domain:status>
</domain:add>
<domain:rem>
<domain:ns>
<domain:hostObj>ns1.example.com</domain:hostObj>
</domain:ns>
<domain:contact type="tech">sh8013</domain:contact>
<domain:status s="clientUpdateProhibited"></domain:status>
</domain:rem>
<domain:chg>
<domain:registrant>mak21</domain:registrant>
</domain:chg>
</domain:update>
</update>
<clTRID>ABC-12345</clTRID>
</command>
</epp>
').to_s.squish
xml = domain_update_xml(
name: { value: 'example.ee' },
add: [
{ ns:
[
hostObj: { value: 'ns1.example.com' },
hostObj: { value: 'ns2.example.com' }
]
},
{ contact: { attrs: { type: 'tech' }, value: 'mak21' } },
{ status: { attrs: { s: 'clientUpdateProhibited' }, value: '' } },
{ status: { attrs: { s: 'clientHold', lang: 'en' }, value: 'Payment overdue.' } }
],
rem: [
ns: [
hostObj: { value: 'ns1.example.com' }
],
contact: { attrs: { type: 'tech' }, value: 'sh8013' },
status: { attrs: { s: 'clientUpdateProhibited' }, value: '' }
],
chg: [
registrant: { value: 'mak21' }
]
)
generated = Nokogiri::XML(xml).to_s.squish
expect(generated).to eq(expected)
# Update with NS IP-s
expected = Nokogiri::XML('<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<epp xmlns="urn:ietf:params:xml:ns:epp-1.0">
<command>
<update>
<domain:update
xmlns:domain="urn:ietf:params:xml:ns:domain-1.0">
<domain:name>one.ee</domain:name>
<domain:add>
<domain:contact type="admin">sh8013</domain:contact>
<domain:status s="testStatus"
lang="et">Payment overdue.</domain:status>
</domain:add>
<domain:rem>
<domain:ns>
<domain:hostAttr>
<domain:hostName>ns1.example.net</domain:hostName>
<domain:hostAddr ip="v4">192.0.2.2</domain:hostAddr>
<domain:hostAddr ip="v6">1080:0:0:0:8:800:200C:417A</domain:hostAddr>
</domain:hostAttr>
</domain:ns>
<domain:contact type="tech">sh8013</domain:contact>
<domain:status s="clientUpdateProhibited"></domain:status>
</domain:rem>
<domain:chg>
<domain:registrant>sh8013</domain:registrant>
</domain:chg>
</domain:update>
</update>
<clTRID>ABC-12345</clTRID>
</command>
</epp>
').to_s.squish
xml = domain_update_xml(
name: { value: 'one.ee' },
add: [
ns: nil,
contact: { value: 'sh8013', attrs: { type: 'admin' } },
status: { value: 'Payment overdue.', attrs: { s: 'testStatus', lang: 'et' } }
],
rem: [
ns: [
hostAttr: [
{ hostName: { value: 'ns1.example.net' } },
{ hostAddr: { value: '192.0.2.2', attrs: { ip: 'v4' } } },
{ hostAddr: { value: '1080:0:0:0:8:800:200C:417A', attrs: { ip: 'v6' } } }
]
],
contact: { attrs: { type: 'tech' }, value: 'sh8013' },
status: { attrs: { s: 'clientUpdateProhibited' }, value: '' }
],
chg: [
registrant: { value: 'sh8013' }
]
)
generated = Nokogiri::XML(xml).to_s.squish
expect(generated).to eq(expected)
## Update with chg
expected = Nokogiri::XML('<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<epp xmlns="urn:ietf:params:xml:ns:epp-1.0">
<command>
<update>
<domain:update
xmlns:domain="urn:ietf:params:xml:ns:domain-1.0">
<domain:name>example.ee</domain:name>
<domain:chg>
<domain:registrant>mak21</domain:registrant>
</domain:chg>
</domain:update>
</update>
<clTRID>ABC-12345</clTRID>
</command>
</epp>
').to_s.squish
xml = domain_update_xml(
chg: [
registrant: { value: 'mak21' }
]
)
generated = Nokogiri::XML(xml).to_s.squish
expect(generated).to eq(expected)
end
it 'generates valid transfer xml' do it 'generates valid transfer xml' do
expected = Nokogiri::XML('<?xml version="1.0" encoding="UTF-8" standalone="no"?> expected = Nokogiri::XML('<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<epp xmlns="urn:ietf:params:xml:ns:epp-1.0"> <epp xmlns="urn:ietf:params:xml:ns:epp-1.0">
@ -276,41 +86,5 @@ describe 'EPP Helper', epp: true do
generated = Nokogiri::XML(xml).to_s.squish generated = Nokogiri::XML(xml).to_s.squish
expect(generated).to eq(expected) expect(generated).to eq(expected)
end end
it 'generates valid delete xml' do
expected = Nokogiri::XML('<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<epp xmlns="urn:ietf:params:xml:ns:epp-1.0">
<command>
<delete>
<domain:delete
xmlns:domain="urn:ietf:params:xml:ns:domain-1.0">
<domain:name>example.ee</domain:name>
</domain:delete>
</delete>
<clTRID>ABC-12345</clTRID>
</command>
</epp>
').to_s.squish
generated = Nokogiri::XML(domain_delete_xml).to_s.squish
expect(generated).to eq(expected)
expected = Nokogiri::XML('<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<epp xmlns="urn:ietf:params:xml:ns:epp-1.0">
<command>
<delete>
<domain:delete
xmlns:domain="urn:ietf:params:xml:ns:domain-1.0">
<domain:name>one.ee</domain:name>
</domain:delete>
</delete>
<clTRID>ABC-12345</clTRID>
</command>
</epp>
').to_s.squish
generated = Nokogiri::XML(domain_delete_xml(name: 'one.ee')).to_s.squish
expect(generated).to eq(expected)
end
end end
end end

View file

@ -14,7 +14,7 @@ describe Domain do
create_settings create_settings
end end
it 'validates domain name' do it 'validates domain name', skip: true do
d = Fabricate(:domain) d = Fabricate(:domain)
expect(d.name).to_not be_nil expect(d.name).to_not be_nil

View file

@ -73,53 +73,6 @@ module Epp
end end
end end
def domain_check_xml(xml_params = {})
xml_params[:names] = xml_params[:names] || ['example.ee']
xml = Builder::XmlMarkup.new
xml.instruct!(:xml, standalone: 'no')
xml.epp('xmlns' => 'urn:ietf:params:xml:ns:epp-1.0') do
xml.command do
xml.check do
xml.tag!('domain:check', 'xmlns:domain' => 'urn:ietf:params:xml:ns:domain-1.0') do
xml_params[:names].each do |x|
xml.tag!('domain:name', (x || 'example.ee'))
end if xml_params[:names].any?
end
end
xml.clTRID 'ABC-12345'
end
end
end
def domain_update_xml(xml_params = {}, dnssec_params = false)
defaults = {
name: { value: 'example.ee' }
}
xml_params = defaults.deep_merge(xml_params)
xml = Builder::XmlMarkup.new
xml.instruct!(:xml, standalone: 'no')
xml.epp('xmlns' => 'urn:ietf:params:xml:ns:epp-1.0') do
xml.command do
xml.update do
xml.tag!('domain:update', 'xmlns:domain' => 'urn:ietf:params:xml:ns:domain-1.0') do
generate_xml_from_hash(xml_params, xml, 'domain:')
end
end
xml.extension do
xml.tag!('secDNS:create', 'xmlns:secDNS' => 'urn:ietf:params:xml:ns:secDNS-1.1') do
generate_xml_from_hash(dnssec_params, xml, 'secDNS:')
end
end if dnssec_params != false
xml.clTRID 'ABC-12345'
end
end
end
def generate_xml_from_hash(xml_params, xml, ns = '') def generate_xml_from_hash(xml_params, xml, ns = '')
xml_params.each do |k, v| xml_params.each do |k, v|
# Value is a hash which has string type value # Value is a hash which has string type value
@ -174,25 +127,6 @@ module Epp
end end
end end
end end
def domain_delete_xml(xml_params = {})
xml_params[:name] = xml_params[:name] || 'example.ee'
xml = Builder::XmlMarkup.new
xml.instruct!(:xml, standalone: 'no')
xml.epp('xmlns' => 'urn:ietf:params:xml:ns:epp-1.0') do
xml.command do
xml.delete do
xml.tag!('domain:delete', 'xmlns:domain' => 'urn:ietf:params:xml:ns:domain-1.0') do
if xml_params[:name] != false
xml.tag!('domain:name', xml_params[:name])
end
end
end
xml.clTRID 'ABC-12345'
end
end
end
end end
RSpec.configure do |c| RSpec.configure do |c|