diff --git a/plugin/dnssec/cache_test.go b/plugin/dnssec/cache_test.go index 64e5bd068..23acdbe78 100644 --- a/plugin/dnssec/cache_test.go +++ b/plugin/dnssec/cache_test.go @@ -59,6 +59,22 @@ func TestCacheNotValidExpired(t *testing.T) { } } +func TestCacheEmptySigsNotCached(t *testing.T) { + c := cache.New[[]dns.RR](defaultCap) + m := testMsg() + state := request.Request{Req: m, Zone: "miek.nl."} + k := hash(m.Answer) + + // Create a Dnssec instance with no keys; sign() will produce no signatures. + d := New([]string{"miek.nl."}, []*DNSKEY{}, false, nil, c) + d.Sign(state, time.Now().UTC(), server) + + _, ok := d.get(k, server) + if ok { + t.Errorf("Empty signatures should not be cached") + } +} + func TestCacheNotValidYet(t *testing.T) { fPriv, rmPriv, _ := test.TempFile(".", privKey) fPub, rmPub, _ := test.TempFile(".", pubKey) diff --git a/plugin/dnssec/dnssec.go b/plugin/dnssec/dnssec.go index 0b714a1af..2d9003f93 100644 --- a/plugin/dnssec/dnssec.go +++ b/plugin/dnssec/dnssec.go @@ -143,7 +143,9 @@ func (d Dnssec) sign(rrs []dns.RR, signerName string, ttl, incep, expir uint32, } sigs = append(sigs, sig) } - d.set(k, sigs) + if len(sigs) > 0 { + d.set(k, sigs) + } return sigs, nil }) return sigs.([]dns.RR), err