From c38680a3b11b7f54379f2e2a8c3adf7b243d50c6 Mon Sep 17 00:00:00 2001 From: Martin Lensment Date: Fri, 24 Jul 2015 16:38:14 +0300 Subject: [PATCH] Validate not_found too against schema #2752 --- app/controllers/epp_controller.rb | 2 +- config/routes.rb | 2 +- lib/epp_constraint.rb | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/app/controllers/epp_controller.rb b/app/controllers/epp_controller.rb index 5ddfe104a..a99d739db 100644 --- a/app/controllers/epp_controller.rb +++ b/app/controllers/epp_controller.rb @@ -9,7 +9,7 @@ class EppController < ApplicationController before_action :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] xsd = Nokogiri::XML::Schema(File.read("lib/schemas/#{params[:schema]}")) xsd.validate(params[:nokogiri_frame]).each do |error| diff --git a/config/routes.rb b/config/routes.rb index 4ec266d9a..925947ea9 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -10,7 +10,7 @@ Rails.application.routes.draw do post 'command/poll', to: 'polls#poll', constraints: EppConstraint.new(:poll) 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' end diff --git a/lib/epp_constraint.rb b/lib/epp_constraint.rb index b7e151a62..9c60edbc3 100644 --- a/lib/epp_constraint.rb +++ b/lib/epp_constraint.rb @@ -13,7 +13,7 @@ class EppConstraint 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) + unless [:keyrelay, :poll, :session, :not_found].include?(@type) element = "//#{@type}:#{request.params[:action]}" return false if request.params[:nokogiri_frame].xpath("#{element}", OBJECT_TYPES[@type]).none? # TODO: Support multiple schemas