middleware/caching (#360)
Add the rcode to the cached item and use this when we synthesize the answer again. We could also infer the rcode from the reassembled message, but this seems easier and is only an integer. Also set the autoritative bit to 0 for all from-cache answers. Fixes 357
This commit is contained in:
parent
039596f319
commit
ba26f47d5c
2 changed files with 28 additions and 1 deletions
22
middleware/cache/cache_test.go
vendored
22
middleware/cache/cache_test.go
vendored
|
@ -1,6 +1,8 @@
|
|||
package cache
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
|
@ -64,12 +66,30 @@ var cacheTestCases = []cacheTestCase{
|
|||
},
|
||||
in: test.Case{},
|
||||
},
|
||||
{
|
||||
RecursionAvailable: true, Authoritative: true,
|
||||
Case: test.Case{
|
||||
Rcode: dns.RcodeNameError,
|
||||
Qname: "example.org.", Qtype: dns.TypeA,
|
||||
Ns: []dns.RR{
|
||||
test.SOA("example.org. 3600 IN SOA sns.dns.icann.org. noc.dns.icann.org. 2016082540 7200 3600 1209600 3600"),
|
||||
},
|
||||
},
|
||||
in: test.Case{
|
||||
Rcode: dns.RcodeNameError,
|
||||
Qname: "example.org.", Qtype: dns.TypeA,
|
||||
Ns: []dns.RR{
|
||||
test.SOA("example.org. 3600 IN SOA sns.dns.icann.org. noc.dns.icann.org. 2016082540 7200 3600 1209600 3600"),
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
func cacheMsg(m *dns.Msg, tc cacheTestCase) *dns.Msg {
|
||||
m.RecursionAvailable = tc.RecursionAvailable
|
||||
m.AuthenticatedData = tc.AuthenticatedData
|
||||
m.Authoritative = tc.Authoritative
|
||||
m.Rcode = tc.Rcode
|
||||
m.Truncated = tc.Truncated
|
||||
m.Answer = tc.in.Answer
|
||||
m.Ns = tc.in.Ns
|
||||
|
@ -89,6 +109,8 @@ func newTestCache(ttl time.Duration) (*Cache, *ResponseWriter) {
|
|||
func TestCache(t *testing.T) {
|
||||
c, crr := newTestCache(maxTTL)
|
||||
|
||||
log.SetOutput(ioutil.Discard)
|
||||
|
||||
for _, tc := range cacheTestCases {
|
||||
m := tc.in.Msg()
|
||||
m = cacheMsg(m, tc)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue