From 1f468352c8999f7a7555fe3baff6eebc84719285 Mon Sep 17 00:00:00 2001 From: Martin Lensment Date: Thu, 3 Jul 2014 18:17:00 +0300 Subject: [PATCH] Domain xsd + enable validation --- app/controllers/concerns/epp/common.rb | 25 +- app/controllers/epp/commands_controller.rb | 5 - doc/schemas/domain-1.0.xsd | 432 +++++++++++++++++++++ 3 files changed, 449 insertions(+), 13 deletions(-) create mode 100644 doc/schemas/domain-1.0.xsd diff --git a/app/controllers/concerns/epp/common.rb b/app/controllers/concerns/epp/common.rb index ea217a7ce..3038e0d7a 100644 --- a/app/controllers/concerns/epp/common.rb +++ b/app/controllers/concerns/epp/common.rb @@ -1,6 +1,11 @@ module Epp::Common extend ActiveSupport::Concern + OBJECT_TYPES = { + 'urn:ietf:params:xml:ns:contact-1.0' => 'contact', + 'urn:ietf:params:xml:ns:domain-1.0' => 'domain' + } + included do protect_from_forgery with: :null_session before_action :validate_request, only: [:proxy] @@ -24,13 +29,17 @@ module Epp::Common end def validate_request - # xsd = Nokogiri::XML::Schema(File.read('doc/schemas/contact-1.0.xsd')) - # doc = Nokogiri::XML(params[:frame]) - # @extValues = xsd.validate(doc) - # if @extValues.any? - # @code = '2001' - # @msg = 'Command syntax error' - # render '/epp/error' and return - # end + type = OBJECT_TYPES[params_hash['epp']['xmlns:ns2']] + return unless type + + xsd = Nokogiri::XML::Schema(File.read("doc/schemas/#{type}-1.0.xsd")) + doc = Nokogiri::XML(params[:frame]) + @extValues = xsd.validate(doc) + if @extValues.any? + binding.pry + @code = '2001' + @msg = 'Command syntax error' + render '/epp/error' and return + end end end diff --git a/app/controllers/epp/commands_controller.rb b/app/controllers/epp/commands_controller.rb index 602950a3d..fe2b0d054 100644 --- a/app/controllers/epp/commands_controller.rb +++ b/app/controllers/epp/commands_controller.rb @@ -3,11 +3,6 @@ class Epp::CommandsController < ApplicationController include Epp::DomainsHelper include Epp::ContactsHelper - OBJECT_TYPES = { - 'urn:ietf:params:xml:ns:contact-1.0' => 'contact', - 'urn:ietf:params:xml:ns:domain-1.0' => 'domain' - } - private def create send("create_#{OBJECT_TYPES[params_hash['epp']['xmlns:ns2']]}") diff --git a/doc/schemas/domain-1.0.xsd b/doc/schemas/domain-1.0.xsd new file mode 100644 index 000000000..d58e45c8c --- /dev/null +++ b/doc/schemas/domain-1.0.xsd @@ -0,0 +1,432 @@ + + + + + + + + + + + + Extensible Provisioning Protocol v1.0 + domain provisioning schema. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +