mirror of
https://github.com/internetee/registry.git
synced 2025-06-06 04:37:30 +02:00
Add creation of csync inputs based on name_puny
This commit is contained in:
parent
82c048b316
commit
d887bcd734
3 changed files with 39 additions and 4 deletions
|
@ -83,9 +83,9 @@ class CsyncJob < ApplicationJob
|
|||
# From this point we're working on generating input for cdnskey-scanner
|
||||
def gather_pollable_domains
|
||||
@logger.info 'CsyncJob Generate: Gathering current domain(s) data'
|
||||
Nameserver.select(:hostname, :domain_id).all.each do |ns|
|
||||
Nameserver.select(:hostname_puny, :domain_id).all.each do |ns|
|
||||
%i[secure insecure].each do |i|
|
||||
@input_store[i][ns.hostname] = [] unless @input_store[i].key? ns.hostname
|
||||
@input_store[i][ns.hostname_puny] = [] unless @input_store[i].key? ns.hostname_puny
|
||||
end
|
||||
|
||||
append_domains_to_list(ns)
|
||||
|
@ -94,14 +94,16 @@ class CsyncJob < ApplicationJob
|
|||
|
||||
def append_domains_to_list(nameserver)
|
||||
Domain.where(id: nameserver.domain_id).all.each do |domain|
|
||||
@input_store[domain.dnskeys.any? ? :secure : :insecure][nameserver.hostname].push domain.name
|
||||
key = domain.dnskeys.any? ? :secure : :insecure
|
||||
hostname = nameserver.hostname_puny || nameserver.hostname
|
||||
@input_store[key][hostname].push domain.name_puny
|
||||
end
|
||||
end
|
||||
|
||||
def generate_scanner_input
|
||||
@logger.info 'CsyncJob Generate: Gathering current domain(s) data'
|
||||
gather_pollable_domains
|
||||
|
||||
check_directory
|
||||
out_file = File.new(ENV['cdns_scanner_input_file'], 'w+')
|
||||
|
||||
%i[secure insecure].each do |state|
|
||||
|
@ -113,6 +115,15 @@ class CsyncJob < ApplicationJob
|
|||
@logger.info 'CsyncJob Generate: Finished writing output to ' + ENV['cdns_scanner_input_file']
|
||||
end
|
||||
|
||||
def check_directory
|
||||
dirname = File.dirname(ENV['cdns_scanner_input_file'])
|
||||
|
||||
FileUtils.mkdir_p(dirname) unless File.directory?(dirname)
|
||||
return if File.exist?(ENV['cdns_scanner_input_file'])
|
||||
|
||||
FileUtils.touch(ENV['cdns_scanner_input_file'])
|
||||
end
|
||||
|
||||
def create_input_lines(out_file, state)
|
||||
@input_store[state].keys.each do |nameserver|
|
||||
domains = @input_store[state][nameserver].join(' ')
|
||||
|
|
5
test/fixtures/nameservers.yml
vendored
5
test/fixtures/nameservers.yml
vendored
|
@ -1,5 +1,6 @@
|
|||
shop_ns1:
|
||||
hostname: ns1.bestnames.test
|
||||
hostname_puny: ns1.bestnames.test
|
||||
ipv4:
|
||||
- 192.0.2.1
|
||||
ipv6:
|
||||
|
@ -8,6 +9,7 @@ shop_ns1:
|
|||
|
||||
shop_ns2:
|
||||
hostname: ns2.bestnames.test
|
||||
hostname_puny: ns2.bestnames.test
|
||||
ipv4:
|
||||
- 192.0.2.2
|
||||
ipv6:
|
||||
|
@ -16,6 +18,7 @@ shop_ns2:
|
|||
|
||||
airport_ns1:
|
||||
hostname: ns1.bestnames.test
|
||||
hostname_puny: ns1.bestnames.test
|
||||
ipv4:
|
||||
- 192.0.2.2
|
||||
ipv6:
|
||||
|
@ -24,6 +27,7 @@ airport_ns1:
|
|||
|
||||
airport_ns2:
|
||||
hostname: ns2.bestnames.test
|
||||
hostname_puny: ns2.bestnames.test
|
||||
ipv4:
|
||||
- 192.0.2.0
|
||||
- 192.0.2.3
|
||||
|
@ -34,4 +38,5 @@ airport_ns2:
|
|||
|
||||
metro_ns1:
|
||||
hostname: ns1.bestnames.test
|
||||
hostname_puny: ns1.bestnames.test
|
||||
domain: metro
|
||||
|
|
|
@ -6,6 +6,10 @@ class CsyncJobTest < ActiveSupport::TestCase
|
|||
setup do
|
||||
@dnskey = dnskeys(:one)
|
||||
@domain = domains(:shop)
|
||||
dirname = File.dirname(ENV['cdns_scanner_input_file'])
|
||||
|
||||
FileUtils.mkdir_p(dirname) unless File.directory?(dirname)
|
||||
FileUtils.touch(ENV['cdns_scanner_input_file']) unless File.exists?(ENV['cdns_scanner_input_file'])
|
||||
end
|
||||
|
||||
def test_generates_input_file_for_cdnskey_scanner
|
||||
|
@ -19,6 +23,21 @@ class CsyncJobTest < ActiveSupport::TestCase
|
|||
assert_equal expected_contents, IO.read(ENV['cdns_scanner_input_file'])
|
||||
end
|
||||
|
||||
def test_generates_input_file_from_name_puny
|
||||
@domain.update(name: 'pööriöö.ee', name_puny: 'xn--pri-snaaca.ee')
|
||||
@domain.save(validate: false)
|
||||
@nameserver = @domain.nameservers.first
|
||||
@nameserver.update(hostname: 'täpiline.ee', hostname_puny: 'xn--theke1-bua.ee')
|
||||
@domain.reload
|
||||
@dnskey.update(domain: @domain)
|
||||
|
||||
expected_contents = "[secure]\nns2.bestnames.test #{@domain.name_puny}\n#{@nameserver.hostname_puny} #{@domain.name_puny}\n" \
|
||||
"[insecure]\nns2.bestnames.test airport.test\nns1.bestnames.test airport.test metro.test\n"
|
||||
|
||||
CsyncJob.perform_now(generate: true)
|
||||
assert_equal expected_contents, IO.read(ENV['cdns_scanner_input_file'])
|
||||
end
|
||||
|
||||
def test_creates_csync_record_when_new_cdnskey_discovered
|
||||
assert_nil @domain.csync_record
|
||||
CsyncJob.perform_now
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue