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 c0915e7
Show file tree
Hide file tree
Showing 7 changed files with 12 additions and 44 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
3 changes: 0 additions & 3 deletions test/fixtures/reserved_domains.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,3 @@ one:
name: reserved.test
password: reserved-001

two:
name: company-name.test
password: company-002
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ class Api::V1::BusinessRegistry::DomainNamesControllerTest < ActionDispatch::Int
assert_response :success
assert_equal @allowed_origins.first, response.headers['Access-Control-Allow-Origin']
json_response = JSON.parse(response.body)
assert_includes json_response['variants'], 'testcompany'
assert_includes json_response['variants'], 'test-company'
assert_includes json_response['variants'], 'test_company'
assert_includes json_response['variants'], 'testcompanyas'
assert_includes json_response['variants'], 'test-company-as'
assert_includes json_response['variants'], 'test_company_as'
assert_includes json_response['variants'], "testcompany#{Time.current.year}"
end

Expand Down
2 changes: 2 additions & 0 deletions test/integration/repp/v1/retained_domains_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ def test_get_index_with_type_parameter
get repp_v1_retained_domains_path({ 'type' => 'reserved' })
response_json = JSON.parse(response.body, symbolize_names: true)

puts response_json

assert response_json[:count] == 1

expected_objects = [{ name: 'reserved.test',
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
8 changes: 4 additions & 4 deletions test/services/eis_billing_system/get_invoice_number_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ class GetInvoiceNumberTest < ActionDispatch::IntegrationTest
setup do
@original_base_url = ENV['eis_billing_system_base_url']
@original_billing_secret = ENV['billing_secret']
ENV['eis_billing_system_base_url'] = 'https://test-billing.example.com'
ENV['eis_billing_system_base_url'] = 'http://eis_billing_system:3000'
ENV['billing_secret'] = 'test_secret'
end

Expand All @@ -17,15 +17,15 @@ class GetInvoiceNumberTest < ActionDispatch::IntegrationTest
test "call returns expected result" do
expected_response = '{"invoice_number": "12345"}'

stub_request(:post, "https://test-billing.example.com/api/v1/invoice_generator/invoice_number_generator")
stub_request(:post, "http://eis_billing_system:3000/api/v1/invoice_generator/invoice_number_generator")
.to_return(status: 200, body: expected_response, headers: { 'Content-Type' => 'application/json' })

result = EisBilling::GetInvoiceNumber.call

assert_equal expected_response, result.body
assert_equal '200', result.code

assert_requested :post, "https://test-billing.example.com/api/v1/invoice_generator/invoice_number_generator", {
assert_requested :post, "http://eis_billing_system:3000/api/v1/invoice_generator/invoice_number_generator", {
headers: {
'Content-Type' => 'application/json',
'Authorization' => /^Bearer .+$/
Expand All @@ -35,7 +35,7 @@ class GetInvoiceNumberTest < ActionDispatch::IntegrationTest
end

test "invoice_number_generator_url returns correct URL" do
expected_url = "https://test-billing.example.com/api/v1/invoice_generator/invoice_number_generator"
expected_url = "http://eis_billing_system:3000/api/v1/invoice_generator/invoice_number_generator"
assert_equal expected_url, EisBilling::GetInvoiceNumber.send(:invoice_number_generator_url)
end

Expand Down

0 comments on commit c0915e7

Please sign in to comment.