Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions SYNTAX-REFERENCE.md
Original file line number Diff line number Diff line change
Expand Up @@ -2898,6 +2898,16 @@ Enum Values:
- <code>ANY</code>

- <code>SRV</code>

- <code>RRSIG</code>

- <code>NSEC</code>

- <code>DNSKEY</code>

- <code>NSEC3</code>

- <code>NSEC3PARAM</code>
</div>

<hr />
Expand Down
12 changes: 11 additions & 1 deletion pkg/protocols/dns/dns.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ type Request struct {
Name string `yaml:"name,omitempty" json:"name,omitempty" jsonschema:"title=hostname to make dns request for,description=Name is the Hostname to make DNS request for"`
// description: |
// RequestType is the type of DNS request to make.
RequestType DNSRequestTypeHolder `yaml:"type,omitempty" json:"type,omitempty" jsonschema:"title=type of dns request to make,description=Type is the type of DNS request to make,enum=A,enum=NS,enum=DS,enum=CNAME,enum=SOA,enum=PTR,enum=MX,enum=TXT,enum=AAAA"`
RequestType DNSRequestTypeHolder `yaml:"type,omitempty" json:"type,omitempty" jsonschema:"title=type of dns request to make,description=Type is the type of DNS request to make,enum=A,enum=NS,enum=DS,enum=CNAME,enum=SOA,enum=PTR,enum=MX,enum=TXT,enum=AAAA,enum=CAA,enum=TLSA,enum=ANY,enum=SRV,enum=RRSIG,enum=NSEC,enum=DNSKEY,enum=NSEC3,enum=NSEC3PARAM"`
// description: |
// Class is the class of the DNS request.
//
Expand Down Expand Up @@ -309,6 +309,16 @@ func questionTypeToInt(questionType string) uint16 {
question = dns.TypeANY
case "SRV":
question = dns.TypeSRV
case "RRSIG":
question = dns.TypeRRSIG
case "NSEC":
question = dns.TypeNSEC
case "DNSKEY":
question = dns.TypeDNSKEY
case "NSEC3":
question = dns.TypeNSEC3
case "NSEC3PARAM":
question = dns.TypeNSEC3PARAM
}
return question
}
Expand Down
41 changes: 28 additions & 13 deletions pkg/protocols/dns/dns_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,24 +39,39 @@ const (
ANY
// name:SRV
SRV
// name:RRSIG
RRSIG
// name:NSEC
NSEC
// name:DNSKEY
DNSKEY
// name:NSEC3
NSEC3
// name:NSEC3PARAM
NSEC3PARAM
limit
)

// DNSRequestTypeMapping is a table for conversion of method from string.
var DNSRequestTypeMapping = map[DNSRequestType]string{
A: "A",
NS: "NS",
DS: "DS",
CNAME: "CNAME",
SOA: "SOA",
PTR: "PTR",
MX: "MX",
TXT: "TXT",
AAAA: "AAAA",
CAA: "CAA",
TLSA: "TLSA",
ANY: "ANY",
SRV: "SRV",
A: "A",
NS: "NS",
DS: "DS",
CNAME: "CNAME",
SOA: "SOA",
PTR: "PTR",
MX: "MX",
TXT: "TXT",
AAAA: "AAAA",
CAA: "CAA",
TLSA: "TLSA",
ANY: "ANY",
SRV: "SRV",
RRSIG: "RRSIG",
NSEC: "NSEC",
DNSKEY: "DNSKEY",
NSEC3: "NSEC3",
NSEC3PARAM: "NSEC3PARAM",
}

// GetSupportedDNSRequestTypes returns list of supported types
Expand Down
92 changes: 92 additions & 0 deletions pkg/protocols/dns/dns_types_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
package dns

import (
"testing"

"github.com/miekg/dns"
"github.com/stretchr/testify/require"
)

func TestToDNSRequestTypesDNSSEC(t *testing.T) {
tests := []struct {
input string
expected DNSRequestType
}{
{"NSEC", NSEC},
{"nsec", NSEC},
{"NSEC3", NSEC3},
{"NSEC3PARAM", NSEC3PARAM},
{"DNSKEY", DNSKEY},
{"RRSIG", RRSIG},
{"rrsig", RRSIG},
}
for _, tt := range tests {
t.Run(tt.input, func(t *testing.T) {
got, err := toDNSRequestTypes(tt.input)
require.NoError(t, err)
require.Equal(t, tt.expected, got)
require.Equal(t, normalizeValue(tt.expected.String()), normalizeValue(tt.input))
})
}
}

func TestToDNSRequestTypesInvalid(t *testing.T) {
_, err := toDNSRequestTypes("NOTAREALTYPE")
require.Error(t, err)
}

func TestQuestionTypeToIntDNSSEC(t *testing.T) {
tests := []struct {
input string
expected uint16
}{
{"NSEC", dns.TypeNSEC},
{"NSEC3", dns.TypeNSEC3},
{"NSEC3PARAM", dns.TypeNSEC3PARAM},
{"DNSKEY", dns.TypeDNSKEY},
{"RRSIG", dns.TypeRRSIG},
{"A", dns.TypeA},
}
for _, tt := range tests {
t.Run(tt.input, func(t *testing.T) {
require.Equal(t, tt.expected, questionTypeToInt(tt.input))
})
}
}

func TestGetSupportedDNSRequestTypesIncludesDNSSEC(t *testing.T) {
supported := GetSupportedDNSRequestTypes()
require.Contains(t, supported, NSEC)
require.Contains(t, supported, NSEC3)
require.Contains(t, supported, NSEC3PARAM)
require.Contains(t, supported, DNSKEY)
require.Contains(t, supported, RRSIG)
}

func TestMakeDNSRequestNSECQuestion(t *testing.T) {
recursion := false
request := &Request{
RequestType: DNSRequestTypeHolder{DNSRequestType: NSEC},
Name: "{{FQDN}}",
Class: "inet",
Recursion: &recursion,
}
request.question = questionTypeToInt(request.RequestType.String())
request.class = classToInt(request.Class)

msg, err := request.Make("example.com", map[string]interface{}{"FQDN": "example.com"})
require.NoError(t, err)
require.Len(t, msg.Question, 1)
require.Equal(t, dns.TypeNSEC, msg.Question[0].Qtype)
require.Equal(t, "example.com.", msg.Question[0].Name)
}

func TestDNSRequestTypeHolderUnmarshalYAMLDNSSEC(t *testing.T) {
var holder DNSRequestTypeHolder
err := holder.UnmarshalYAML(func(v interface{}) error {
*v.(*string) = "NSEC3"
return nil
})
require.NoError(t, err)
require.Equal(t, NSEC3, holder.DNSRequestType)
}
5 changes: 5 additions & 0 deletions pkg/templates/templates_doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -1225,6 +1225,11 @@ func init() {
"TLSA",
"ANY",
"SRV",
"RRSIG",
"NSEC",
"DNSKEY",
"NSEC3",
"NSEC3PARAM",
}

FILERequestDoc.Type = "file.Request"
Expand Down
Loading