2014-11-09 20:56:22 +11:00
|
|
|
package dns
|
|
|
|
|
2014-11-12 10:32:03 +11:00
|
|
|
import "testing"
|
2014-11-09 20:57:06 +11:00
|
|
|
|
2014-11-09 20:56:22 +11:00
|
|
|
func TestDynamicUpdateParsing(t *testing.T) {
|
|
|
|
prefix := "example.com. IN "
|
|
|
|
for _, typ := range TypeToString {
|
|
|
|
if typ == "CAA" || typ == "OPT" || typ == "AXFR" || typ == "IXFR" || typ == "ANY" || typ == "TKEY" ||
|
|
|
|
typ == "TSIG" || typ == "ISDN" || typ == "UNSPEC" || typ == "NULL" || typ == "ATMA" {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
r, e := NewRR(prefix + typ)
|
|
|
|
if e != nil {
|
|
|
|
t.Log("failure to parse: " + prefix + typ)
|
|
|
|
t.Fail()
|
|
|
|
} else {
|
|
|
|
t.Logf("parsed: %s", r.String())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-11-09 21:04:46 +11:00
|
|
|
func TestDynamicUpdateUnpack(t *testing.T) {
|
|
|
|
// From https://github.com/miekg/dns/issues/150#issuecomment-62296803
|
2014-11-10 03:09:49 +11:00
|
|
|
// It should be an update message for the zone "example.",
|
|
|
|
// deleting the A RRset "example." and then adding an A record at "example.".
|
|
|
|
// class ANY, TYPE A
|
2014-11-09 21:04:46 +11:00
|
|
|
buf := []byte{171, 68, 40, 0, 0, 1, 0, 0, 0, 2, 0, 0, 7, 101, 120, 97, 109, 112, 108, 101, 0, 0, 6, 0, 1, 192, 12, 0, 1, 0, 255, 0, 0, 0, 0, 0, 0, 192, 12, 0, 1, 0, 1, 0, 0, 0, 0, 0, 4, 127, 0, 0, 1}
|
|
|
|
msg := new(Msg)
|
|
|
|
err := msg.Unpack(buf)
|
|
|
|
if err != nil {
|
2014-11-10 03:16:41 +11:00
|
|
|
t.Log("failed to unpack: " + err.Error() + "\n" + msg.String())
|
2014-11-10 03:09:49 +11:00
|
|
|
t.Fail()
|
2014-11-09 21:04:46 +11:00
|
|
|
}
|
|
|
|
}
|
2014-11-12 10:32:03 +11:00
|
|
|
|
|
|
|
func TestDynamicUpdateZeroRdataUnpack(t *testing.T) {
|
|
|
|
m := new(Msg)
|
|
|
|
rr := &RR_Header{Name: ".", Rrtype: 0, Class: 1, Ttl: ^uint32(0), Rdlength: 0}
|
|
|
|
m.Answer = []RR{rr, rr, rr, rr, rr}
|
|
|
|
m.Ns = m.Answer
|
|
|
|
for n, s := range TypeToString {
|
|
|
|
rr.Rrtype = n
|
|
|
|
bytes, err := m.Pack()
|
|
|
|
if err != nil {
|
|
|
|
t.Logf("failed to pack %s: %v", s, err)
|
|
|
|
t.Fail()
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
if err := new(Msg).Unpack(bytes); err != nil {
|
|
|
|
t.Logf("failed to unpack %s: %v", s, err)
|
|
|
|
t.Fail()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|