Add test & validation to not to register blocked IDN domains via EPP

Fixes https://github.com/internetee/registry/issues/1142#issuecomment-581889350
This commit is contained in:
Alex Sherman 2020-02-04 18:34:50 +05:00
parent 89cdfe20fc
commit 934033cfbc
2 changed files with 33 additions and 1 deletions

View file

@ -33,7 +33,9 @@ class DomainNameValidator < ActiveModel::EachValidator
def validate_blocked(value) def validate_blocked(value)
return true unless value return true unless value
return false if BlockedDomain.where(name: value).count.positive? return false if BlockedDomain.where(name: value).any?
return false if BlockedDomain.where(name: SimpleIDN.to_unicode(value)).any?
DNS::Zone.where(origin: value).count.zero? DNS::Zone.where(origin: value).count.zero?
end end
end end

View file

@ -144,6 +144,36 @@ class EppDomainCreateBaseTest < EppTestCase
assert_epp_response :data_management_policy_violation assert_epp_response :data_management_policy_violation
end end
def test_blocked_punicode_domain_cannot_be_registered
blocked_domain = 'blockedäöüõ.test'
assert BlockedDomain.find_by(name: blocked_domain)
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>
<create>
<domain:create xmlns:domain="https://epp.tld.ee/schema/domain-eis-1.0.xsd">
<domain:name>#{SimpleIDN.to_ascii('blockedäöüõ.test')}</domain:name>
<domain:registrant>#{contacts(:john).code}</domain:registrant>
</domain:create>
</create>
<extension>
<eis:extdata xmlns:eis="https://epp.tld.ee/schema/eis-1.0.xsd">
<eis:legalDocument type="pdf">#{'test' * 2000}</eis:legalDocument>
</eis:extdata>
</extension>
</command>
</epp>
XML
assert_no_difference 'Domain.count' do
post epp_create_path, params: { frame: request_xml },
headers: { 'HTTP_COOKIE' => 'session=api_bestnames' }
end
assert_epp_response :data_management_policy_violation
end
def test_reserved_domain_cannot_be_registered_with_wrong_registration_code def test_reserved_domain_cannot_be_registered_with_wrong_registration_code
request_xml = <<-XML request_xml = <<-XML
<?xml version="1.0" encoding="UTF-8" standalone="no"?> <?xml version="1.0" encoding="UTF-8" standalone="no"?>