mirror of
https://github.com/internetee/registry.git
synced 2025-07-22 10:45:58 +02:00
Merge pull request #2039 from internetee/2306-csync-trim-whitespaces
2306-csync-trim-whitespaces
This commit is contained in:
commit
2a9692cb03
4 changed files with 45 additions and 4 deletions
|
@ -90,13 +90,19 @@ class CsyncRecord < ApplicationRecord
|
||||||
def validate_unique_pub_key
|
def validate_unique_pub_key
|
||||||
return false unless domain
|
return false unless domain
|
||||||
return true if disable_requested?
|
return true if disable_requested?
|
||||||
return true unless domain.dnskeys.where(public_key: dnskey.public_key).any?
|
return true unless dnskey_already_present?
|
||||||
|
|
||||||
errors.add(:public_key, 'already tied to this domain')
|
errors.add(:public_key, 'already tied to this domain')
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# since dnskeys stored in DB may include whitespace chars, we could not find them by
|
||||||
|
# 'where' clause using dnskey.public_key being stripped of whitespaces by csync generator
|
||||||
|
def dnskey_already_present?
|
||||||
|
domain.dnskeys.pluck(:public_key).map { |key| key.gsub(/\s+/, '') }.include? dnskey.public_key
|
||||||
|
end
|
||||||
|
|
||||||
def self.by_domain_name(domain_name)
|
def self.by_domain_name(domain_name)
|
||||||
domain = Domain.find_by(name: domain_name)
|
domain = Domain.find_by(name: domain_name) || Domain.find_by(name_puny: domain_name)
|
||||||
log.info "CsyncRecord: '#{domain_name}' not in zone. Not initializing record." unless domain
|
log.info "CsyncRecord: '#{domain_name}' not in zone. Not initializing record." unless domain
|
||||||
CsyncRecord.find_or_initialize_by(domain: domain) if domain
|
CsyncRecord.find_or_initialize_by(domain: domain) if domain
|
||||||
end
|
end
|
||||||
|
@ -112,8 +118,11 @@ class CsyncRecord < ApplicationRecord
|
||||||
end
|
end
|
||||||
|
|
||||||
def log
|
def log
|
||||||
@log ||= Rails.env.test? ? logger : Logger.new(STDOUT)
|
self.class.log
|
||||||
@log
|
end
|
||||||
|
|
||||||
|
def self.log
|
||||||
|
Rails.env.test? ? logger : Logger.new(STDOUT)
|
||||||
end
|
end
|
||||||
|
|
||||||
def validate_csync_action
|
def validate_csync_action
|
||||||
|
|
10
test/fixtures/dnskeys.yml
vendored
10
test/fixtures/dnskeys.yml
vendored
|
@ -8,3 +8,13 @@ one:
|
||||||
ds_alg: 13
|
ds_alg: 13
|
||||||
ds_digest_type: 2
|
ds_digest_type: 2
|
||||||
ds_digest: 39456058862EA09DD96992ED2BDAFAEDE8C7E949589E3DA903A46F4F9CD373EA
|
ds_digest: 39456058862EA09DD96992ED2BDAFAEDE8C7E949589E3DA903A46F4F9CD373EA
|
||||||
|
with_whitespace:
|
||||||
|
domain:
|
||||||
|
flags: 257
|
||||||
|
protocol: 3
|
||||||
|
alg: 13
|
||||||
|
public_key: mdsswUyr3DPW132mOi8V9xE SWE8jTo0dxCjjnopKl+GqJxpVXckHAeF+KkxLbxILfDLUT0rAK9iUzy1L53eKGQ==
|
||||||
|
ds_key_tag: 2371
|
||||||
|
ds_alg: 13
|
||||||
|
ds_digest_type: 2
|
||||||
|
ds_digest: 39456058862EA09DD96992ED2BDAFAEDE8C7E949589E3DA903A46F4F9CD373EA
|
||||||
|
|
2
test/fixtures/files/cdns_output.txt
vendored
2
test/fixtures/files/cdns_output.txt
vendored
|
@ -2,3 +2,5 @@ insecure-empty ns1.bestnames.test 127.0.0.1 airport.test
|
||||||
insecure-empty ns2.bestnames.test 127.0.0.1 airport.test
|
insecure-empty ns2.bestnames.test 127.0.0.1 airport.test
|
||||||
insecure ns1.bestnames.test 127.0.0.1 shop.test 257 3 13 mdsswUyr3DPW132mOi8V9xESWE8jTo0dxCjjnopKl+GqJxpVXckHAeF+KkxLbxILfDLUT0rAK9iUzy1L53eKGQ==
|
insecure ns1.bestnames.test 127.0.0.1 shop.test 257 3 13 mdsswUyr3DPW132mOi8V9xESWE8jTo0dxCjjnopKl+GqJxpVXckHAeF+KkxLbxILfDLUT0rAK9iUzy1L53eKGQ==
|
||||||
insecure ns2.bestnames.test 127.0.0.1 shop.test 257 3 13 mdsswUyr3DPW132mOi8V9xESWE8jTo0dxCjjnopKl+GqJxpVXckHAeF+KkxLbxILfDLUT0rAK9iUzy1L53eKGQ==
|
insecure ns2.bestnames.test 127.0.0.1 shop.test 257 3 13 mdsswUyr3DPW132mOi8V9xESWE8jTo0dxCjjnopKl+GqJxpVXckHAeF+KkxLbxILfDLUT0rAK9iUzy1L53eKGQ==
|
||||||
|
secure library.test 257 3 13 mdsswUyr3DPW132mOi8V9xESWE8jTo0dxCjjnopKl+GqJxpVXckHAeF+KkxLbxILfDLUT0rAK9iUzy1L53eKGQ==
|
||||||
|
secure library.test 257 3 13 mdsswUyr3DPW132mOi8V9xESWE8jTo0dxCjjnopKl+GqJxpVXckHAeF+KkxLbxILfDLUT0rAK9iUzy1L53eKGQ==
|
||||||
|
|
|
@ -89,4 +89,24 @@ class CsyncJobTest < ActiveSupport::TestCase
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_does_not_update_if_whitespaces_in_dnskey
|
||||||
|
@dnskey = dnskeys(:with_whitespace)
|
||||||
|
@domain = domains(:library)
|
||||||
|
@dnskey.domain_id = @domain.id
|
||||||
|
@dnskey.save(validate: false)
|
||||||
|
pubkey = @dnskey.public_key
|
||||||
|
|
||||||
|
CsyncJob.perform_now
|
||||||
|
@domain.reload
|
||||||
|
|
||||||
|
2.times do
|
||||||
|
CsyncJob.perform_now
|
||||||
|
end
|
||||||
|
|
||||||
|
@domain.reload
|
||||||
|
@dnskey.reload
|
||||||
|
assert_equal @dnskey, @domain.dnskeys.last
|
||||||
|
assert_equal pubkey, @domain.dnskeys.last.public_key
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue