Permalink
Browse files

dns: Tidied up newline removal, changelog bumped

This now uses String#strip to remove any leading/trailing whitespace.

Test case added, changelog bumped.
  • Loading branch information...
patch0 committed Jan 21, 2016
1 parent 73fdcca commit c2eb5765681ddfce7dd518ca1a7dc3965aaab461
Showing with 21 additions and 9 deletions.
  1. +6 −2 dns/debian/changelog
  2. +2 −5 dns/lib/symbiosis/domain/dns.rb
  3. +13 −2 dns/test.d/tc_dns.rb
View
@@ -1,9 +1,13 @@
symbiosis-dns (2015:1010) stable; urgency=medium
symbiosis-dns (2015:1011) stable; urgency=medium
* Fixed up DMARC record generation to produce valid records.
* Avoid generating invalid SPF records by stripping any potential
newline characters prior to generating them.
-- Patrick J Cherry <patrick@bytemark.co.uk> Thu, 21 Jan 2016 10:04:49 +0000
symbiosis-dns (2015:1010) stable; urgency=medium
* Fixed up DMARC record generation to produce valid records.
-- Patrick J Cherry <patrick@bytemark.co.uk> Thu, 14 Jan 2016 16:44:59 +0000
@@ -25,11 +25,8 @@ def spf_record
spf = "v=spf1 +a +mx ?all" if spf === true
if spf.is_a?(String)
# We encode just the first line.
line = spf.split($/).first
# But we make sure we remove any trailing \r, or \n characeters
line = line.tr( "\n\r", "" )
# We encode just the first line, and remove any whitespace from the ends.
line = spf.split($/).first.strip
tinydns_encode(line)
else
View
@@ -156,8 +156,6 @@ def test_spf_record
# Now stick a different record in.
#
spf_record = "v=spf1 ip6:2001:41c8:1:2:3::4 -all"
encoded_spf_record = "ip6:2001:41c8:1:2:3::4 -all"
encoded_spf_record = "v=spf1 ip6\\0721080\\072\\0728\\072800\\07268/96 -all"
@domain.__send__(:set_param,"spf", spf_record, @domain.config_dir)
txt = config.generate_config
spf_records = txt.split($/).select{|l| l =~ basic_spf_record_match}
@@ -170,6 +168,19 @@ def test_spf_record
assert_match(/^'#{Regexp.escape(@domain.name)}:#{Regexp.escape(spf_record.gsub(":",'\\\\072'))}:/, r)
end
#
# Test a record with a newline
#
spf_record = "v=spf1 ip6:2001:41c8:1:2:3::4 -all\r\n"
@domain.__send__(:set_param,"spf", spf_record, @domain.config_dir)
txt = config.generate_config
spf_records = txt.split($/).select{|l| l =~ basic_spf_record_match}
assert_not_equal([], spf_records, "SPF record(s) not found when custom SPF record with newline was set")
spf_records.each do |r|
assert_match(/^'#{Regexp.escape(@domain.name)}:#{Regexp.escape(spf_record.strip.gsub(":",'\\\\072'))}:/, r, "SPF record generation failed when newlines were added")
end
end
def test_bytemark_antispam

0 comments on commit c2eb576

Please sign in to comment.