Skip to content

Commit

Permalink
add test
Browse files Browse the repository at this point in the history
update README
  • Loading branch information
dmachard committed Nov 30, 2024
1 parent 7939b97 commit 9595ca2
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 4 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<p align="center">
<img src="https://goreportcard.com/badge/github.com/dmachard/go-dns-collector" alt="Go Report"/>
<img src="https://img.shields.io/badge/go%20version-min%201.21-green" alt="Go version"/>
<img src="https://img.shields.io/badge/go%20tests-508-green" alt="Go tests"/>
<img src="https://img.shields.io/badge/go%20tests-509-green" alt="Go tests"/>
<img src="https://img.shields.io/badge/go%20bench-21-green" alt="Go bench"/>
<img src="https://img.shields.io/badge/go%20lines-31977-green" alt="Go lines"/>
</p>
Expand Down
37 changes: 34 additions & 3 deletions dnsutils/dns_parser_payload_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ func TestDecodePayload_QueryHappy(t *testing.T) {

if dm.DNS.ID != 0x9e84 ||
dm.DNS.Opcode != 0 ||
dm.DNS.Rcode != RcodeToString(0) ||
dm.DNS.Flags.QR ||
dm.DNS.Flags.TC ||
dm.DNS.Flags.AA ||
Expand Down Expand Up @@ -72,7 +71,6 @@ func TestDecodePayload_QueryHappy(t *testing.T) {
len(dm.DNS.DNSRRs.Records) != 0 {
t.Errorf("Unexpected sections parsed")
}

}
func TestDecodePayload_QueryInvalid(t *testing.T) {
payload := []byte{
Expand Down Expand Up @@ -996,7 +994,6 @@ func TestDecodePayload_Truncated(t *testing.T) {
if dm.DNS.MalformedPacket != true {
t.Errorf("expected packet to be malformed")
}

}

// Dynamic query (UPDATE)
Expand Down Expand Up @@ -1086,3 +1083,37 @@ func TestDecodePayload_MDNSResponseWithNoQuestion(t *testing.T) {
t.Error("expected no error on decode", err)
}
}

// Rcode should not be set on query
func TestDecodePayload_Query_NoRcode(t *testing.T) {
payload := []byte{
// transaction ID
0xb1, 0x17,
// flags
0x01, 0x00,
// questions
0x00, 0x01,
// answer
0x00, 0x00,
// authority
0x00, 0x00,
// additional
0x00, 0x00,
// queries
0x00, 0x00, 0x06, 0x00, 0x01,
}

dm := DNSMessage{}
dm.Init()
dm.DNS.Payload = payload
dm.DNS.Length = len(payload)

// decode header and paylo
header, _ := DecodeDNS(payload)
DecodePayload(&dm, &header, pkgconfig.GetDefaultConfig())

// check the rcode
if dm.DNS.Rcode != "-" {
t.Errorf("invalid rcode: %s", dm.DNS.Rcode)
}
}

0 comments on commit 9595ca2

Please sign in to comment.