diff --git a/app/models/dns/domain_name.rb b/app/models/dns/domain_name.rb index 0f8e7d4b0..f388a975d 100644 --- a/app/models/dns/domain_name.rb +++ b/app/models/dns/domain_name.rb @@ -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 diff --git a/app/models/epp/domain.rb b/app/models/epp/domain.rb index 09eb49481..4e3d20305 100644 --- a/app/models/epp/domain.rb +++ b/app/models/epp/domain.rb @@ -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 diff --git a/config/locales/en.yml b/config/locales/en.yml index ebf5b5b15..a01604919 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -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' diff --git a/test/integration/epp/domain/check/base_test.rb b/test/integration/epp/domain/check/base_test.rb index 8185ef5fd..65e746947 100644 --- a/test/integration/epp/domain/check/base_test.rb +++ b/test/integration/epp/domain/check/base_test.rb @@ -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 + + + + + + test + + + + + 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 diff --git a/test/models/dns/domain_name_test.rb b/test/models/dns/domain_name_test.rb index 122803e0e..c0445cf9e 100644 --- a/test/models/dns/domain_name_test.rb +++ b/test/models/dns/domain_name_test.rb @@ -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