aboutsummaryrefslogtreecommitdiff
path: root/plugin/file/apex_test.go
diff options
context:
space:
mode:
authorGravatar Miek Gieben <miek@miek.nl> 2021-01-11 09:21:54 +0100
committerGravatar GitHub <noreply@github.com> 2021-01-11 09:21:54 +0100
commitae330a3f55ea4d097a8e2e656da362fa6380c463 (patch)
tree118154e06bf9b26ed93fadc8de38003fd3b3148d /plugin/file/apex_test.go
parent79cd81473b4a8f909dd6abb0cd5ff4a1539a3ea3 (diff)
downloadcoredns-ae330a3f55ea4d097a8e2e656da362fa6380c463.tar.gz
coredns-ae330a3f55ea4d097a8e2e656da362fa6380c463.tar.zst
coredns-ae330a3f55ea4d097a8e2e656da362fa6380c463.zip
plugin/file: document wrong behavior in lookup fox Apex (#4376)
An apex only zone returns the wrong answer, document this by adding a test. Closes: #4374 Signed-off-by: Miek Gieben <miek@miek.nl>
Diffstat (limited to 'plugin/file/apex_test.go')
-rw-r--r--plugin/file/apex_test.go45
1 files changed, 45 insertions, 0 deletions
diff --git a/plugin/file/apex_test.go b/plugin/file/apex_test.go
new file mode 100644
index 000000000..2108543c3
--- /dev/null
+++ b/plugin/file/apex_test.go
@@ -0,0 +1,45 @@
+package file
+
+import (
+ "context"
+ "strings"
+ "testing"
+
+ "github.com/coredns/coredns/plugin/pkg/dnstest"
+ "github.com/coredns/coredns/plugin/test"
+
+ "github.com/miekg/dns"
+)
+
+const exampleApexOnly = `$ORIGIN example.com.
+@ IN SOA ns1.example.com. admin.example.com. (
+ 2005011437 ; Serial
+ 1200 ; Refresh
+ 144 ; Retry
+ 1814400 ; Expire
+ 2h ) ; Minimum
+@ IN NS ns1.example.com.
+`
+
+func TestLookupApex(t *testing.T) {
+ // this tests a zone with *only* an apex. The behavior here is wrong, we should return NODATA, but we do a NXDOMAIN.
+ // Adding this test to document this. Note a zone that doesn't have any data is pretty useless anyway, so rather than
+ // fix this with an entirely new branch in lookup.go, just live with it.
+ zone, err := Parse(strings.NewReader(exampleApexOnly), "example.com.", "stdin", 0)
+ if err != nil {
+ t.Fatalf("Expected no error when reading zone, got %q", err)
+ }
+ fm := File{Next: test.ErrorHandler(), Zones: Zones{Z: map[string]*Zone{"example.com.": zone}, Names: []string{"example.com."}}}
+ ctx := context.TODO()
+
+ m := new(dns.Msg)
+ m.SetQuestion("example.com.", dns.TypeA)
+
+ rec := dnstest.NewRecorder(&test.ResponseWriter{})
+ if _, err := fm.ServeDNS(ctx, rec, m); err != nil {
+ t.Errorf("Expected no error, got %v", err)
+ }
+ if rec.Msg.Rcode != dns.RcodeNameError { // Should be RcodeSuccess in a perfect world.
+ t.Errorf("Expected rcode %d, got %d", dns.RcodeNameError, rec.Msg.Rcode)
+ }
+}