Validate request against schemas #2799

This commit is contained in:
Martin Lensment 2015-07-22 18:34:19 +03:00
parent c1f9a470df
commit c79fee5a49
2 changed files with 18 additions and 13 deletions

View file

@ -6,22 +6,26 @@ class EppController < ApplicationController
before_action :generate_svtrid
before_action :latin_only
# before_action :validate_against_schema
before_action :validate_against_schema
# def validate_against_schema
def validate_against_schema
# filename =
# if params[:epp_object_type] == :domain
# xsd = Nokogiri::XML::Schema(File.read('doc/schemas/domain-eis-1.0.xsd'))
# xsd.validate(Nokogiri::XML(params[:raw_frame])).each do |error|
# epp_errors << {
# code: 2002,
# msg: error
# }
# end
# end
return if params[:action] == 'hello'
params[:schema] = 'epp-1.0.xsd' unless params[:schema]
xsd = Nokogiri::XML::Schema(File.read("doc/schemas/#{params[:schema]}"))
xsd.validate(Nokogiri::XML(params[:raw_frame])).each do |error|
epp_errors << {
code: 2001,
msg: error
}
end
# handle_errors and return if epp_errors.any?
# end
handle_errors and return if epp_errors.any?
end
before_action :validate_request
before_action :update_epp_session

View file

@ -15,6 +15,7 @@ class EppConstraint
unless [:keyrelay, :poll].include?(@type)
element = "//#{@type}:#{request.params[:action]}"
return false if parsed_frame.xpath("#{element}", OBJECT_TYPES[@type]).none?
request.params[:schema] = OBJECT_TYPES[@type][@type].split('/').last
end
request.params[:parsed_frame] = parsed_frame.remove_namespaces!