Skip to content

Commit

Permalink
Added a DNS test case for rrsToMapStrs with a OPT resource record
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewkroh committed Oct 28, 2016
1 parent cbde106 commit 7c2fe09
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions packetbeat/protos/dns/dns_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -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"])
}

0 comments on commit 7c2fe09

Please sign in to comment.