Skip to content

Commit

Permalink
rollback
Browse files Browse the repository at this point in the history
  • Loading branch information
OlegPhenomenon committed Aug 5, 2024
1 parent 0259b8c commit 2a41048
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 34 deletions.
9 changes: 1 addition & 8 deletions app/models/reserved_domain.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ class ReservedDomain < ApplicationRecord
before_save :sync_dispute_password
after_destroy :remove_data

before_validation :normalize_name, on: %w[create, update]
validates :name, domain_name: true, uniqueness: true

alias_attribute :registration_code, :password
Expand Down Expand Up @@ -41,7 +40,7 @@ def new_password_for(name)
end

def name=(val)
super SimpleIDN.to_unicode(val).mb_chars.downcase.strip
super SimpleIDN.to_unicode(val)
end

def fill_empty_passwords
Expand Down Expand Up @@ -70,10 +69,4 @@ def generate_data
def remove_data
UpdateWhoisRecordJob.perform_later name, 'reserved'
end

private

def normalize_name
self.name = SimpleIDN.to_unicode(name).mb_chars.downcase.strip
end
end
9 changes: 2 additions & 7 deletions app/validators/domain_name_validator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,7 @@ class DomainNameValidator < ActiveModel::EachValidator
# rubocop:disable Metrics/CyclomaticComplexity
# rubocop:disable Metrics/LineLength
def validate_each(record, attribute, value)
origins = DNS::Zone.origins

if origins.include?(value)
record.errors.add(:base, :domain_name_blocked)
elsif !self.class.validate_format(value)
if !self.class.validate_format(value)
record.errors.add(attribute, options[:message] || record.errors.generate_message(attribute, :invalid))
elsif !self.class.validate_blocked(value)
record.errors.add(:base, :domain_name_blocked)
Expand All @@ -22,7 +18,7 @@ def validate_format(value)
origins = DNS::Zone.origins
# if someone tries to register an origin domain, let this validation pass
# the error will be caught in blocked domains validator
return false unless origins.include?(value.split('.').last)
return true if origins.include?(value)

general_domains = /(#{origins.join('|')})/

Expand All @@ -32,7 +28,6 @@ def validate_format(value)
return false unless value.match?(regexp)

value = SimpleIDN.to_unicode(value).mb_chars.downcase.strip

end

unicode_chars = /\u00E4\u00F5\u00F6\u00FC\u0161\u017E/ # äõöüšž
Expand Down
19 changes: 0 additions & 19 deletions test/models/reserved_domain_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,23 +13,4 @@ def test_aliases_registration_code_to_password
reserved_domain = ReservedDomain.new(password: 'reserved-001')
assert_equal 'reserved-001', reserved_domain.registration_code
end

def test_create_reserved_domain_with_punycode_name
reserved_domain = ReservedDomain.create(name: 'xn--4ca7aey.test')
assert reserved_domain.valid?
end

def test_create_reserved_domain_with_unicode_name
reserved_domain = ReservedDomain.create(name: 'õäöü.test')
assert reserved_domain.valid?
end

def test_cannot_create_the_same_domain_twicde_with_punycode_and_unicode
punycode_reserved_domain = ReservedDomain.new(name: 'xn--4ca7aey.test')
assert punycode_reserved_domain.valid?
punycode_reserved_domain.save && punycode_reserved_domain.reload

unicode_reserved_domain = ReservedDomain.new(name: 'õäöü.test')
assert_not unicode_reserved_domain.valid?
end
end

0 comments on commit 2a41048

Please sign in to comment.