fix truncation bug (#2261)

* fix truncation bug

* Generate records with generic RRs

* Remove SoundCloud from test name

* Comment for binary-search -1 adjustment

Explain why the binary search may have exited with
a reply size that is too large by one record.

* Refactor to remove sub variable

patch suggested by miek removes unnecessary sub
variable for removing a single line from the
reply.Extra length.
This commit is contained in:
stuart nelson 2018-11-03 11:01:56 +01:00 committed by Miek Gieben
parent 1ad002c9f3
commit cac6fe1d07
2 changed files with 49 additions and 11 deletions

View file

@ -159,6 +159,36 @@ func TestRequestScrubExtraRegression(t *testing.T) {
}
}
func TestTruncation(t *testing.T) {
for bufsize := 1024; bufsize <= 4096; bufsize += 12 {
m := new(dns.Msg)
m.SetQuestion("http.service.tcp.srv.k8s.example.org", dns.TypeSRV)
m.SetEdns0(uint16(bufsize), true)
req := Request{W: &test.ResponseWriter{}, Req: m}
reply := new(dns.Msg)
reply.SetReply(m)
for i := 0; i < 61; i++ {
reply.Answer = append(reply.Answer, test.SRV(fmt.Sprintf("http.service.tcp.srv.k8s.example.org. 5 IN SRV 0 0 80 10-144-230-%d.default.pod.k8s.example.org.", i)))
}
for i := 0; i < 5; i++ {
reply.Extra = append(reply.Extra, test.A(fmt.Sprintf("ip-10-10-52-5%d.subdomain.example.org. 5 IN A 10.10.52.5%d", i, i)))
}
for i := 0; i < 5; i++ {
reply.Ns = append(reply.Ns, test.NS(fmt.Sprintf("srv.subdomain.example.org. 5 IN NS ip-10-10-33-6%d.subdomain.example.org.", i)))
}
req.Scrub(reply)
want, got := req.Size(), reply.Len()
if want < got {
t.Fatalf("Want scrub to reduce message length below %d bytes, got %d bytes", want, got)
}
}
}
func TestRequestScrubAnswerExact(t *testing.T) {
m := new(dns.Msg)
m.SetQuestion("large.example.com.", dns.TypeSRV)