mirror of
https://github.com/internetee/registry.git
synced 2025-05-29 17:10:08 +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)
|
||||
|
|
|
@ -2,7 +2,7 @@ require 'rails_helper'
|
|||
|
||||
describe ContactMailer do
|
||||
describe 'email changed notification when delivery turned off' do
|
||||
before :all do
|
||||
before :all do
|
||||
@contact = Fabricate(:contact, email: 'test@example.ee')
|
||||
@mail = ContactMailer.email_updated('test@example.com', @contact)
|
||||
end
|
||||
|
@ -25,7 +25,8 @@ describe ContactMailer do
|
|||
end
|
||||
|
||||
describe 'email changed notification' do
|
||||
before :all 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,8 +1,12 @@
|
|||
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
|
||||
before :all do
|
||||
@registrant = Fabricate(:registrant, email: 'test@example.com')
|
||||
@domain = Fabricate(:domain, registrant: @registrant)
|
||||
@mail = DomainMailer.pending_update_request_for_old_registrant(@domain)
|
||||
|
@ -26,7 +30,7 @@ describe DomainMailer do
|
|||
end
|
||||
|
||||
describe 'pending update request for an old registrant' do
|
||||
before :all do
|
||||
before :all do
|
||||
@registrant = Fabricate(:registrant, email: 'test@example.com')
|
||||
@new_registrant = Fabricate(:registrant, email: 'test@example.org')
|
||||
@domain = Fabricate(:domain, registrant: @registrant)
|
||||
|
@ -59,7 +63,7 @@ describe DomainMailer do
|
|||
end
|
||||
|
||||
describe 'pending upadte notification for a new registrant' do
|
||||
before :all do
|
||||
before :all do
|
||||
@registrant = Fabricate(:registrant, email: 'old@example.com')
|
||||
@new_registrant = Fabricate(:registrant, email: 'new@example.org')
|
||||
@domain = Fabricate(:domain, registrant: @registrant)
|
||||
|
@ -88,7 +92,7 @@ describe DomainMailer do
|
|||
end
|
||||
|
||||
describe 'pending update notification for a new registrant' do
|
||||
before :all do
|
||||
before :all do
|
||||
@registrant = Fabricate(:registrant, email: 'old@example.com')
|
||||
@new_registrant = Fabricate(:registrant, email: 'new@example.org')
|
||||
@domain = Fabricate(:domain, registrant: @registrant)
|
||||
|
@ -117,7 +121,7 @@ describe DomainMailer do
|
|||
end
|
||||
|
||||
describe 'pending update rejected notification for a new registrant' do
|
||||
before :all do
|
||||
before :all do
|
||||
@registrant = Fabricate(:registrant, email: 'old@example.com')
|
||||
@new_registrant = Fabricate(:registrant, email: 'new@example.org')
|
||||
@domain = Fabricate(:domain, registrant: @registrant)
|
||||
|
@ -145,7 +149,7 @@ describe DomainMailer do
|
|||
end
|
||||
|
||||
describe 'registrant updated notification for a new registrant' do
|
||||
before :all do
|
||||
before :all do
|
||||
@registrant = Fabricate(:registrant, email: 'test@example.com')
|
||||
@domain = Fabricate(:domain, registrant: @registrant)
|
||||
@domain.deliver_emails = true
|
||||
|
@ -170,7 +174,7 @@ describe DomainMailer do
|
|||
end
|
||||
|
||||
describe 'registrant updated notification for a old registrant' do
|
||||
before :all do
|
||||
before :all do
|
||||
@registrant = Fabricate(:registrant, email: 'test@example.com')
|
||||
@domain = Fabricate(:domain, registrant: @registrant)
|
||||
@domain.deliver_emails = true
|
||||
|
@ -195,7 +199,7 @@ describe DomainMailer do
|
|||
end
|
||||
|
||||
describe 'domain pending delete notification when delivery turned off' do
|
||||
before :all do
|
||||
before :all do
|
||||
@registrant = Fabricate(:registrant, email: 'test@example.com')
|
||||
@domain = Fabricate(:domain, registrant: @registrant)
|
||||
@mail = DomainMailer.pending_deleted(@domain)
|
||||
|
@ -219,7 +223,7 @@ describe DomainMailer do
|
|||
end
|
||||
|
||||
describe 'email pending delete notification' do
|
||||
before :all do
|
||||
before :all do
|
||||
@registrant = Fabricate(:registrant, email: 'test@example.com')
|
||||
@domain = Fabricate(:domain, name: 'delete-pending.ee', registrant: @registrant)
|
||||
@domain.deliver_emails = true
|
||||
|
@ -250,7 +254,7 @@ describe DomainMailer do
|
|||
end
|
||||
|
||||
describe 'pending delete rejected notification' do
|
||||
before :all do
|
||||
before :all do
|
||||
@registrant = Fabricate(:registrant, email: 'test@example.com')
|
||||
@domain = Fabricate(:domain, name: 'delete-pending-rejected.ee', registrant: @registrant)
|
||||
@domain.deliver_emails = true
|
||||
|
@ -277,7 +281,7 @@ describe DomainMailer do
|
|||
end
|
||||
|
||||
describe 'pending delete expired notification' do
|
||||
before :all do
|
||||
before :all do
|
||||
@registrant = Fabricate(:registrant, email: 'test@example.com')
|
||||
@domain = Fabricate(:domain, name: 'pending-delete-expired.ee', registrant: @registrant)
|
||||
@domain.deliver_emails = true
|
||||
|
@ -304,7 +308,7 @@ describe DomainMailer do
|
|||
end
|
||||
|
||||
describe 'pending delete rejected notification' do
|
||||
before :all do
|
||||
before :all do
|
||||
@registrant = Fabricate(:registrant, email: 'test@example.com')
|
||||
@domain = Fabricate(:domain, name: 'delete-confirmed.ee', registrant: @registrant)
|
||||
@domain.deliver_emails = true
|
||||
|
|
|
@ -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