mirror of
https://github.com/internetee/registry.git
synced 2025-07-20 09:46:09 +02:00
added tests
This commit is contained in:
parent
1665e6e71e
commit
8ef0692ca9
2 changed files with 59 additions and 31 deletions
|
@ -3,6 +3,9 @@ module Xsd
|
||||||
SCHEMA_PATH = 'lib/schemas/'.freeze
|
SCHEMA_PATH = 'lib/schemas/'.freeze
|
||||||
BASE_URL = 'https://epp.tld.ee/schema/'.freeze
|
BASE_URL = 'https://epp.tld.ee/schema/'.freeze
|
||||||
|
|
||||||
|
REGEX_PREFIX_WITH_DASH = /(?<prefix>\w+-\w+)-(?<version>\w.\w).xsd/
|
||||||
|
REGEX_PREFIX_WITHOUT_DASH = /(?<prefix>\w+)-(?<version>\w.\w).xsd/
|
||||||
|
|
||||||
PREFIXES = %w[
|
PREFIXES = %w[
|
||||||
domain-ee
|
domain-ee
|
||||||
domain-eis
|
domain-eis
|
||||||
|
@ -24,7 +27,7 @@ module Xsd
|
||||||
def initialize(params)
|
def initialize(params)
|
||||||
schema_path = params.fetch(:schema_path, SCHEMA_PATH)
|
schema_path = params.fetch(:schema_path, SCHEMA_PATH)
|
||||||
@for_prefix = params.fetch(:for_prefix)
|
@for_prefix = params.fetch(:for_prefix)
|
||||||
@for_version = params.fetch(:for_version, '1.1')
|
@for_version = params.fetch(:for_version, '1.1')
|
||||||
@xsd_schemas = Dir.entries(schema_path).select { |f| File.file? File.join(schema_path, f) }
|
@xsd_schemas = Dir.entries(schema_path).select { |f| File.file? File.join(schema_path, f) }
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -33,47 +36,32 @@ module Xsd
|
||||||
end
|
end
|
||||||
|
|
||||||
def call
|
def call
|
||||||
filename = latest(for_prefix)
|
filename = get_schema(for_prefix)
|
||||||
BASE_URL + filename
|
BASE_URL + filename
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
# xml = response.gsub!(/(?<=>)(.*?)(?=<)/, &:strip)
|
def get_schema(prefix)
|
||||||
# xml.to_s.match(/xmlns:domain=\"https:\/\/epp.tld.ee\/schema\/(?<prefix>\w+-\w+)-(?<version>\w.\w).xsd/)
|
actual_schema = ''
|
||||||
# The prefix and version of the response are returned are these variants - res[:prefix] res[:version]
|
|
||||||
|
|
||||||
def latest(prefix)
|
|
||||||
schemas = schemas_by_name[prefix]
|
schemas = schemas_by_name[prefix]
|
||||||
|
|
||||||
actual_schema = ''
|
schemas.each do |schema|
|
||||||
|
result = return_some(schema)
|
||||||
|
actual_schema = schema if result[:version] == @for_version
|
||||||
|
|
||||||
schemas.each do |schema|
|
actual_schema = 'epp-ee-1.0.xsd' if result[:prefix] == 'epp-ee'
|
||||||
result = return_some(schema)
|
actual_schema = 'eis-1.0.xsd' if result[:prefix] == 'eis'
|
||||||
|
end
|
||||||
|
|
||||||
if result[:version] == @for_version
|
actual_schema
|
||||||
actual_schema = schema
|
|
||||||
end
|
|
||||||
|
|
||||||
if result[:prefix] == 'epp-ee'
|
|
||||||
actual_schema = 'epp-ee-1.0.xsd'
|
|
||||||
end
|
|
||||||
|
|
||||||
if result[:prefix] == 'eis'
|
|
||||||
actual_schema = 'eis-1.0.xsd'
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
actual_schema
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def return_some(data)
|
def return_some(data)
|
||||||
res = data.to_s.match(/(?<prefix>\w+-\w+)-(?<version>\w.\w).xsd/)
|
res = data.to_s.match(REGEX_PREFIX_WITH_DASH)
|
||||||
|
res = data.to_s.match(REGEX_PREFIX_WITHOUT_DASH) if res.nil?
|
||||||
res = data.to_s.match(/(?<prefix>\w+)-(?<version>\w.\w).xsd/) if res.nil?
|
res
|
||||||
|
end
|
||||||
res
|
|
||||||
end
|
|
||||||
|
|
||||||
def basename(filename)
|
def basename(filename)
|
||||||
File.basename(filename, '.xsd')
|
File.basename(filename, '.xsd')
|
||||||
|
|
|
@ -48,6 +48,46 @@ class EppDomainInfoBaseTest < EppTestCase
|
||||||
'domain' => Xsd::Schema.filename(for_prefix: 'domain-ee').to_s).text
|
'domain' => Xsd::Schema.filename(for_prefix: 'domain-ee').to_s).text
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_return_wrong_schema_with_invalid_version
|
||||||
|
request_xml = <<-XML
|
||||||
|
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||||
|
<epp xmlns="#{Xsd::Schema.filename(for_prefix: 'epp-ee')}">
|
||||||
|
<command>
|
||||||
|
<info>
|
||||||
|
<domain:info xmlns:domain="#{Xsd::Schema.filename(for_prefix: 'domain-ee', for_version: '1.0')}">
|
||||||
|
<domain:name>shop.test</domain:name>
|
||||||
|
</domain:info>
|
||||||
|
</info>
|
||||||
|
</command>
|
||||||
|
</epp>
|
||||||
|
XML
|
||||||
|
|
||||||
|
post epp_info_path, params: { frame: request_xml },
|
||||||
|
headers: { 'HTTP_COOKIE' => 'session=api_bestnames' }
|
||||||
|
|
||||||
|
assert_epp_response :wrong_schema
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_return_valid_response_if_specify_the_version
|
||||||
|
request_xml = <<-XML
|
||||||
|
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||||
|
<epp xmlns="#{Xsd::Schema.filename(for_prefix: 'epp-ee')}">
|
||||||
|
<command>
|
||||||
|
<info>
|
||||||
|
<domain:info xmlns:domain="#{Xsd::Schema.filename(for_prefix: 'domain-ee', for_version: '1.1')}">
|
||||||
|
<domain:name>shop.test</domain:name>
|
||||||
|
</domain:info>
|
||||||
|
</info>
|
||||||
|
</command>
|
||||||
|
</epp>
|
||||||
|
XML
|
||||||
|
|
||||||
|
post epp_info_path, params: { frame: request_xml },
|
||||||
|
headers: { 'HTTP_COOKIE' => 'session=api_bestnames' }
|
||||||
|
|
||||||
|
assert_epp_response :completed_successfully
|
||||||
|
end
|
||||||
|
|
||||||
def test_returns_valid_response_if_schema_version_is_previous
|
def test_returns_valid_response_if_schema_version_is_previous
|
||||||
dispute = disputes(:expired)
|
dispute = disputes(:expired)
|
||||||
dispute.update!(starts_at: Time.zone.now, expires_at: Time.zone.now + 5.days, closed: nil)
|
dispute.update!(starts_at: Time.zone.now, expires_at: Time.zone.now + 5.days, closed: nil)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue