mirror of
https://github.com/internetee/registry.git
synced 2025-05-30 09:30:03 +02:00
Validate origin domains #2849
This commit is contained in:
parent
71b2763df6
commit
5ba39fb406
23 changed files with 99 additions and 24 deletions
|
@ -29,7 +29,6 @@ class Epp::DomainsController < EppController
|
|||
handle_errors(@domain) and return if @domain.errors.any?
|
||||
|
||||
handle_errors and return unless balance_ok?('create')
|
||||
|
||||
ActiveRecord::Base.transaction do
|
||||
if @domain.save # TODO: Maybe use validate: false here because we have already validated the domain?
|
||||
current_user.registrar.debit!({
|
||||
|
|
|
@ -9,22 +9,27 @@ class DomainNameValidator < ActiveModel::EachValidator
|
|||
|
||||
class << self
|
||||
def validate_format(value)
|
||||
return true if value == 'ee'
|
||||
return true unless value
|
||||
value = value.mb_chars.downcase.strip
|
||||
|
||||
general_domains = /(.pri.ee|.com.ee|.fie.ee|.med.ee|.ee)/
|
||||
origins = ZonefileSetting.pluck(:origin)
|
||||
# if someone tries to register an origin domain, let this validation pass
|
||||
# the error will be catched in blocked domains validator
|
||||
return true if origins.include?(value)
|
||||
|
||||
general_domains = /(#{origins.join('|')})/
|
||||
# general_domains = /(.pri.ee|.com.ee|.fie.ee|.med.ee|.ee)/
|
||||
|
||||
# it's punycode
|
||||
if value[2] == '-' && value[3] == '-'
|
||||
regexp = /\Axn--[a-zA-Z0-9-]{0,59}#{general_domains}\z/
|
||||
regexp = /\Axn--[a-zA-Z0-9-]{0,59}\.#{general_domains}\z/
|
||||
return false unless value =~ regexp
|
||||
value = SimpleIDN.to_unicode(value).mb_chars.downcase.strip
|
||||
end
|
||||
|
||||
# rubocop: disable Metrics/LineLength
|
||||
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,61}[a-zA-Z0-9#{unicode_chars.source}]\.#{general_domains.source}\z/
|
||||
# rubocop: enable Metrics/LineLength
|
||||
# rubocop: disable Style/DoubleNegation
|
||||
!!(value =~ regexp)
|
||||
|
|
|
@ -3,6 +3,12 @@ require 'rails_helper'
|
|||
describe 'EPP Contact', epp: true do
|
||||
before :all do
|
||||
@xsd = Nokogiri::XML::Schema(File.read('lib/schemas/contact-eis-1.0.xsd'))
|
||||
Fabricate(:zonefile_setting, origin: 'ee')
|
||||
Fabricate(:zonefile_setting, origin: 'pri.ee')
|
||||
Fabricate(:zonefile_setting, origin: 'med.ee')
|
||||
Fabricate(:zonefile_setting, origin: 'fie.ee')
|
||||
Fabricate(:zonefile_setting, origin: 'com.ee')
|
||||
|
||||
@registrar1 = Fabricate(:registrar1)
|
||||
@registrar2 = Fabricate(:registrar2)
|
||||
@epp_xml = EppXml::Contact.new(cl_trid: 'ABC-12345')
|
||||
|
|
|
@ -4,6 +4,13 @@ describe 'EPP Domain', epp: true do
|
|||
before(:all) do
|
||||
@xsd = Nokogiri::XML::Schema(File.read('lib/schemas/domain-eis-1.0.xsd'))
|
||||
@epp_xml = EppXml.new(cl_trid: 'ABC-12345')
|
||||
|
||||
Fabricate(:zonefile_setting, origin: 'ee')
|
||||
Fabricate(:zonefile_setting, origin: 'pri.ee')
|
||||
Fabricate(:zonefile_setting, origin: 'med.ee')
|
||||
Fabricate(:zonefile_setting, origin: 'fie.ee')
|
||||
Fabricate(:zonefile_setting, origin: 'com.ee')
|
||||
|
||||
@registrar1 = Fabricate(:registrar1, code: 'REGDOMAIN1')
|
||||
@registrar1.credit!({ sum: 10000 })
|
||||
@registrar2 = Fabricate(:registrar2, code: 'REGDOMAIN2')
|
||||
|
|
|
@ -2,6 +2,7 @@ require 'rails_helper'
|
|||
|
||||
describe 'EPP Keyrelay', epp: true do
|
||||
before(:all) do
|
||||
Fabricate(:zonefile_setting, origin: 'ee')
|
||||
@registrar1 = Fabricate(:registrar1)
|
||||
@registrar2 = Fabricate(:registrar2)
|
||||
@domain = Fabricate(:domain, registrar: @registrar2)
|
||||
|
|
|
@ -2,6 +2,7 @@ require 'rails_helper'
|
|||
|
||||
feature 'BlockedDomain', type: :feature do
|
||||
before :all do
|
||||
Fabricate(:zonefile_setting, origin: 'ee')
|
||||
@user = Fabricate(:admin_user)
|
||||
end
|
||||
|
||||
|
|
|
@ -2,6 +2,8 @@ require 'rails_helper'
|
|||
|
||||
feature 'Domain', type: :feature do
|
||||
before :all do
|
||||
Fabricate(:zonefile_setting, origin: 'ee')
|
||||
Fabricate(:zonefile_setting, origin: 'pri.ee')
|
||||
@user = Fabricate(:admin_user)
|
||||
end
|
||||
|
||||
|
|
|
@ -2,6 +2,7 @@ require 'rails_helper'
|
|||
|
||||
feature 'ReservedDomain', type: :feature do
|
||||
before :all do
|
||||
Fabricate(:zonefile_setting, origin: 'ee')
|
||||
@user = Fabricate(:admin_user)
|
||||
end
|
||||
|
||||
|
|
|
@ -1,6 +1,10 @@
|
|||
require 'rails_helper'
|
||||
|
||||
feature 'DomainDeleteConfirm', type: :feature do
|
||||
before :all do
|
||||
Fabricate(:zonefile_setting, origin: 'ee')
|
||||
end
|
||||
|
||||
context 'as unknown user with domain without token' do
|
||||
before :all do
|
||||
@domain = Fabricate(:domain)
|
||||
|
|
|
@ -1,6 +1,10 @@
|
|||
require 'rails_helper'
|
||||
|
||||
feature 'DomainUpdateConfirm', type: :feature do
|
||||
before :all do
|
||||
Fabricate(:zonefile_setting, origin: 'ee')
|
||||
end
|
||||
|
||||
context 'as unknown user with domain without update token' do
|
||||
before :all do
|
||||
@domain = Fabricate(:domain)
|
||||
|
|
|
@ -2,6 +2,8 @@ require 'rails_helper'
|
|||
|
||||
feature 'Domains', type: :feature do
|
||||
before :all do
|
||||
Fabricate(:zonefile_setting, origin: 'ee')
|
||||
Fabricate(:zonefile_setting, origin: 'pri.ee')
|
||||
@user = Fabricate(:api_user)
|
||||
end
|
||||
|
||||
|
@ -58,7 +60,9 @@ feature 'Domains', type: :feature do
|
|||
|
||||
it 'should search domains' do
|
||||
# having shared state across tests is really annoying sometimes...
|
||||
click_link "#{@user} (#{@user.roles.first}) - #{@user.registrar}"
|
||||
within('.dropdown-menu') do
|
||||
click_link "#{@user} (#{@user.roles.first}) - #{@user.registrar}"
|
||||
end
|
||||
|
||||
Fabricate(:domain, name: 'abcde.ee', registrar: @user.registrar)
|
||||
Fabricate(:domain, name: 'abcdee.ee', registrar: @user.registrar)
|
||||
|
|
|
@ -2,6 +2,7 @@ require 'rails_helper'
|
|||
|
||||
feature 'Sessions', type: :feature do
|
||||
before :all do
|
||||
Fabricate(:zonefile_setting, origin: 'ee')
|
||||
@user = Fabricate(:ee_user)
|
||||
@registrar1 = Fabricate(:registrar1)
|
||||
@registrar2 = Fabricate(:registrar2)
|
||||
|
|
|
@ -26,6 +26,7 @@ describe ContactMailer do
|
|||
|
||||
describe 'email changed notification' do
|
||||
before :all do
|
||||
Fabricate(:zonefile_setting, origin: 'ee')
|
||||
@domain = Fabricate(:domain)
|
||||
@contact = @domain.registrant
|
||||
@contact.reload # until figured out why registrant_domains not loaded
|
||||
|
|
|
@ -1,6 +1,10 @@
|
|||
require 'rails_helper'
|
||||
|
||||
describe DomainMailer do
|
||||
before :all do
|
||||
Fabricate(:zonefile_setting, origin: 'ee')
|
||||
end
|
||||
|
||||
describe 'pending update request for an old registrant when delivery turned off' do
|
||||
before :all do
|
||||
@registrant = Fabricate(:registrant, email: 'test@example.com')
|
||||
|
|
|
@ -2,6 +2,7 @@ require 'rails_helper'
|
|||
|
||||
describe Contact do
|
||||
before :all do
|
||||
Fabricate(:zonefile_setting, origin: 'ee')
|
||||
@api_user = Fabricate(:api_user)
|
||||
end
|
||||
|
||||
|
@ -383,6 +384,7 @@ end
|
|||
|
||||
describe Contact, '.destroy_orphans' do
|
||||
before do
|
||||
Fabricate(:zonefile_setting, origin: 'ee')
|
||||
@contact_1 = Fabricate(:contact, code: 'asd12')
|
||||
@contact_2 = Fabricate(:contact, code: 'asd13')
|
||||
end
|
||||
|
|
|
@ -1,6 +1,10 @@
|
|||
require 'rails_helper'
|
||||
|
||||
describe Dnskey do
|
||||
before :all do
|
||||
Fabricate(:zonefile_setting, origin: 'ee')
|
||||
end
|
||||
|
||||
it { should belong_to(:domain) }
|
||||
|
||||
context 'with invalid attribute' do
|
||||
|
|
|
@ -1,6 +1,14 @@
|
|||
require 'rails_helper'
|
||||
|
||||
describe Domain do
|
||||
before :all do
|
||||
Fabricate(:zonefile_setting, origin: 'ee')
|
||||
Fabricate(:zonefile_setting, origin: 'pri.ee')
|
||||
Fabricate(:zonefile_setting, origin: 'med.ee')
|
||||
Fabricate(:zonefile_setting, origin: 'fie.ee')
|
||||
Fabricate(:zonefile_setting, origin: 'com.ee')
|
||||
end
|
||||
|
||||
it { should belong_to(:registrar) }
|
||||
it { should have_many(:nameservers) }
|
||||
it { should belong_to(:registrant) }
|
||||
|
@ -573,16 +581,17 @@ describe Domain do
|
|||
end
|
||||
|
||||
it 'should not create zone origin domain' do
|
||||
zs = Fabricate(:zonefile_setting)
|
||||
d = Fabricate.build(:domain, name: 'ee')
|
||||
d.save.should == false
|
||||
d.errors.full_messages.should match_array([
|
||||
"Data management policy violation: Domain name is blocked [name]"
|
||||
])
|
||||
|
||||
zs.destroy
|
||||
|
||||
d.save.should == true
|
||||
d = Fabricate.build(:domain, name: 'bla')
|
||||
d.save.should == false
|
||||
d.errors.full_messages.should match_array([
|
||||
"Domain name Domain name is invalid"
|
||||
])
|
||||
end
|
||||
|
||||
# d = Domain.new
|
||||
|
|
|
@ -1,6 +1,10 @@
|
|||
require 'rails_helper'
|
||||
|
||||
describe DomainTransfer do
|
||||
before :all do
|
||||
Fabricate(:zonefile_setting, origin: 'ee')
|
||||
end
|
||||
|
||||
it { should belong_to(:domain) }
|
||||
|
||||
context 'with invalid attribute' do
|
||||
|
|
|
@ -1,6 +1,10 @@
|
|||
require 'rails_helper'
|
||||
|
||||
describe Keyrelay do
|
||||
before :all do
|
||||
Fabricate(:zonefile_setting, origin: 'ee')
|
||||
end
|
||||
|
||||
it { should belong_to(:domain) }
|
||||
it { should belong_to(:requester) }
|
||||
it { should belong_to(:accepter) }
|
||||
|
|
|
@ -1,6 +1,10 @@
|
|||
require 'rails_helper'
|
||||
|
||||
describe Nameserver do
|
||||
before :all do
|
||||
Fabricate(:zonefile_setting, origin: 'ee')
|
||||
end
|
||||
|
||||
it { should belong_to(:domain) }
|
||||
|
||||
context 'with invalid attribute' do
|
||||
|
|
|
@ -1,6 +1,9 @@
|
|||
require 'rails_helper'
|
||||
|
||||
describe RegistrantVerification do
|
||||
before :all do
|
||||
Fabricate(:zonefile_setting, origin: 'ee')
|
||||
end
|
||||
context 'with invalid attribute' do
|
||||
before :all do
|
||||
@registrant_verification = RegistrantVerification.new
|
||||
|
|
|
@ -1,6 +1,10 @@
|
|||
require 'rails_helper'
|
||||
|
||||
describe WhoisRecord do
|
||||
before :all do
|
||||
Fabricate(:zonefile_setting, origin: 'ee')
|
||||
end
|
||||
|
||||
context 'with invalid attribute' do
|
||||
before :all do
|
||||
@whois_record = WhoisRecord.new
|
||||
|
|
|
@ -2,6 +2,7 @@ require 'rails_helper'
|
|||
|
||||
describe Repp::DomainV1 do
|
||||
before :all do
|
||||
Fabricate(:zonefile_setting, origin: 'ee')
|
||||
@registrar1 = Fabricate(:registrar1)
|
||||
@api_user = Fabricate(:gitlab_api_user, registrar: @registrar1)
|
||||
Fabricate.times(2, :domain, registrar: @api_user.registrar)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue