diff options
author | 2018-10-23 17:55:40 +0100 | |
---|---|---|
committer | 2018-10-23 09:55:40 -0700 | |
commit | 898b1ef31691fac4bc45ad507f6d5762555f4dea (patch) | |
tree | 688a8c6b1a994c09f6b50ed3c6ef9ad68a5321fb /test/compression_scrub_test.go | |
parent | 96529b2c501b47a71a0f6eae5a04ebe86ba1ab1d (diff) | |
download | coredns-898b1ef31691fac4bc45ad507f6d5762555f4dea.tar.gz coredns-898b1ef31691fac4bc45ad507f6d5762555f4dea.tar.zst coredns-898b1ef31691fac4bc45ad507f6d5762555f4dea.zip |
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>
Diffstat (limited to 'test/compression_scrub_test.go')
-rw-r--r-- | test/compression_scrub_test.go | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/test/compression_scrub_test.go b/test/compression_scrub_test.go new file mode 100644 index 000000000..b18f1fe0a --- /dev/null +++ b/test/compression_scrub_test.go @@ -0,0 +1,60 @@ +package test + +import ( + "net" + "testing" + + "github.com/miekg/dns" +) + +func TestCompressScrub(t *testing.T) { + corefile := `example.org:0 { + erratic { + drop 0 + delay 0 + large + } + }` + + i, udp, _, err := CoreDNSServerAndPorts(corefile) + if err != nil { + t.Fatalf("Could not get CoreDNS serving instance: %s", err) + } + defer i.Stop() + + c, err := net.Dial("udp", udp) + if err != nil { + t.Fatalf("Could not dial %s", err) + } + m := new(dns.Msg) + m.SetQuestion("example.org.", dns.TypeA) + q, _ := m.Pack() + + c.Write(q) + buf := make([]byte, 1024) + n, err := c.Read(buf) + if err != nil || n == 0 { + t.Errorf("Expected reply, got: %s", err) + return + } + if n >= 512 { + t.Fatalf("Expected returned packet to be < 512, got %d", n) + } + buf = buf[:n] + // If there is compression in the returned packet we should look for compression pointers, if found + // the pointers should return to the domain name in the query (the first domain name that's avaiable for + // compression. This means we're looking for a combo where the pointers is detected and the offset is 12 + // the position of the first name after the header. The erratic plugin adds 30 RRs that should all be compressed. + found := 0 + for i := 0; i < len(buf)-1; i++ { + if buf[i]&0xC0 == 0xC0 { + off := (int(buf[i])^0xC0)<<8 | int(buf[i+1]) + if off == 12 { + found++ + } + } + } + if found != 30 { + t.Errorf("Failed to find all compression pointers in the packet, wanted 30, got %d", found) + } +} |