mirror of
https://github.com/internetee/registry.git
synced 2025-05-16 17:37:17 +02:00
Move xml parsing to epp constraint #2752
This commit is contained in:
parent
2148cc57e5
commit
c94da28af6
2 changed files with 5 additions and 5 deletions
|
@ -9,10 +9,10 @@ class EppController < ApplicationController
|
|||
before_action :validate_against_schema
|
||||
|
||||
def validate_against_schema
|
||||
return if params[:action] == 'hello'
|
||||
return if ['hello', 'error'].include?(params[:action])
|
||||
params[:schema] = 'epp-1.0.xsd' unless params[:schema]
|
||||
xsd = Nokogiri::XML::Schema(File.read("lib/schemas/#{params[:schema]}"))
|
||||
xsd.validate(Nokogiri::XML(params[:raw_frame])).each do |error|
|
||||
xsd.validate(params[:nokogiri_frame]).each do |error|
|
||||
epp_errors << {
|
||||
code: 2001,
|
||||
msg: error
|
||||
|
|
|
@ -10,16 +10,16 @@ class EppConstraint
|
|||
|
||||
# creates parsed_frame, detects epp request object
|
||||
def matches?(request)
|
||||
parsed_frame = Nokogiri::XML(request.params[:raw_frame])
|
||||
request.params[:nokogiri_frame] ||= Nokogiri::XML(request.params[:raw_frame])
|
||||
request.params[:parsed_frame] ||= request.params[:nokogiri_frame].dup.remove_namespaces!
|
||||
|
||||
unless [:keyrelay, :poll, :session].include?(@type)
|
||||
element = "//#{@type}:#{request.params[:action]}"
|
||||
return false if parsed_frame.xpath("#{element}", OBJECT_TYPES[@type]).none?
|
||||
return false if request.params[:nokogiri_frame].xpath("#{element}", OBJECT_TYPES[@type]).none?
|
||||
# TODO: Support multiple schemas
|
||||
request.params[:schema] = OBJECT_TYPES[@type][@type].split('/').last
|
||||
end
|
||||
|
||||
request.params[:parsed_frame] = parsed_frame.remove_namespaces!
|
||||
request.params[:epp_object_type] = @type
|
||||
true
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue