diff --git a/app/controllers/epp_controller.rb b/app/controllers/epp_controller.rb index a99d739db..f719e68b0 100644 --- a/app/controllers/epp_controller.rb +++ b/app/controllers/epp_controller.rb @@ -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))}" diff --git a/config/initializers/load_schemas.rb b/config/initializers/load_schemas.rb new file mode 100644 index 000000000..617022179 --- /dev/null +++ b/config/initializers/load_schemas.rb @@ -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")) diff --git a/lib/epp_constraint.rb b/lib/epp_constraint.rb index 9c60edbc3..10bc6b643 100644 --- a/lib/epp_constraint.rb +++ b/lib/epp_constraint.rb @@ -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