mirror of
https://github.com/internetee/registry.git
synced 2025-05-17 17:59:47 +02:00
Refactor epp requests closer to international standard
This commit is contained in:
parent
4684b311a2
commit
9def6a7c27
11 changed files with 81 additions and 70 deletions
|
@ -11,12 +11,8 @@ module Epp::Common
|
||||||
send(params[:command])
|
send(params[:command])
|
||||||
end
|
end
|
||||||
|
|
||||||
def parsed_frame
|
def params_hash
|
||||||
Nokogiri::XML(params[:frame]).remove_namespaces!
|
@params_hash ||= Hash.from_xml(params[:frame]).with_indifferent_access
|
||||||
end
|
|
||||||
|
|
||||||
def get_params_hash(path)
|
|
||||||
Hash.from_xml(parsed_frame.css(path).to_xml).with_indifferent_access
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def epp_session
|
def epp_session
|
||||||
|
@ -28,13 +24,13 @@ module Epp::Common
|
||||||
end
|
end
|
||||||
|
|
||||||
def validate_request
|
def validate_request
|
||||||
xsd = Nokogiri::XML::Schema(File.read('doc/schemas/epp-1.0.xsd'))
|
# xsd = Nokogiri::XML::Schema(File.read('doc/schemas/contact-1.0.xsd'))
|
||||||
doc = Nokogiri::XML(params[:frame])
|
# doc = Nokogiri::XML(params[:frame])
|
||||||
@extValues = xsd.validate(doc)
|
# @extValues = xsd.validate(doc)
|
||||||
if @extValues.any?
|
# if @extValues.any?
|
||||||
@code = '2001'
|
# @code = '2001'
|
||||||
@msg = 'Command syntax error'
|
# @msg = 'Command syntax error'
|
||||||
render '/epp/error' and return
|
# render '/epp/error' and return
|
||||||
end
|
# end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -4,20 +4,16 @@ class Epp::CommandsController < ApplicationController
|
||||||
include Epp::ContactsHelper
|
include Epp::ContactsHelper
|
||||||
|
|
||||||
OBJECT_TYPES = {
|
OBJECT_TYPES = {
|
||||||
'http://www.nic.cz/xml/epp/domain-1.4 domain-1.4.xsd' => 'domain',
|
'urn:ietf:params:xml:ns:contact-1.0' => 'contact',
|
||||||
'http://www.nic.cz/xml/epp/contact-1.6 contact-1.6.xsd' => 'contact'
|
'urn:ietf:params:xml:ns:domain-1.0' => 'domain'
|
||||||
}
|
}
|
||||||
|
|
||||||
private
|
private
|
||||||
def create
|
def create
|
||||||
ph = get_params_hash('create create')[:create]
|
send("create_#{OBJECT_TYPES[params_hash['epp']['xmlns:ns2']]}")
|
||||||
type = OBJECT_TYPES[ph[:schemaLocation]]
|
|
||||||
send("create_#{type}")
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def check
|
def check
|
||||||
ph = get_params_hash('check check')[:check]
|
send("check_#{OBJECT_TYPES[params_hash['epp']['xmlns:ns2']]}")
|
||||||
type = OBJECT_TYPES[ph[:schemaLocation]]
|
|
||||||
send("check_#{type}")
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -27,7 +27,7 @@ class Epp::SessionsController < ApplicationController
|
||||||
### HELPER METHODS ###
|
### HELPER METHODS ###
|
||||||
|
|
||||||
def login_params
|
def login_params
|
||||||
ph = get_params_hash('epp command login')[:login]
|
ph = params_hash['epp']['command']['login']
|
||||||
{ username: ph[:clID], password: ph[:pw] }
|
{ username: ph[:clID], password: ph[:pw] }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
module Epp::ContactsHelper
|
module Epp::ContactsHelper
|
||||||
def create_contact
|
def create_contact
|
||||||
ph = get_params_hash('epp command create create')[:create]
|
ph = params_hash
|
||||||
|
|
||||||
@contact = Contact.new(
|
@contact = Contact.new(
|
||||||
code: ph[:id],
|
code: ph[:id],
|
||||||
|
|
|
@ -5,7 +5,7 @@ module Epp::DomainsHelper
|
||||||
end
|
end
|
||||||
|
|
||||||
def check_domain
|
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])
|
@domains = Domain.check_availability(ph[:name])
|
||||||
render '/epp/domains/check'
|
render '/epp/domains/check'
|
||||||
end
|
end
|
||||||
|
@ -13,7 +13,7 @@ module Epp::DomainsHelper
|
||||||
### HELPER METHODS ###
|
### HELPER METHODS ###
|
||||||
|
|
||||||
def domain_create_params
|
def domain_create_params
|
||||||
ph = get_params_hash('epp command create create')[:create]
|
ph = params_hash['epp']['command']['create']['create']
|
||||||
|
|
||||||
{
|
{
|
||||||
name: ph[:name],
|
name: ph[:name],
|
||||||
|
@ -21,7 +21,7 @@ module Epp::DomainsHelper
|
||||||
registered_at: Time.now,
|
registered_at: Time.now,
|
||||||
valid_from: Date.today,
|
valid_from: Date.today,
|
||||||
valid_to: Date.today + ph[:period].to_i.years,
|
valid_to: Date.today + ph[:period].to_i.years,
|
||||||
auth_info: ph[:authInfo]
|
auth_info: ph[:authInfo][:pw]
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
require 'rails_helper'
|
require 'rails_helper'
|
||||||
|
|
||||||
describe 'EPP Domain', epp: true do
|
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
|
context 'with valid user' do
|
||||||
before(:each) { Fabricate(:epp_user) }
|
before(:each) { Fabricate(:epp_user) }
|
||||||
|
@ -11,28 +11,27 @@ describe 'EPP Domain', epp: true do
|
||||||
response = epp_request('domains/create.xml')
|
response = epp_request('domains/create.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')
|
||||||
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Ü')
|
expect(Domain.first.registrar.name).to eq('Zone Media OÜ')
|
||||||
end
|
end
|
||||||
|
|
||||||
# incomplete
|
|
||||||
it 'checks a domain' do
|
it 'checks a domain' do
|
||||||
response = epp_request('domains/check.xml')
|
response = epp_request('domains/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')
|
||||||
|
|
||||||
domain = response[:parsed].css('resData chkData cd name').first
|
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')
|
expect(domain[:avail]).to eq('1')
|
||||||
|
|
||||||
Fabricate(:domain, name: 'test.ee')
|
Fabricate(:domain, name: 'one.ee')
|
||||||
|
|
||||||
response = epp_request('domains/check.xml')
|
response = epp_request('domains/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
|
||||||
|
|
||||||
expect(name.text).to eq('test.ee')
|
expect(name.text).to eq('one.ee')
|
||||||
expect(name[:avail]).to eq('0')
|
expect(name[:avail]).to eq('0')
|
||||||
expect(reason.text).to eq('in use') #confirm this with current API
|
expect(reason.text).to eq('in use') #confirm this with current API
|
||||||
end
|
end
|
||||||
|
@ -43,11 +42,11 @@ describe 'EPP Domain', epp: true do
|
||||||
expect(response[:msg]).to eq('Command completed successfully')
|
expect(response[:msg]).to eq('Command completed successfully')
|
||||||
|
|
||||||
domain = response[:parsed].css('resData chkData cd name').first
|
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')
|
expect(domain[:avail]).to eq('1')
|
||||||
|
|
||||||
domain = response[:parsed].css('resData chkData cd name').last
|
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')
|
expect(domain[:avail]).to eq('1')
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -57,14 +56,14 @@ describe 'EPP Domain', epp: true do
|
||||||
expect(response[:msg]).to eq('Command completed successfully')
|
expect(response[:msg]).to eq('Command completed successfully')
|
||||||
|
|
||||||
domain = response[:parsed].css('resData chkData cd name').first
|
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')
|
expect(domain[:avail]).to eq('1')
|
||||||
|
|
||||||
domain = response[:parsed].css('resData chkData cd').last
|
domain = response[:parsed].css('resData chkData cd').last
|
||||||
name = domain.css('name').first
|
name = domain.css('name').first
|
||||||
reason = domain.css('reason').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(name[:avail]).to eq('0')
|
||||||
expect(reason.text).to eq('invalid format')
|
expect(reason.text).to eq('invalid format')
|
||||||
end
|
end
|
||||||
|
|
|
@ -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>
|
<?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>
|
</domain:check>
|
||||||
</check>
|
</check>
|
||||||
<clTRID>imkt004#14-06-27at16:13:33</clTRID>
|
<clTRID>ABC-12345</clTRID>
|
||||||
</command>
|
</command>
|
||||||
</epp>
|
</epp>
|
||||||
|
|
|
@ -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>
|
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||||
<domain:name>bla.ee</domain:name>
|
<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>
|
</domain:check>
|
||||||
</check>
|
</check>
|
||||||
<clTRID>naug002#14-06-30at10:45:27</clTRID>
|
<clTRID>ABC-12345</clTRID>
|
||||||
</command>
|
</command>
|
||||||
</epp>
|
</epp>
|
||||||
|
|
|
@ -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>
|
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||||
<domain:name>bla.ee</domain:name>
|
<epp xmlns="urn:ietf:params:xml:ns:epp-1.0">
|
||||||
<domain:name>asdasd</domain:name>
|
<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>
|
</domain:check>
|
||||||
</check>
|
</check>
|
||||||
<clTRID>ixsz002#14-06-30at11:43:32</clTRID>
|
<clTRID>ABC-12345</clTRID>
|
||||||
</command>
|
</command>
|
||||||
</epp>
|
</epp>
|
||||||
|
|
|
@ -1,21 +1,23 @@
|
||||||
<?xml version="1.0" encoding="utf-8" standalone="no"?>
|
<?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">
|
<epp xmlns="urn:ietf:params:xml:ns:epp-1.0">
|
||||||
<command>
|
<command>
|
||||||
<create>
|
<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:create
|
||||||
<domain:name>testing.ee</domain:name>
|
xmlns:domain="urn:ietf:params:xml:ns:domain-1.0">
|
||||||
|
<domain:name>example.ee</domain:name>
|
||||||
<domain:period unit="y">1</domain:period>
|
<domain:period unit="y">1</domain:period>
|
||||||
<domain:nsset>name_server_set1</domain:nsset>
|
<domain:ns>
|
||||||
<domain:registrant>domain_registrator1</domain:registrant>
|
<domain:hostObj>ns1.example.net</domain:hostObj>
|
||||||
<domain:admin>administrative_contact1</domain:admin>
|
<domain:hostObj>ns2.example.net</domain:hostObj>
|
||||||
<domain:authInfo>password</domain:authInfo>
|
</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>
|
</domain:create>
|
||||||
</create>
|
</create>
|
||||||
<extension>
|
<clTRID>ABC-12345</clTRID>
|
||||||
<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>
|
|
||||||
</command>
|
</command>
|
||||||
</epp>
|
</epp>
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
require 'rails_helper'
|
require 'rails_helper'
|
||||||
|
|
||||||
describe 'EPP Session', epp: true do
|
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
|
context 'when not connected' do
|
||||||
it 'greets client upon connection' do
|
it 'greets client upon connection' do
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue