Support multiple errors

This commit is contained in:
Martin Lensment 2014-07-30 14:32:37 +03:00
parent 1e2dad06f9
commit 9fdf40cdcd
6 changed files with 32 additions and 27 deletions

View file

@ -12,6 +12,7 @@ module Epp::Common
end
def proxy
@errors = []
@svTRID = "ccReg-#{'%010d' % rand(10 ** 10)}"
send(params[:command])
end
@ -34,10 +35,10 @@ module Epp::Common
xsd = Nokogiri::XML::Schema(File.read("doc/schemas/#{type}-1.0.xsd"))
doc = Nokogiri::XML(params[:frame])
@extValues = xsd.validate(doc)
if @extValues.any?
@code = '2001'
@msg = 'Command syntax error'
ext_values = xsd.validate(doc)
@errors = []
if ext_values.any?
@errors << {code: '2001', msg: 'Command syntax error', ext_values: ext_values}
render '/epp/error' and return
end
end

View file

@ -2,7 +2,8 @@ class Epp::ErrorsController < ApplicationController
include Epp::Common
def error
@code, @msg = params[:code], params[:msg]
@errors = []
@errors << {code: params[:code], msg: params[:msg]}
render '/epp/error'
end
end

View file

@ -2,7 +2,7 @@ module Epp::ContactsHelper
def create_contact
ph = params_hash['epp']['command']['create']['create']
ph[:ident] ? @contact = Contact.where(ident: ph[:ident]).first_or_initialize : @contact = Contact.new
ph[:ident] ? @contact = Contact.where(ident: ph[:ident]).first_or_initialize : @contact = Contact.new
if @contact.new_record?
@contact.assign_attributes(
code: ph[:id],
@ -10,7 +10,7 @@ module Epp::ContactsHelper
ident: ph[:ident],
email: ph[:email]
)
end
end
@contact.name = ph[:postalInfo][:name]
@contact.ident_type = ident_type
@ -32,12 +32,10 @@ module Epp::ContactsHelper
@contact.destroy
render '/epp/contacts/delete'
rescue NoMethodError => e
@code = '2303'
@msg = "Object does not exist"
@errors << {code: '2303', msg: "Object does not exist"}
render '/epp/error'
rescue
@code = '2400'
@msg = "Command failed"
@errors << {code: '2400', msg: "Command failed"}
render '/epp/error'
end
end
@ -49,8 +47,7 @@ module Epp::ContactsHelper
if @contacts.any?
render '/epp/contacts/check'
else
@code = '2303'
@msg = "Object does not exist"
@errors << {code: '2303', msg: "Object does not exist"}
render 'epp/error'
end
end
@ -59,9 +56,9 @@ module Epp::ContactsHelper
def ident_type
result = params[:frame].slice(/(?<=\<ns2:ident type=)(.*)(?=<)/)
return nil unless result
Contact::IDENT_TYPES.any? { |type| return type if result.include?(type) }
return nil
end

View file

@ -35,8 +35,7 @@ module Epp::DomainsHelper
def handle_domain_name_errors
[:epp_domain_taken, :epp_domain_reserved].each do |x|
if @domain.errors.added?(:name, x)
@code = '2302'
@msg = @domain.errors[:name].first
@errors << {code: '2302', msg: @domain.errors[:name].first}
end
end
end

View file

@ -1,19 +1,22 @@
xml.epp_head do
xml.response do
xml.result('code' => @code) do
xml.msg(@msg, 'lang' => 'en')
end
end
@errors.each do |x|
xml.result('code' => x[:code]) do
xml.msg(x[:msg], 'lang' => 'en')
x[:ext_values].each do |y|
xml.extValue do
xml.value do
# xml.tag!()
xml.reason y.to_s
end
end
end if x[:ext_values]
@extValues.each do |x|
xml.extValue do
xml.value do
# xml.tag!()
xml.reason x.to_s
end
end
end if @extValues && @extValues.any?
end
xml << render('/epp/shared/trID')
end

View file

@ -31,6 +31,10 @@ describe 'EPP Domain', epp: true do
expect(response[:clTRID]).to eq('ABC-12345')
end
it 'does not create a domain with false period' do
end
it 'checks a domain' do
response = epp_request('domains/check.xml')
expect(response[:result_code]).to eq('1000')