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

This commit is contained in:
Priit Tamboom 2014-06-30 12:41:31 +03:00
commit 54d72db6cd
6 changed files with 71 additions and 10 deletions

View file

@ -1,21 +1,17 @@
module Epp::DomainsHelper
def create_domain
domain = Domain.create!(domain_params)
domain = Domain.create!(domain_create_params)
render '/epp/domains/create'
end
def check_domain
cp = command_params_for('check')
@domain = cp[:name]
@avail = Domain.find_by(name: @domain) ? '0' : '1'
@domains = Domain.check_availability(domain_check_params[:names])
render '/epp/domains/check'
end
### HELPER METHODS ###
def domain_params
def domain_create_params
cp = command_params_for('create')
{
name: cp[:name],
@ -26,4 +22,9 @@ module Epp::DomainsHelper
auth_info: cp[:authInfo]
}
end
def domain_check_params
node_set = parsed_frame.css('epp command check check name')
node_set.inject({names: []}){ |hash, obj| hash[:names] << obj.text; hash }
end
end

View file

@ -4,4 +4,15 @@ class Domain < ActiveRecord::Base
belongs_to :owner_contact, class_name: 'Contact'
belongs_to :technical_contact, class_name: 'Contact'
belongs_to :admin_contact, class_name: 'Contact'
class << self
def check_availability(domains)
res = []
domains.each do |x|
res << {name: x, avail: Domain.find_by(name: x) ? 0 : 1}
end
res
end
end
end

View file

@ -6,8 +6,10 @@ xml.epp_head do
xml.resData do
xml.tag!('domain:chkData', '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') do
xml.tag!('domain:cd') do
xml.tag!('domain:name', @domain, 'avail' => @avail)
@domains.each do |x|
xml.tag!('domain:cd') do
xml.tag!('domain:name', x[:name], 'avail' => x[:avail])
end
end
end
end

View file

@ -16,7 +16,7 @@ describe 'EPP Domain', epp: true do
end
# incomplete
it 'checks domain' do
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')
@ -33,5 +33,37 @@ describe 'EPP Domain', epp: true do
expect(domain[:avail]).to eq('0')
end
it 'checks multiple domains' do
response = epp_request('domains/check_multiple.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[:avail]).to eq('1')
domain = response[:parsed].css('resData chkData cd name').last
expect(domain.text).to eq('bla.ee')
expect(domain[:avail]).to eq('1')
end
it 'checks invalid format domain' do
response = epp_request('domains/check_multiple_with_invalid.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[: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[:avail]).to eq('0')
expect(reason.text).to eq('invalid format')
end
end
end

View file

@ -0,0 +1,7 @@
<?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>
</epp>

View file

@ -0,0 +1,8 @@
<?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>
</epp>