request and response have the same domain schema

This commit is contained in:
Oleg Hasjanov 2021-06-22 12:59:56 +03:00
parent 230fb301a7
commit 6f431232f4
7 changed files with 28 additions and 8 deletions

View file

@ -4,6 +4,7 @@ module Epp
before_action :find_domain, only: %i[info renew update transfer delete]
before_action :find_password, only: %i[info update transfer delete]
before_action :set_paper_trail_whodunnit
before_action :parse_schemas_prefix_and_version
def info
authorize! :info, @domain
@ -243,5 +244,14 @@ module Epp
end
true
end
def parse_schemas_prefix_and_version
return unless params[:frame]
xml = params[:frame].gsub!(/(?<=>)(.*?)(?=<)/, &:strip).to_s
res = xml.match(/xmlns:domain=\"https:\/\/epp.tld.ee\/schema\/(?<prefix>\w+-\w+)-(?<version>\w.\w).xsd/)
@schema_version = res[:version]
@schema_prefix = res[:prefix]
end
end
end

View file

@ -5,7 +5,8 @@ xml.epp_head do
end
xml.resData do
xml.tag!('domain:chkData', 'xmlns:domain' => Xsd::Schema.filename(for_prefix: 'domain-ee')) do
xml.tag!('domain:chkData',
'xmlns:domain' => Xsd::Schema.filename(for_prefix: @schema_prefix)) do
@domains.each do |x|
xml.tag!('domain:cd') do
xml.tag!('domain:name', x[:name], 'avail' => x[:avail])

View file

@ -5,7 +5,8 @@ xml.epp_head do
end
xml.resData do
xml.tag!('domain:creData', 'xmlns:domain' => Xsd::Schema.filename(for_prefix: 'domain-ee')) do
xml.tag!('domain:creData',
'xmlns:domain' => Xsd::Schema.filename(for_prefix: @schema_prefix)) do
xml.tag!('domain:name', @domain.name)
xml.tag!('domain:crDate', @domain.created_at.try(:iso8601))
xml.tag!('domain:exDate', @domain.valid_to.iso8601)

View file

@ -5,7 +5,8 @@ xml.epp_head do
end
xml.resData do
xml.tag! 'domain:infData', 'xmlns:domain' => Xsd::Schema.filename(for_prefix: 'domain-ee') do
xml.tag! 'domain:infData',
'xmlns:domain' => Xsd::Schema.filename(for_prefix: @schema_prefix) do
xml.tag!('domain:name', @domain.name)
xml.tag!('domain:roid', @domain.roid)
@domain.statuses.each do |s|

View file

@ -5,7 +5,8 @@ xml.epp_head do
end
xml.resData do
xml.tag!('domain:renData', 'xmlns:domain' => Xsd::Schema.filename(for_prefix: 'domain-ee')) do
xml.tag!('domain:renData',
'xmlns:domain' => Xsd::Schema.filename(for_prefix: @schema_prefix)) do
xml.tag!('domain:name', @domain[:name])
xml.tag!('domain:exDate', @domain.valid_to.iso8601)
end

View file

@ -77,12 +77,12 @@ class EppDomainInfoBaseTest < EppTestCase
post epp_info_path, params: { frame: request_xml },
headers: { 'HTTP_COOKIE' => 'session=api_bestnames' }
response_xml = Nokogiri::XML(response.body)
assert_epp_response :completed_successfully
schema = EPP_ALL_SCHEMA
schema_validation_errors = schema.validate(response_xml)
assert_equal 0, schema_validation_errors.size
res = parsing_schemas_prefix_and_version(response.body)
assert_equal res[:prefix], 'domain-eis'
assert_equal res[:version], '1.0'
end
def test_returns_valid_response_if_disputed

View file

@ -95,4 +95,10 @@ class EppTestCase < ActionDispatch::IntegrationTest
raise Exception.new('Wrong prefix')
end
end
# The prefix and version of the response are returned are these variants - res[:prefix] res[:version]
def parsing_schemas_prefix_and_version(response)
xml = response.gsub!(/(?<=>)(.*?)(?=<)/, &:strip)
xml.to_s.match(/xmlns:domain=\"https:\/\/epp.tld.ee\/schema\/(?<prefix>\w+-\w+)-(?<version>\w.\w).xsd/)
end
end