This commit is contained in:
Martin Lensment 2014-08-13 13:53:14 +03:00
parent 7cd2d1aec4
commit ca608a004b
10 changed files with 42 additions and 214 deletions

View file

@ -9,7 +9,7 @@ describe 'EPP Domain', epp: true do
it 'returns error if contact does not exists' do
Fabricate(:contact, code: 'jd1234')
response = epp_request('domains/create.xml')
response = epp_request(domain_create_xml, :xml)
expect(response[:results][0][:result_code]).to eq('2303')
expect(response[:results][0][:msg]).to eq('Contact was not found')
expect(response[:results][0][:value]).to eq('sh8013')
@ -33,7 +33,7 @@ describe 'EPP Domain', epp: true do
}
it 'creates a domain' do
response = epp_request('domains/create.xml')
response = epp_request(domain_create_xml, :xml)
expect(response[:result_code]).to eq('1000')
expect(response[:msg]).to eq('Command completed successfully')
expect(response[:clTRID]).to eq('ABC-12345')
@ -46,8 +46,8 @@ describe 'EPP Domain', epp: true do
end
it 'does not create duplicate domain' do
epp_request('domains/create.xml')
response = epp_request('domains/create.xml')
epp_request(domain_create_xml, :xml)
response = epp_request(domain_create_xml, :xml)
expect(response[:result_code]).to eq('2302')
expect(response[:msg]).to eq('Domain name already exists')
expect(response[:clTRID]).to eq('ABC-12345')
@ -55,14 +55,19 @@ describe 'EPP Domain', epp: true do
it 'does not create reserved domain' do
Fabricate(:reserved_domain)
response = epp_request('domains/create_reserved.xml')
xml = domain_create_xml(name: '1162.ee')
response = epp_request(xml, :xml)
expect(response[:result_code]).to eq('2302')
expect(response[:msg]).to eq('Domain name is reserved or restricted')
expect(response[:clTRID]).to eq('ABC-12345')
end
it 'does not create domain without contacts and registrant' do
response = epp_request('domains/create_wo_contacts_and_registrant.xml')
xml = domain_create_xml(contacts: [], registrant: false)
response = epp_request(xml, :xml)
expect(response[:results][0][:result_code]).to eq('2003')
expect(response[:results][0][:msg]).to eq('Required parameter missing: contact')
@ -71,24 +76,30 @@ describe 'EPP Domain', epp: true do
end
it 'does not create domain without nameservers' do
response = epp_request('domains/create_wo_nameservers.xml')
xml = domain_create_xml(nameservers: [])
response = epp_request(xml, :xml)
expect(response[:result_code]).to eq('2003')
expect(response[:msg]).to eq('Required parameter missing: ns')
end
it 'does not create domain with too many nameservers' do
response = epp_request('domains/create_w_too_many_nameservers.xml')
nameservers = []
14.times {|i| nameservers << {hostObj: "ns#{i}.example.net"}}
xml = domain_create_xml(nameservers: nameservers)
response = epp_request(xml, :xml)
expect(response[:result_code]).to eq('2004')
expect(response[:msg]).to eq('Nameservers count must be between 1-13')
end
it 'returns error when invalid nameservers are present' do
response = epp_request('domains/create_w_invalid_nameservers.xml')
xml = domain_create_xml(nameservers: [{hostObj: 'invalid1-'}, {hostObj: '-invalid2'}])
response = epp_request(xml, :xml)
expect(response[:result_code]).to eq('2005')
expect(response[:msg]).to eq('Hostname is invalid')
end
it 'creates domain with nameservers with ips' do
response = epp_request('domains/create_w_host_attrs.xml')
expect(Domain.first.nameservers.count).to eq(2)
@ -103,17 +114,21 @@ describe 'EPP Domain', epp: true do
end
it 'creates a domain with period in days' do
response = epp_request('domains/create_w_period_in_days.xml')
xml = domain_create_xml(period_value: 365, period_unit: 'd')
response = epp_request(xml, :xml)
expect(response[:result_code]).to eq('1000')
expect(response[:msg]).to eq('Command completed successfully')
expect(Domain.first.valid_to).to eq(Date.today + 1.year)
end
it 'does not create a domain with invalid period' do
response = epp_request('domains/create_w_invalid_period.xml')
xml = domain_create_xml(period_value: 367, period_unit: 'd')
response = epp_request(xml, :xml)
expect(response[:results][0][:result_code]).to eq('2004')
expect(response[:results][0][:msg]).to eq('Period must add up to 1, 2 or 3 years')
expect(response[:results][0][:value]).to eq('843')
expect(response[:results][0][:value]).to eq('367')
end
end
@ -138,7 +153,9 @@ describe 'EPP Domain', epp: true do
end
it 'does not create a domain without admin contact' do
response = epp_request('domains/create_wo_contacts.xml')
xml = domain_create_xml(contacts: [])
response = epp_request(xml, :xml)
expect(response[:result_code]).to eq('2003')
expect(response[:msg]).to eq('Required parameter missing: contact')
expect(response[:clTRID]).to eq('ABC-12345')

