mirror of
https://github.com/internetee/registry.git
synced 2025-05-17 01:47:18 +02:00
Validate not_found too against schema #2752
This commit is contained in:
parent
626fa6d25d
commit
c38680a3b1
3 changed files with 3 additions and 3 deletions
|
@ -9,7 +9,7 @@ class EppController < ApplicationController
|
||||||
|
|
||||||
before_action :validate_against_schema
|
before_action :validate_against_schema
|
||||||
def validate_against_schema
|
def validate_against_schema
|
||||||
return if ['hello', 'error', 'keyrelay', 'not_found'].include?(params[:action])
|
return if ['hello', 'error', 'keyrelay'].include?(params[:action])
|
||||||
params[:schema] = 'epp-1.0.xsd' unless params[:schema]
|
params[:schema] = 'epp-1.0.xsd' unless params[:schema]
|
||||||
xsd = Nokogiri::XML::Schema(File.read("lib/schemas/#{params[:schema]}"))
|
xsd = Nokogiri::XML::Schema(File.read("lib/schemas/#{params[:schema]}"))
|
||||||
xsd.validate(params[:nokogiri_frame]).each do |error|
|
xsd.validate(params[:nokogiri_frame]).each do |error|
|
||||||
|
|
|
@ -10,7 +10,7 @@ Rails.application.routes.draw do
|
||||||
post 'command/poll', to: 'polls#poll', constraints: EppConstraint.new(:poll)
|
post 'command/poll', to: 'polls#poll', constraints: EppConstraint.new(:poll)
|
||||||
post 'command/keyrelay', to: 'keyrelays#keyrelay', constraints: EppConstraint.new(:keyrelay)
|
post 'command/keyrelay', to: 'keyrelays#keyrelay', constraints: EppConstraint.new(:keyrelay)
|
||||||
|
|
||||||
post 'command/:command', to: 'errors#not_found' # fallback route
|
post 'command/:command', to: 'errors#not_found', constraints: EppConstraint.new(:not_found) # fallback route
|
||||||
|
|
||||||
get 'error/:command', to: 'errors#error'
|
get 'error/:command', to: 'errors#error'
|
||||||
end
|
end
|
||||||
|
|
|
@ -13,7 +13,7 @@ class EppConstraint
|
||||||
request.params[:nokogiri_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!
|
request.params[:parsed_frame] ||= request.params[:nokogiri_frame].dup.remove_namespaces!
|
||||||
|
|
||||||
unless [:keyrelay, :poll, :session].include?(@type)
|
unless [:keyrelay, :poll, :session, :not_found].include?(@type)
|
||||||
element = "//#{@type}:#{request.params[:action]}"
|
element = "//#{@type}:#{request.params[:action]}"
|
||||||
return false if request.params[:nokogiri_frame].xpath("#{element}", OBJECT_TYPES[@type]).none?
|
return false if request.params[:nokogiri_frame].xpath("#{element}", OBJECT_TYPES[@type]).none?
|
||||||
# TODO: Support multiple schemas
|
# TODO: Support multiple schemas
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue