Make domain unavailable when zone with the same origin exists

This commit is contained in:
Artur Beljajev 2019-01-07 03:20:55 +02:00
parent ee864c807f
commit d40dc28484
5 changed files with 41 additions and 3 deletions

View file

@ -7,7 +7,7 @@ module DNS
end
def unavailable?
registered? || blocked?
registered? || blocked? || zone_with_same_origin?
end
def unavailability_reason
@ -15,6 +15,8 @@ module DNS
:registered
elsif blocked?
:blocked
elsif zone_with_same_origin?
:zone_with_same_origin
end
end
@ -29,5 +31,9 @@ module DNS
def blocked?
BlockedDomain.where(name: name).any?
end
def zone_with_same_origin?
DNS::Zone.where(origin: name).any?
end
end
end

View file

@ -805,8 +805,8 @@ class Epp::Domain < Domain
domain_name = DNS::DomainName.new(domain_name_as_string)
if domain_name.unavailable?
reason = domain_name.unavailability_reason
result << { name: domain_name_as_string, avail: 0, reason: I18n.t("errors.messages.epp_domain_#{reason}") }
reason = I18n.t("errors.messages.epp_domain_#{domain_name.unavailability_reason}")
result << { name: domain_name_as_string, avail: 0, reason: reason }
next
end

View file

@ -198,6 +198,7 @@ en:
blank: 'is missing'
epp_domain_registered: in use
epp_domain_blocked: Blocked
epp_domain_zone_with_same_origin: Zone with the same origin exists
epp_obj_does_not_exist: 'Object does not exist'
epp_authorization_error: 'Authorization error'
epp_id_taken: 'Contact id already exists'

View file

@ -134,6 +134,29 @@ class EppDomainCheckBaseTest < ApplicationIntegrationTest
assert_equal 'Blocked', response_xml.at_xpath('//domain:reason', 'domain' => 'https://epp.tld.ee/schema/domain-eis-1.0.xsd').text
end
def test_domain_is_unavailable_when_zone_with_the_same_origin_exists
assert_equal 'test', dns_zones(:one).origin
request_xml = <<-XML
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<epp xmlns="https://epp.tld.ee/schema/epp-ee-1.0.xsd">
<command>
<check>
<domain:check xmlns:domain="https://epp.tld.ee/schema/domain-eis-1.0.xsd">
<domain:name>test</domain:name>
</domain:check>
</check>
</command>
</epp>
XML
post '/epp/command/check', { frame: request_xml }, 'HTTP_COOKIE' => 'session=api_bestnames'
response_xml = Nokogiri::XML(response.body)
assert_equal '0', response_xml.at_xpath('//domain:name', 'domain' => 'https://epp.tld.ee/schema/domain-eis-1.0.xsd')['avail']
assert_equal 'Zone with the same origin exists', response_xml.at_xpath('//domain:reason', 'domain' => 'https://epp.tld.ee/schema/domain-eis-1.0.xsd').text
end
def test_multiple_domains
request_xml = <<-XML
<?xml version="1.0" encoding="UTF-8" standalone="no"?>

View file

@ -16,4 +16,12 @@ class DNS::DomainNameTest < ActiveSupport::TestCase
assert domain_name.unavailable?
assert_equal :blocked, domain_name.unavailability_reason
end
def test_unavailable_when_zone_with_the_same_origin_exists
domain_name = DNS::DomainName.new('test')
assert_equal 'test', dns_zones(:one).origin
assert domain_name.unavailable?
assert_equal :zone_with_same_origin, domain_name.unavailability_reason
end
end