View file

@ -1,23 +0,0 @@
<?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="urn:ietf:params:xml:ns:domain-1.0">
<domain:name>1162.ee</domain:name>
<domain:period unit="y">1</domain:period>
<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>
<clTRID>ABC-12345</clTRID>
</command>
</epp>

View file

@ -1,24 +0,0 @@
<?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="urn:ietf:params:xml:ns:domain-1.0">
<domain:name>example.ee</domain:name>
<domain:period unit="y">1</domain:period>
<domain:ns>
<domain:hostObj>invalid1-</domain:hostObj>
<domain:hostObj>-invalid2</domain:hostObj>
</domain:ns>
<domain:registrant>jd1234</domain:registrant>
<domain:contact type="admin">sh8013</domain:contact>
<domain:contact type="tech">sh8013</domain:contact>
<domain:contact type="tech">sh801333</domain:contact>
<domain:authInfo>
<domain:pw>2fooBAR</domain:pw>
</domain:authInfo>
</domain:create>
</create>
<clTRID>ABC-12345</clTRID>
</command>
</epp>

View file

@ -1,24 +0,0 @@
<?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="urn:ietf:params:xml:ns:domain-1.0">
<domain:name>example.ee</domain:name>
<domain:period unit="d">843</domain:period>
<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:contact type="tech">sh801333</domain:contact>
<domain:authInfo>
<domain:pw>2fooBAR</domain:pw>
</domain:authInfo>
</domain:create>
</create>
<clTRID>ABC-12345</clTRID>
</command>
</epp>

View file

@ -1,24 +0,0 @@
<?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="urn:ietf:params:xml:ns:domain-1.0">
<domain:name>example.ee</domain:name>
<domain:period unit="d">365</domain:period>
<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:contact type="tech">sh801333</domain:contact>
<domain:authInfo>
<domain:pw>2fooBAR</domain:pw>
</domain:authInfo>
</domain:create>
</create>
<clTRID>ABC-12345</clTRID>
</command>
</epp>

View file

@ -1,36 +0,0 @@
<?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="urn:ietf:params:xml:ns:domain-1.0">
<domain:name>example.ee</domain:name>
<domain:period unit="y">1</domain:period>
<domain:ns>
<domain:hostObj>ns1.example.net</domain:hostObj>
<domain:hostObj>ns2.example.net</domain:hostObj>
<domain:hostObj>ns3.example.net</domain:hostObj>
<domain:hostObj>ns4.example.net</domain:hostObj>
<domain:hostObj>ns5.example.net</domain:hostObj>
<domain:hostObj>ns6.example.net</domain:hostObj>
<domain:hostObj>ns7.example.net</domain:hostObj>
<domain:hostObj>ns8.example.net</domain:hostObj>
<domain:hostObj>ns9.example.net</domain:hostObj>
<domain:hostObj>ns10.example.net</domain:hostObj>
<domain:hostObj>ns11.example.net</domain:hostObj>
<domain:hostObj>ns12.example.net</domain:hostObj>
<domain:hostObj>ns13.example.net</domain:hostObj>
<domain:hostObj>ns14.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:contact type="tech">sh801333</domain:contact>
<domain:authInfo>
<domain:pw>2fooBAR</domain:pw>
</domain:authInfo>
</domain:create>
</create>
<clTRID>ABC-12345</clTRID>
</command>
</epp>

