mirror of
https://github.com/internetee/registry.git
synced 2025-06-10 14:44:47 +02:00
Merge pull request #1628 from internetee/1625-single-character-domains
Add support of single-character domains
This commit is contained in:
commit
72619d7e23
3 changed files with 28 additions and 6 deletions
|
@ -1,4 +1,6 @@
|
||||||
class DomainNameValidator < ActiveModel::EachValidator
|
class DomainNameValidator < ActiveModel::EachValidator
|
||||||
|
# rubocop:disable Metrics/CyclomaticComplexity
|
||||||
|
# rubocop:disable Metrics/LineLength
|
||||||
def validate_each(record, attribute, value)
|
def validate_each(record, attribute, value)
|
||||||
if !self.class.validate_format(value)
|
if !self.class.validate_format(value)
|
||||||
record.errors[attribute] << (options[:message] || record.errors.generate_message(attribute, :invalid))
|
record.errors[attribute] << (options[:message] || record.errors.generate_message(attribute, :invalid))
|
||||||
|
@ -27,8 +29,9 @@ class DomainNameValidator < ActiveModel::EachValidator
|
||||||
end
|
end
|
||||||
|
|
||||||
unicode_chars = /\u00E4\u00F5\u00F6\u00FC\u0161\u017E/ # äõöüšž
|
unicode_chars = /\u00E4\u00F5\u00F6\u00FC\u0161\u017E/ # äõöüšž
|
||||||
regexp = /\A[a-zA-Z0-9#{unicode_chars.source}][a-zA-Z0-9#{unicode_chars.source}-]{0,61}[a-zA-Z0-9#{unicode_chars.source}]\.#{general_domains.source}\z/
|
regexp = /\A[a-zA-Z0-9#{unicode_chars.source}][a-zA-Z0-9#{unicode_chars.source}-]{0,62}\.#{general_domains.source}\z/
|
||||||
!!(value =~ regexp)
|
end_regexp = /\-\.#{general_domains.source}\z/ # should not contain dash as a closing char
|
||||||
|
!!(value =~ regexp && value !~ end_regexp)
|
||||||
end
|
end
|
||||||
|
|
||||||
def validate_blocked(value)
|
def validate_blocked(value)
|
||||||
|
@ -39,4 +42,6 @@ class DomainNameValidator < ActiveModel::EachValidator
|
||||||
DNS::Zone.where(origin: value).count.zero?
|
DNS::Zone.where(origin: value).count.zero?
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
# rubocop:enable Metrics/CyclomaticComplexity
|
||||||
|
# rubocop:enable Metrics/LineLength
|
||||||
end
|
end
|
||||||
|
|
|
@ -0,0 +1,20 @@
|
||||||
|
class FillSingleCharactedBlockedDomains < ActiveRecord::Migration[6.0]
|
||||||
|
|
||||||
|
DOMAIN_NAMES = %w[a.ee b.ee c.ee d.ee e.ee f.ee g.ee h.ee i.ee j.ee k.ee l.ee m.ee n.ee o.ee
|
||||||
|
p.ee q.ee r.ee s.ee š.ee z.ee ž.ee t.ee u.ee v.ee w.ee õ.ee ä.ee ö.ee ü.ee
|
||||||
|
x.ee y.ee 0.ee 1.ee 2.ee 3.ee 4.ee 5.ee 6.ee 7.ee 8.ee 9.ee].freeze
|
||||||
|
|
||||||
|
def up
|
||||||
|
BlockedDomain.transaction do
|
||||||
|
DOMAIN_NAMES.each do |name|
|
||||||
|
BlockedDomain.find_or_create_by(name: name)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def down
|
||||||
|
BlockedDomain.transaction do
|
||||||
|
BlockedDomain.by_domain(DOMAIN_NAMES).delete_all
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
|
@ -31,7 +31,7 @@ class DomainTest < ActiveSupport::TestCase
|
||||||
def test_validates_name_format
|
def test_validates_name_format
|
||||||
assert_equal dns_zones(:one).origin, 'test'
|
assert_equal dns_zones(:one).origin, 'test'
|
||||||
domain = valid_domain
|
domain = valid_domain
|
||||||
subdomain_min_length = 2
|
subdomain_min_length = 1
|
||||||
subdomain_max_length = 63
|
subdomain_max_length = 63
|
||||||
|
|
||||||
domain.name = '!invalid'
|
domain.name = '!invalid'
|
||||||
|
@ -46,9 +46,6 @@ class DomainTest < ActiveSupport::TestCase
|
||||||
domain.name = 'example-.test'
|
domain.name = 'example-.test'
|
||||||
assert domain.invalid?
|
assert domain.invalid?
|
||||||
|
|
||||||
domain.name = "#{'a' * subdomain_min_length.pred}.test"
|
|
||||||
assert domain.invalid?
|
|
||||||
|
|
||||||
domain.name = "#{'a' * subdomain_max_length.next}.test"
|
domain.name = "#{'a' * subdomain_max_length.next}.test"
|
||||||
assert domain.invalid?
|
assert domain.invalid?
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue