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

This commit is contained in:
Andres Keskküla 2014-08-15 11:53:12 +03:00
commit 5fa1107e3e
11 changed files with 123 additions and 45 deletions

View file

@ -29,6 +29,8 @@ module Epp::DomainsHelper
def info_domain def info_domain
@domain = find_domain @domain = find_domain
handle_errors(@domain) and return unless @domain
render '/epp/domains/info' render '/epp/domains/info'
end end

View file

@ -22,7 +22,9 @@ module EppErrors
values.each do |err| values.each do |err|
if err.is_a?(Hash) if err.is_a?(Hash)
next unless code = find_epp_code(err[:msg]) next unless code = find_epp_code(err[:msg])
epp_errors << {code: code, msg: err[:msg], value: {val: err[:val], obj: err[:obj]}} err_msg = {code: code, msg: err[:msg]}
err_msg[:value] = {val: err[:val], obj: err[:obj]} if err[:val]
epp_errors << err_msg
else else
next unless code = find_epp_code(err) next unless code = find_epp_code(err)
err = {code: code, msg: err} err = {code: code, msg: err}

View file

@ -8,7 +8,8 @@ class Domain < ActiveRecord::Base
'2302' => ['Domain name already exists', 'Domain name is reserved or restricted'], # Object exists '2302' => ['Domain name already exists', 'Domain name is reserved or restricted'], # Object exists
'2306' => ['Registrant is missing', 'Admin contact is missing', 'Given and current expire dates do not match'], # Parameter policy error '2306' => ['Registrant is missing', 'Admin contact is missing', 'Given and current expire dates do not match'], # Parameter policy error
'2004' => ['Nameservers count must be between 1-13', 'Period must add up to 1, 2 or 3 years'], # Parameter value range error '2004' => ['Nameservers count must be between 1-13', 'Period must add up to 1, 2 or 3 years'], # Parameter value range error
'2303' => ['Registrant not found', 'Contact was not found'] # Object does not exist '2303' => ['Registrant not found', 'Contact was not found'], # Object does not exist
'2200' => ['Authentication error']
} }
EPP_ATTR_MAP = { EPP_ATTR_MAP = {
@ -156,6 +157,14 @@ class Domain < ActiveRecord::Base
}) if cur_exp_date.to_date != valid_to }) if cur_exp_date.to_date != valid_to
end end
## SHARED
# For domain transfer
def authenticate(pw)
errors.add(:auth_info, {msg: errors.generate_message(:auth_info, :wrong_pw)}) if pw != auth_info
errors.empty?
end
class << self class << self
def convert_period_to_time(period, unit) def convert_period_to_time(period, unit)
return period.to_i.days if unit == 'd' return period.to_i.days if unit == 'd'

View file

@ -54,6 +54,8 @@ en:
ip_invalid: 'IPv4 is invalid' ip_invalid: 'IPv4 is invalid'
period: period:
out_of_range: 'Period must add up to 1, 2 or 3 years' out_of_range: 'Period must add up to 1, 2 or 3 years'
auth_info:
wrong_pw: 'Authentication error'
nameserver: nameserver:
attributes: attributes:
hostname: hostname:

View file

@ -64,6 +64,9 @@
<domain:info <domain:info
xmlns:domain="urn:ietf:params:xml:ns:domain-1.0"> xmlns:domain="urn:ietf:params:xml:ns:domain-1.0">
<domain:name hosts="all">example.ee</domain:name> <domain:name hosts="all">example.ee</domain:name>
<domain:authInfo>
<domain:pw>2fooBAR</domain:pw>
</domain:authInfo>
</domain:info> </domain:info>
</info> </info>
<clTRID>ABC-12345</clTRID> <clTRID>ABC-12345</clTRID>

View file