View file

@ -1,21 +0,0 @@
<?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="urn:ietf:params:xml:ns:domain-1.0">
<domain:name>example.ee</domain:name>
<domain:period unit="y">1</domain:period>
<domain:ns>
<domain:hostObj>ns1.example.net</domain:hostObj>
<domain:hostObj>ns2.example.net</domain:hostObj>
</domain:ns>
<domain:registrant>jd1234</domain:registrant>
<domain:authInfo>
<domain:pw>2fooBAR</domain:pw>
</domain:authInfo>
</domain:create>
</create>
<clTRID>ABC-12345</clTRID>
</command>
</epp>

View file

@ -1,20 +0,0 @@
<?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="urn:ietf:params:xml:ns:domain-1.0">
<domain:name>example.ee</domain:name>
<domain:period unit="y">1</domain:period>
<domain:ns>
<domain:hostObj>ns1.example.net</domain:hostObj>
<domain:hostObj>ns2.example.net</domain:hostObj>
</domain:ns>
<domain:authInfo>
<domain:pw>2fooBAR</domain:pw>
</domain:authInfo>
</domain:create>
</create>
<clTRID>ABC-12345</clTRID>
</command>
</epp>

View file

@ -1,18 +0,0 @@
<?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="urn:ietf:params:xml:ns:domain-1.0">
<domain:name>example.ee</domain:name>
<domain:period unit="y">1</domain:period>
<domain:registrant>jd1234</domain:registrant>
<domain:contact type="admin">sh8013</domain:contact>
<domain:authInfo>
<domain:pw>2fooBAR</domain:pw>
</domain:authInfo>
</domain:create>
</create>
<clTRID>ABC-12345</clTRID>
</command>
</epp>

View file

@ -4,9 +4,10 @@ module Epp
end
# handles connection and login automatically
def epp_request(filename)
def epp_request(data, type=:filename)
begin
parse_response(server.request(read_body(filename)))
return parse_response(server.request(read_body(data))) if type == :filename
return parse_response(server.request(data))
rescue Exception => e
e
end
@ -44,8 +45,8 @@ module Epp
# THIS FEATURE IS EXPERIMENTAL AND NOT IN USE ATM
def domain_create_template(xml_params={})
xml_params[:nameservers] = xml_params[:ns] || [{hostObj: 'ns1.example.net'}, {hostObj: 'ns2.example.net'}]
def domain_create_xml(xml_params={})
xml_params[:nameservers] = xml_params[:nameservers] || [{hostObj: 'ns1.example.net'}, {hostObj: 'ns2.example.net'}]
xml_params[:contacts] = xml_params[:contacts] || [
{contact_value: 'sh8013', contact_type: 'admin'},
{contact_value: 'sh8013', contact_type: 'tech'},
@ -62,25 +63,25 @@ module Epp
xml.create do
xml.tag!('domain:create', 'xmlns:domain' => 'urn:ietf:params:xml:ns:domain-1.0') do
xml.tag!('domain:name', (xml_params[:name] || 'expample.ee'))
xml.tag!('domain:name', (xml_params[:name] || 'expample.ee')) if xml_params[:name] != false
xml.tag!('domain:period', (xml_params[:period_value] || 1), 'unit' => (xml_params[:period_unit] || 'y'))
xml.tag!('domain:period', (xml_params[:period_value] || 1), 'unit' => (xml_params[:period_unit] || 'y')) if xml_params[:period] != false
xml.tag!('domain:ns') do
xml_params[:nameservers].each do |x|
xml.tag!('domain:hostObj', x[:hostObj])
end
end
end if xml_params[:nameservers].any?
xml.tag!('domain:registrant', (xml_params[:registrant] || 'jd1234'))
xml.tag!('domain:registrant', (xml_params[:registrant] || 'jd1234')) if xml_params[:registrant] != false
xml_params[:contacts].each do |x|
xml.tag!('domain:contact', x[:contact_value], 'type' => (x[:contact_type]))
end
end if xml_params[:contacts].any?
xml.tag!('domain:authInfo') do
xml.tag!('domain:pw', xml_params[:pw] || '2fooBAR')
end
end if xml_params[:authInfo] != false
end
end
xml.clTRID 'ABC-12345'