fix(dnssec): avoid caching empty signing results (#7996)

This commit is contained in:
Ville Vesilehto
2026-04-02 00:20:15 +03:00
committed by GitHub
parent 6d6c50db3a
commit 510977c476
2 changed files with 19 additions and 1 deletions

View File

@@ -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)

View File

@@ -143,7 +143,9 @@ func (d Dnssec) sign(rrs []dns.RR, signerName string, ttl, incep, expir uint32,
}
sigs = append(sigs, sig)
}
if len(sigs) > 0 {
d.set(k, sigs)
}
return sigs, nil
})
return sigs.([]dns.RR), err