Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@syedazeez337
Copy link
Contributor

Summary

This PR fixes a subtle but important bug in the test plugin of CoreDNS where TXT record assertions failed to correctly distinguish between:

  • Multiple distinct TXT records, and
  • A single TXT record split across multiple 255-byte strings (as allowed by RFC 1035 §3.3.14).

The result was inaccurate test validations — either false positives or failures — especially in cases where long TXT records were involved.


Problem Description

In DNS, a single TXT record may be split into multiple substrings due to the 255-byte limit. For example:

example.org. 3600 IN TXT "chunk1..." "chunk2..."

This is one TXT record, not two.

The test plugin previously compared TXT records using raw []string slices from dns.TXT.Txt, like:

for j, txt := range x.Txt {
    if txt != expected.Txt[j] {
        ...
    }
}

This caused incorrect results when:

  • A single record was split across multiple strings (len(Txt) > 1), and
  • The expected result consisted of multiple separate TXT RRs.

Solution

The comparison logic has been updated to:

  • Join the substrings using strings.Join(...)
  • Compare the full logical string instead of chunk-by-chunk

Example Fix:

actualTxt := strings.Join(x.Txt, "")
expectedTxt := strings.Join(section[i].(*dns.TXT).Txt, "")

Additional Changes

  • ✅ Added a regression test: plugin/test/testdata/txtrecordsplit.test
    • Covers both split and multi-record TXT scenarios
  • ✅ Created a stubbed RunTestFile in testdata_test.go to enable isolated testing
  • ✅ Ensured the code passes go fmt and golangci-lint with no issues

Impact

This improves the reliability of the test plugin when verifying TXT records, especially in cases involving long or split TXT strings. It ensures future plugin development or zone file testing behaves consistently with DNS standards.


Related Issue

Fixes #7404

…cords

This fixes an issue where the test plugin failed to distinguish between:
- a single TXT record split into multiple 255-byte chunks
- multiple separate TXT records with single chunks

The logic now joins TXT chunks for both actual and expected records before comparison,
ensuring semantic correctness per RFC 1035 and avoiding false positives.

Fixes coredns#7404

Signed-off-by: Syed Azeez <[email protected]>
@codecov
Copy link

codecov bot commented Jul 15, 2025

Codecov Report

Attention: Patch coverage is 0% with 4 lines in your changes missing coverage. Please review.

Project coverage is 59.77%. Comparing base (93c57b6) to head (15ff583).
Report is 1533 commits behind head on master.

Files with missing lines Patch % Lines
plugin/test/helpers.go 0.00% 4 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #7413      +/-   ##
==========================================
+ Coverage   55.70%   59.77%   +4.07%     
==========================================
  Files         224      273      +49     
  Lines       10016    18037    +8021     
==========================================
+ Hits         5579    10781    +5202     
- Misses       3978     6624    +2646     
- Partials      459      632     +173     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@yongtang yongtang merged commit 1981f22 into coredns:master Jul 15, 2025
13 checks passed
@micheelengronne
Copy link

Thank you @syedazeez337

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Confusion between multiple TXT records and TXT records longer than 255 bytes for the test plugin

3 participants