Use translation file for errors, display reserved domain error through epp

This commit is contained in:
Martin Lensment 2014-07-30 12:31:36 +03:00
parent e3c60d51fe
commit d96b1b5deb
6 changed files with 40 additions and 2 deletions

View file

@ -8,7 +8,11 @@ module Epp::DomainsHelper
if domain.errors.added?(:name, :taken) if domain.errors.added?(:name, :taken)
@code = '2302' @code = '2302'
@msg = 'Domain name already exists' @msg = 'Domain name already exists'
elsif domain.errors.added?(:name, :epp_domain_reserved)
@code = '2302'
@msg = domain.errors[:name].first
end end
render '/epp/error' render '/epp/error'
end end
end end

View file

@ -30,7 +30,7 @@ class Domain < ActiveRecord::Base
end end
if !DomainNameValidator.validate_reservation(x) if !DomainNameValidator.validate_reservation(x)
res << {name: x, avail: 0, reason: 'Domain name is reserved or restricted'} res << {name: x, avail: 0, reason: I18n.t('errors.messages.epp_domain_reserved')}
next next
end end

View file

@ -10,7 +10,7 @@ class DomainNameValidator < ActiveModel::EachValidator
if !self.class.validate_format(value) if !self.class.validate_format(value)
record.errors[attribute] << (options[:message] || 'invalid format') record.errors[attribute] << (options[:message] || 'invalid format')
elsif !self.class.validate_reservation(value) elsif !self.class.validate_reservation(value)
record.errors[attribute] << (options[:message] || 'Domain name is reserved or restricted') record.errors[attribute] << (options[:message] || I18n.t('errors.messages.epp_domain_reserved'))
end end
end end

View file

@ -20,4 +20,7 @@
# available at http://guides.rubyonrails.org/i18n.html. # available at http://guides.rubyonrails.org/i18n.html.
en: en:
errors:
messages:
epp_domain_reserved: 'Domain name is reserved or restricted'
hello: "Hello world" hello: "Hello world"

View file

@ -23,6 +23,14 @@ describe 'EPP Domain', epp: true do
expect(response[:clTRID]).to eq('ABC-12345') expect(response[:clTRID]).to eq('ABC-12345')
end end
it 'does not create reserved domain' do
Fabricate(:reserved_domain)
response = epp_request('domains/create_reserved.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 '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')

View file

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