diff --git a/packetbeat/protos/dns/dns_test.go b/packetbeat/protos/dns/dns_test.go index 538ec09d738..5e5902bf865 100644 --- a/packetbeat/protos/dns/dns_test.go +++ b/packetbeat/protos/dns/dns_test.go @@ -16,6 +16,7 @@ import ( "github.com/elastic/beats/libbeat/common" "github.com/elastic/beats/libbeat/logp" + mkdns "github.com/miekg/dns" "github.com/stretchr/testify/assert" ) @@ -261,3 +262,27 @@ func assertAddress(t testing.TB, expected common.IPPortTuple, endpoint interface assert.Equal(t, expected.SrcIP.String(), e.IP) assert.Equal(t, expected.SrcPort, e.Port) } + +func TestRRsToMapStrsWithOPTRecord(t *testing.T) { + o := new(mkdns.OPT) + o.Hdr.Name = "." // MUST be the root zone, per definition. + o.Hdr.Rrtype = mkdns.TypeOPT + + r := new(mkdns.MX) + r.Hdr = mkdns.RR_Header{Name: "miek.nl.", Rrtype: mkdns.TypeMX, + Class: mkdns.ClassINET, Ttl: 3600} + r.Preference = 10 + r.Mx = "mx.miek.nl." + + // The OPT record is a psuedo-record so it doesn't become a real record + // in our conversion, and there will be 1 entry instead of 2. + mapStrs := rrsToMapStrs([]mkdns.RR{o, r}) + assert.Len(t, mapStrs, 1) + + mapStr := mapStrs[0] + assert.Equal(t, "IN", mapStr["class"]) + assert.Equal(t, "MX", mapStr["type"]) + assert.Equal(t, "mx.miek.nl.", mapStr["data"]) + assert.Equal(t, "miek.nl.", mapStr["name"]) + assert.EqualValues(t, 10, mapStr["preference"]) +}