This commit is contained in:
Martin Lensment 2015-07-24 17:10:24 +03:00
parent c38680a3b1
commit 1d82fb9052
3 changed files with 12 additions and 5 deletions

View file

@ -10,9 +10,7 @@ class EppController < ApplicationController
before_action :validate_against_schema
def validate_against_schema
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|
schema.validate(params[:nokogiri_frame]).each do |error|
epp_errors << {
code: 2001,
msg: error
@ -73,6 +71,13 @@ class EppController < ApplicationController
render_epp_response '/epp/error'
end
def schema
# TODO: Support multiple schemas
return DOMAIN_SCHEMA if params[:epp_object_type] == :domain
return CONTACT_SCHEMA if params[:epp_object_type] == :contact
EPP_SCHEMA
end
def generate_svtrid
# rubocop: disable Style/VariableName
@svTRID = "ccReg-#{format('%010d', rand(10**10))}"

View file

@ -0,0 +1,3 @@
EPP_SCHEMA = Nokogiri::XML::Schema(File.read("lib/schemas/epp-1.0.xsd"))
DOMAIN_SCHEMA = Nokogiri::XML::Schema(File.read("lib/schemas/domain-eis-1.0.xsd"))
CONTACT_SCHEMA = Nokogiri::XML::Schema(File.read("lib/schemas/contact-eis-1.0.xsd"))

View file

@ -10,14 +10,13 @@ class EppConstraint
# creates parsed_frame, detects epp request object
def matches?(request)
# TODO: Maybe move this to controller to keep params clean
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, :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
request.params[:schema] = OBJECT_TYPES[@type][@type].split('/').last
end
request.params[:epp_object_type] = @type