Refactor epp requests closer to international standard

This commit is contained in:
Martin Lensment 2014-07-03 17:47:53 +03:00
parent 4684b311a2
commit 9def6a7c27
11 changed files with 81 additions and 70 deletions

View file

@ -11,12 +11,8 @@ module Epp::Common
send(params[:command])
end
def parsed_frame
Nokogiri::XML(params[:frame]).remove_namespaces!
end
def get_params_hash(path)
Hash.from_xml(parsed_frame.css(path).to_xml).with_indifferent_access
def params_hash
@params_hash ||= Hash.from_xml(params[:frame]).with_indifferent_access
end
def epp_session
@ -28,13 +24,13 @@ module Epp::Common
end
def validate_request
xsd = Nokogiri::XML::Schema(File.read('doc/schemas/epp-1.0.xsd'))
doc = Nokogiri::XML(params[:frame])
@extValues = xsd.validate(doc)
if @extValues.any?
@code = '2001'
@msg = 'Command syntax error'
render '/epp/error' and return
end
# xsd = Nokogiri::XML::Schema(File.read('doc/schemas/contact-1.0.xsd'))
# doc = Nokogiri::XML(params[:frame])
# @extValues = xsd.validate(doc)
# if @extValues.any?
# @code = '2001'
# @msg = 'Command syntax error'
# render '/epp/error' and return
# end
end
end

View file

@ -4,20 +4,16 @@ class Epp::CommandsController < ApplicationController
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/contact-1.6 contact-1.6.xsd' => 'contact'
'urn:ietf:params:xml:ns:contact-1.0' => 'contact',
'urn:ietf:params:xml:ns:domain-1.0' => 'domain'
}
private
def create
ph = get_params_hash('create create')[:create]
type = OBJECT_TYPES[ph[:schemaLocation]]
send("create_#{type}")
send("create_#{OBJECT_TYPES[params_hash['epp']['xmlns:ns2']]}")
end
def check
ph = get_params_hash('check check')[:check]
type = OBJECT_TYPES[ph[:schemaLocation]]
send("check_#{type}")
send("check_#{OBJECT_TYPES[params_hash['epp']['xmlns:ns2']]}")
end
end

View file

@ -27,7 +27,7 @@ class Epp::SessionsController < ApplicationController
### HELPER METHODS ###
def login_params
ph = get_params_hash('epp command login')[:login]
ph = params_hash['epp']['command']['login']
{ username: ph[:clID], password: ph[:pw] }
end
end

View file

