mirror of
https://github.com/internetee/registry.git
synced 2025-05-17 09:57:23 +02:00
Cleanup #2752
This commit is contained in:
parent
c38680a3b1
commit
1d82fb9052
3 changed files with 12 additions and 5 deletions
|
@ -10,9 +10,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'].include?(params[:action])
|
return if ['hello', 'error', 'keyrelay'].include?(params[:action])
|
||||||
params[:schema] = 'epp-1.0.xsd' unless params[:schema]
|
schema.validate(params[:nokogiri_frame]).each do |error|
|
||||||
xsd = Nokogiri::XML::Schema(File.read("lib/schemas/#{params[:schema]}"))
|
|
||||||
xsd.validate(params[:nokogiri_frame]).each do |error|
|
|
||||||
epp_errors << {
|
epp_errors << {
|
||||||
code: 2001,
|
code: 2001,
|
||||||
msg: error
|
msg: error
|
||||||
|
@ -73,6 +71,13 @@ class EppController < ApplicationController
|
||||||
render_epp_response '/epp/error'
|
render_epp_response '/epp/error'
|
||||||
end
|
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
|
def generate_svtrid
|
||||||
# rubocop: disable Style/VariableName
|
# rubocop: disable Style/VariableName
|
||||||
@svTRID = "ccReg-#{format('%010d', rand(10**10))}"
|
@svTRID = "ccReg-#{format('%010d', rand(10**10))}"
|
||||||
|
|
3
config/initializers/load_schemas.rb
Normal file
3
config/initializers/load_schemas.rb
Normal 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"))
|
|
@ -10,14 +10,13 @@ class EppConstraint
|
||||||
|
|
||||||
# creates parsed_frame, detects epp request object
|
# creates parsed_frame, detects epp request object
|
||||||
def matches?(request)
|
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[: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, :not_found].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
|
|
||||||
request.params[:schema] = OBJECT_TYPES[@type][@type].split('/').last
|
|
||||||
end
|
end
|
||||||
|
|
||||||
request.params[:epp_object_type] = @type
|
request.params[:epp_object_type] = @type
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue