mirror of
https://github.com/coredns/coredns.git
synced 2025-10-27 08:14:18 -04:00
server: actually scrub response (#2225)
* server: actually scrub response Did all the worked, hooked it up wrongly :( This also needs test, but those are hard(er) because we only receive packets after they have been decoded; i.e. we never see the wirefmt. Signed-off-by: Miek Gieben <miek@miek.nl> * Add tests Add a test for checking is compression pointers are set in the packet. This also adds an undocumented 'large' feature to the erratic plugin to send large responses that should be compressed. Commenting the Scrub out in server results in: === RUN TestCompressScrub --- FAIL: TestCompressScrub (0.00s) compression_scrub_test.go:41: Expected returned packet to be < 512, got 839 FAIL exit status 1 FAIL github.com/coredns/coredns/test 0.036s Actually checking the size might be easier, but lets be thorough here and check the pointers them selves. Signed-off-by: Miek Gieben <miek@miek.nl> * Fix tests Signed-off-by: Miek Gieben <miek@miek.nl> * plugin erratic: fix e.large always put an rr in the reply, fix e.large in erractic and add test to check for it. Signed-off-by: Miek Gieben <miek@miek.nl>
This commit is contained in:
committed by
John Belamaric
parent
96529b2c50
commit
898b1ef316
@@ -19,6 +19,7 @@ type Erratic struct {
|
||||
duration time.Duration
|
||||
|
||||
truncate uint64
|
||||
large bool // undocumented feature; return large responses for A request (>512B, to test compression).
|
||||
|
||||
q uint64 // counter of queries
|
||||
}
|
||||
@@ -57,6 +58,11 @@ func (e *Erratic) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Msg
|
||||
rr := *(rrA.(*dns.A))
|
||||
rr.Header().Name = state.QName()
|
||||
m.Answer = append(m.Answer, &rr)
|
||||
if e.large {
|
||||
for i := 0; i < 29; i++ {
|
||||
m.Answer = append(m.Answer, &rr)
|
||||
}
|
||||
}
|
||||
case dns.TypeAAAA:
|
||||
rr := *(rrAAAA.(*dns.AAAA))
|
||||
rr.Header().Name = state.QName()
|
||||
|
||||
@@ -98,3 +98,19 @@ func TestAxfr(t *testing.T) {
|
||||
t.Errorf("Expected for record to be %d, got %d", dns.TypeSOA, x)
|
||||
}
|
||||
}
|
||||
|
||||
func TestErratic(t *testing.T) {
|
||||
e := &Erratic{drop: 0, delay: 0}
|
||||
|
||||
ctx := context.TODO()
|
||||
|
||||
req := new(dns.Msg)
|
||||
req.SetQuestion("example.org.", dns.TypeA)
|
||||
|
||||
rec := dnstest.NewRecorder(&test.ResponseWriter{})
|
||||
e.ServeDNS(ctx, rec, req)
|
||||
|
||||
if rec.Msg.Answer[0].Header().Rrtype != dns.TypeA {
|
||||
t.Errorf("Expected A response, got %d type", rec.Msg.Answer[0].Header().Rrtype)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -104,6 +104,8 @@ func parseErratic(c *caddy.Controller) (*Erratic, error) {
|
||||
return nil, fmt.Errorf("illegal amount value given %q", args[0])
|
||||
}
|
||||
e.truncate = uint64(amount)
|
||||
case "large":
|
||||
e.large = true
|
||||
default:
|
||||
return nil, c.Errf("unknown property '%s'", c.Val())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user