From c1857f488922d981f4b33f5c1b8518ff7d13a663 Mon Sep 17 00:00:00 2001 From: xuweiwei Date: Tue, 26 Apr 2022 00:05:24 +0800 Subject: [PATCH] plugin/file: unified NoData result (#5086) Signed-off-by: xuweiwei --- plugin/file/lookup.go | 2 +- plugin/file/lookup_test.go | 29 +++++++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/plugin/file/lookup.go b/plugin/file/lookup.go index f92cba66f..08eed7d61 100644 --- a/plugin/file/lookup.go +++ b/plugin/file/lookup.go @@ -230,7 +230,7 @@ func (z *Zone) Lookup(ctx context.Context, state request.Request, qname string) nsec := typeFromElem(wildElem, dns.TypeNSEC, do) ret = append(ret, nsec...) } - return nil, ret, nil, Success + return nil, ret, nil, NoData } if do { diff --git a/plugin/file/lookup_test.go b/plugin/file/lookup_test.go index e84d2fce5..79e560428 100644 --- a/plugin/file/lookup_test.go +++ b/plugin/file/lookup_test.go @@ -7,6 +7,7 @@ import ( "github.com/coredns/coredns/plugin/pkg/dnstest" "github.com/coredns/coredns/plugin/test" + "github.com/coredns/coredns/request" "github.com/miekg/dns" ) @@ -188,6 +189,33 @@ func TestLookupNil(t *testing.T) { fm.ServeDNS(ctx, rec, m) } +func TestLookUpNoDataResult(t *testing.T) { + zone, err := Parse(strings.NewReader(dbMiekNL), testzone, "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{testzone: zone}, Names: []string{testzone}}} + ctx := context.TODO() + var noDataTestCases = []test.Case{ + { + Qname: "a.miek.nl.", Qtype: dns.TypeMX, + }, + { + Qname: "wildcard.nodata.miek.nl.", Qtype: dns.TypeMX, + }, + } + + for _, tc := range noDataTestCases { + m := tc.Msg() + state := request.Request{W: &test.ResponseWriter{}, Req: m} + _, _, _, result := fm.Z[testzone].Lookup(ctx, state, tc.Qname) + if result != NoData { + t.Errorf("Expected result == 3 but result == %v ", result) + } + } +} + func BenchmarkFileLookup(b *testing.B) { zone, err := Parse(strings.NewReader(dbMiekNL), testzone, "stdin", 0) if err != nil { @@ -252,4 +280,5 @@ mx IN MX 10 a.miek.nl. txt IN TXT "v=spf1 a mx ~all" caa IN CAA 0 issue letsencrypt.org +*.nodata IN A 139.162.196.79 ext-cname IN CNAME example.com.`