@ -1,6 +1,6 @@
module Epp::ContactsHelper
def create_contact
ph = get_params_hash('epp command create create')[:create]
ph = params_hash
@contact = Contact.new(
code: ph[:id],

View file

@ -5,7 +5,7 @@ module Epp::DomainsHelper
end
def check_domain
ph = get_params_hash('epp command check check')[:check]
ph = params_hash['epp']['command']['check']['check']
@domains = Domain.check_availability(ph[:name])
render '/epp/domains/check'
end
@ -13,7 +13,7 @@ module Epp::DomainsHelper
### HELPER METHODS ###
def domain_create_params
ph = get_params_hash('epp command create create')[:create]
ph = params_hash['epp']['command']['create']['create']
{
name: ph[:name],
@ -21,7 +21,7 @@ module Epp::DomainsHelper
registered_at: Time.now,
valid_from: Date.today,
valid_to: Date.today + ph[:period].to_i.years,
auth_info: ph[:authInfo]
auth_info: ph[:authInfo][:pw]
}
end
end

View file

@ -1,7 +1,7 @@
require 'rails_helper'
describe 'EPP Domain', epp: true do
let(:server) { server = Epp::Server.new({server: 'localhost', tag: 'test', password: 'test', port: 701}) }
let(:server) { server = Epp::Server.new({server: 'localhost', tag: 'gitlab', password: 'ghyt9e4fu', port: 701}) }
context 'with valid user' do
before(:each) { Fabricate(:epp_user) }
@ -11,28 +11,27 @@ describe 'EPP Domain', epp: true do
response = epp_request('domains/create.xml')
expect(response[:result_code]).to eq('1000')
expect(response[:msg]).to eq('Command completed successfully')
expect(response[:clTRID]).to eq('dpbx005#10-01-29at19:21:47')
expect(response[:clTRID]).to eq('ABC-12345')
expect(Domain.first.registrar.name).to eq('Zone Media OÜ')
end
# incomplete
it 'checks a domain' do
response = epp_request('domains/check.xml')
expect(response[:result_code]).to eq('1000')
expect(response[:msg]).to eq('Command completed successfully')
domain = response[:parsed].css('resData chkData cd name').first
expect(domain.text).to eq('test.ee')
expect(domain.text).to eq('one.ee')
expect(domain[:avail]).to eq('1')
Fabricate(:domain, name: 'test.ee')
Fabricate(:domain, name: 'one.ee')
response = epp_request('domains/check.xml')
domain = response[:parsed].css('resData chkData cd').first
name = domain.css('name').first
reason = domain.css('reason').first
expect(name.text).to eq('test.ee')
expect(name.text).to eq('one.ee')
expect(name[:avail]).to eq('0')
expect(reason.text).to eq('in use') #confirm this with current API
end
@ -43,11 +42,11 @@ describe 'EPP Domain', epp: true do
expect(response[:msg]).to eq('Command completed successfully')
domain = response[:parsed].css('resData chkData cd name').first
expect(domain.text).to eq('test.ee')
expect(domain.text).to eq('one.ee')
expect(domain[:avail]).to eq('1')
domain = response[:parsed].css('resData chkData cd name').last
expect(domain.text).to eq('bla.ee')
expect(domain.text).to eq('three.ee')
expect(domain[:avail]).to eq('1')
end
@ -57,14 +56,14 @@ describe 'EPP Domain', epp: true do
expect(response[:msg]).to eq('Command completed successfully')
domain = response[:parsed].css('resData chkData cd name').first
expect(domain.text).to eq('test.ee')
expect(domain.text).to eq('one.ee')
expect(domain[:avail]).to eq('1')
domain = response[:parsed].css('resData chkData cd').last
name = domain.css('name').first
reason = domain.css('reason').first
expect(name.text).to eq('asdasd')
expect(name.text).to eq('notcorrectdomain')
expect(name[:avail]).to eq('0')
expect(reason.text).to eq('invalid format')
end

View file

@ -1,6 +1,12 @@
<?xml version="1.0" encoding="utf-8" standalone="no"?><epp xmlns="urn:ietf:params:xml:ns:epp-1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="urn:ietf:params:xml:ns:epp-1.0 epp-1.0.xsd"><command><check><domain:check xmlns:domain="http://www.nic.cz/xml/epp/domain-1.4" xsi:schemaLocation="http://www.nic.cz/xml/epp/domain-1.4 domain-1.4.xsd"><domain:name>test.ee</domain:name>
</domain:check>
</check>
<clTRID>imkt004#14-06-27at16:13:33</clTRID>
</command>
<?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>one.ee</domain:name>
</domain:check>
</check>
<clTRID>ABC-12345</clTRID>
</command>
</epp>

View file

@ -1,7 +1,14 @@
<?xml version="1.0" encoding="utf-8" standalone="no"?><epp xmlns="urn:ietf:params:xml:ns:epp-1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="urn:ietf:params:xml:ns:epp-1.0 epp-1.0.xsd"><command><check><domain:check xmlns:domain="http://www.nic.cz/xml/epp/domain-1.4" xsi:schemaLocation="http://www.nic.cz/xml/epp/domain-1.4 domain-1.4.xsd"><domain:name>test.ee</domain:name>
<domain:name>bla.ee</domain:name>
</domain:check>
</check>
<clTRID>naug002#14-06-30at10:45:27</clTRID>
</command>
<?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>one.ee</domain:name>
<domain:name>two.ee</domain:name>
<domain:name>three.ee</domain:name>
</domain:check>
</check>
<clTRID>ABC-12345</clTRID>
</command>
</epp>

View file

@ -1,8 +1,13 @@
<?xml version="1.0" encoding="utf-8" standalone="no"?><epp xmlns="urn:ietf:params:xml:ns:epp-1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="urn:ietf:params:xml:ns:epp-1.0 epp-1.0.xsd"><command><check><domain:check xmlns:domain="http://www.nic.cz/xml/epp/domain-1.4" xsi:schemaLocation="http://www.nic.cz/xml/epp/domain-1.4 domain-1.4.xsd"><domain:name>test.ee</domain:name>
<domain:name>bla.ee</domain:name>
<domain:name>asdasd</domain:name>
</domain:check>
</check>
<clTRID>ixsz002#14-06-30at11:43:32</clTRID>
</command>
<?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>one.ee</domain:name>
<domain:name>notcorrectdomain</domain:name>
</domain:check>
</check>
<clTRID>ABC-12345</clTRID>
</command>
</epp>

View file

@ -1,21 +1,23 @@
<?xml version="1.0" encoding="utf-8" standalone="no"?>
<epp xmlns="urn:ietf:params:xml:ns:epp-1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="urn:ietf:params:xml:ns:epp-1.0 epp-1.0.xsd">
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<epp xmlns="urn:ietf:params:xml:ns:epp-1.0">
<command>
<create>
<domain:create xmlns:domain="http://www.nic.cz/xml/epp/domain-1.4" xsi:schemaLocation="http://www.nic.cz/xml/epp/domain-1.4 domain-1.4.xsd">
<domain:name>testing.ee</domain:name>
<domain:create
xmlns:domain="urn:ietf:params:xml:ns:domain-1.0">
<domain:name>example.ee</domain:name>
<domain:period unit="y">1</domain:period>
<domain:nsset>name_server_set1</domain:nsset>
<domain:registrant>domain_registrator1</domain:registrant>
<domain:admin>administrative_contact1</domain:admin>
<domain:authInfo>password</domain:authInfo>
<domain:ns>
<domain:hostObj>ns1.example.net</domain:hostObj>
<domain:hostObj>ns2.example.net</domain:hostObj>
</domain:ns>
<domain:registrant>jd1234</domain:registrant>
<domain:contact type="admin">sh8013</domain:contact>
<domain:contact type="tech">sh8013</domain:contact>
<domain:authInfo>
<domain:pw>2fooBAR</domain:pw>
</domain:authInfo>
</domain:create>
</create>
<extension>
<eis:extdata xmlns:eis="urn:ee:eis:xml:epp:eis-1.0" xsi:schemaLocation="urn:ee:eis:xml:epp:eis-1.0 eis-1.0.xsd">
<eis:legalDocument type="ddoc">.... base64 encoded document ....</eis:legalDocument>
</eis:extdata>
</extension>
<clTRID>dpbx005#10-01-29at19:21:47</clTRID>
<clTRID>ABC-12345</clTRID>
</command>
</epp>

View file

@ -1,7 +1,7 @@
require 'rails_helper'
describe 'EPP Session', epp: true do
let(:server) { server = Epp::Server.new({server: 'localhost', tag: 'test', password: 'test', port: 701}) }
let(:server) { server = Epp::Server.new({server: 'localhost', tag: 'gitlab', password: 'ghyt9e4fu', port: 701}) }
context 'when not connected' do
it 'greets client upon connection' do