@ -178,7 +178,7 @@ describe 'EPP Domain', epp: true do
before(:each) { Fabricate(:domain, name: 'example.ee') } before(:each) { Fabricate(:domain, name: 'example.ee') }
it 'renews a domain' do it 'renews a domain' do
response = epp_request('domains/renew.xml') response = epp_request(domain_renew_xml, :xml)
exDate = response[:parsed].css('renData exDate').text exDate = response[:parsed].css('renData exDate').text
name = response[:parsed].css('renData name').text name = response[:parsed].css('renData name').text
expect(exDate).to eq ('2015-08-07 00:00:00 UTC') expect(exDate).to eq ('2015-08-07 00:00:00 UTC')
@ -234,10 +234,16 @@ describe 'EPP Domain', epp: true do
expect(inf_data.css('upDate').text).to eq(d.updated_at.to_time.utc.to_s) expect(inf_data.css('upDate').text).to eq(d.updated_at.to_time.utc.to_s)
end end
it 'returns error when domain can not be found' do
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
end end
it 'checks a domain' do it 'checks a domain' do
response = epp_request('domains/check.xml') response = epp_request(domain_check_xml, :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')
@ -247,7 +253,7 @@ describe 'EPP Domain', epp: true do
Fabricate(:domain, name: 'example.ee') Fabricate(:domain, name: 'example.ee')
response = epp_request('domains/check.xml') response = epp_request(domain_check_xml, :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

View file

@ -106,7 +106,7 @@ describe 'EPP Helper', epp: true do
expect(generated).to eq(expected) expect(generated).to eq(expected)
end end
it 'creates valid info request' do it 'generates valid info 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">
<command> <command>
@ -114,6 +114,9 @@ describe 'EPP Helper', epp: true do
<domain:info <domain:info
xmlns:domain="urn:ietf:params:xml:ns:domain-1.0"> xmlns:domain="urn:ietf:params:xml:ns:domain-1.0">
<domain:name hosts="all">example.ee</domain:name> <domain:name hosts="all">example.ee</domain:name>
<domain:authInfo>
<domain:pw>2fooBAR</domain:pw>
</domain:authInfo>
</domain:info> </domain:info>
</info> </info>
<clTRID>ABC-12345</clTRID> <clTRID>ABC-12345</clTRID>
@ -132,6 +135,9 @@ describe 'EPP Helper', epp: true do
<domain:info <domain:info
xmlns:domain="urn:ietf:params:xml:ns:domain-1.0"> xmlns:domain="urn:ietf:params:xml:ns:domain-1.0">
<domain:name hosts="sub">one.ee</domain:name> <domain:name hosts="sub">one.ee</domain:name>
<domain:authInfo>
<domain:pw>b3rafsla</domain:pw>
</domain:authInfo>
</domain:info> </domain:info>
</info> </info>
<clTRID>ABC-12345</clTRID> <clTRID>ABC-12345</clTRID>
@ -140,7 +146,89 @@ describe 'EPP Helper', epp: true do
').to_s.squish ').to_s.squish
generated = Nokogiri::XML(domain_info_xml(name_value: 'one.ee', name_hosts: 'sub')).to_s.squish generated = Nokogiri::XML(domain_info_xml(name_value: 'one.ee', name_hosts: 'sub', pw: 'b3rafsla')).to_s.squish
expect(generated).to eq(expected)
end
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
expected = Nokogiri::XML('<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<epp xmlns="urn:ietf:params:xml:ns:epp-1.0">
<command>
<renew>
<domain:renew
xmlns:domain="urn:ietf:params:xml:ns:domain-1.0">
<domain:name>example.ee</domain:name>
<domain:curExpDate>2014-08-07</domain:curExpDate>
<domain:period unit="y">1</domain:period>
</domain:renew>
</renew>
<clTRID>ABC-12345</clTRID>
</command>
</epp>
').to_s.squish
generated = Nokogiri::XML(domain_renew_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>
<renew>
<domain:renew
xmlns:domain="urn:ietf:params:xml:ns:domain-1.0">
<domain:name>one.ee</domain:name>
<domain:curExpDate>2009-11-15</domain:curExpDate>
<domain:period unit="d">365</domain:period>
</domain:renew>
</renew>
<clTRID>ABC-12345</clTRID>
</command>
</epp>
').to_s.squish
generated = Nokogiri::XML(domain_renew_xml(name: 'one.ee', curExpDate: '2009-11-15', period_value: '365', period_unit: 'd')).to_s.squish
expect(generated).to eq(expected) expect(generated).to eq(expected)
end end
end end

View file

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

View file

@ -1,12 +0,0 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<epp xmlns="urn:ietf:params:xml:ns:epp-1.0">
<command>
<info>
<domain:info
xmlns:domain="urn:ietf:params:xml:ns:domain-1.0">
<domain:name hosts="all">example.ee</domain:name>
</domain:info>
</info>
<clTRID>ABC-12345</clTRID>
</command>
</epp>

View file

@ -1,14 +0,0 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<epp xmlns="urn:ietf:params:xml:ns:epp-1.0">
<command>
<renew>
<domain:renew
xmlns:domain="urn:ietf:params:xml:ns:domain-1.0">
<domain:name>example.ee</domain:name>
<domain:curExpDate>2014-08-07</domain:curExpDate>
<domain:period unit="y">1</domain:period>
</domain:renew>
</renew>
<clTRID>ABC-12345</clTRID>
</command>
</epp>

View file

@ -128,6 +128,7 @@ module Epp
def domain_info_xml(xml_params={}) def domain_info_xml(xml_params={})
xml_params[:name_value] = xml_params[:name_value] || 'example.ee' xml_params[:name_value] = xml_params[:name_value] || 'example.ee'
xml_params[:name_hosts] = xml_params[:name_hosts] || 'all' xml_params[:name_hosts] = xml_params[:name_hosts] || 'all'
xml_params[:pw] = xml_params[:pw] || '2fooBAR'
xml = Builder::XmlMarkup.new xml = Builder::XmlMarkup.new
@ -137,6 +138,9 @@ module Epp
xml.info do xml.info do
xml.tag!('domain:info', 'xmlns:domain' => 'urn:ietf:params:xml:ns:domain-1.0') do xml.tag!('domain:info', 'xmlns:domain' => 'urn:ietf:params:xml:ns:domain-1.0') do
xml.tag!('domain:name', xml_params[:name_value], 'hosts' => xml_params[:name_hosts]) if xml_params[:name] != false xml.tag!('domain:name', xml_params[:name_value], 'hosts' => xml_params[:name_hosts]) if xml_params[:name] != false
xml.tag!('domain:authInfo') do
xml.tag!('domain:pw', xml_params[:pw])
end
end end
end end
xml.clTRID 'ABC-12345' xml.clTRID 'ABC-12345'