feat(dns): Support TXT query type (#1679)
Allows monitoring of things like spf records and others. Co-authored-by: TwiN <twin@linux.com>
This commit is contained in:
1 parent
809e5068d7
commit
08895200bb
2 files changed
+19
-2
No files matched your search
@@ -499,6 +499,13 @@ func QueryDNS(queryType, queryName, url string) (connected bool, dnsRcode string
|
|||||||
if srv, ok := rr.(*dns.SRV); ok {
|
if srv, ok := rr.(*dns.SRV); ok {
|
||||||
body = []byte(fmt.Sprintf("%s:%d", srv.Target, srv.Port))
|
body = []byte(fmt.Sprintf("%s:%d", srv.Target, srv.Port))
|
||||||
}
|
}
|
||||||
|
case dns.TypeTXT:
|
||||||
|
if txt, ok := rr.(*dns.TXT); ok {
|
||||||
|
if len(body) > 0 {
|
||||||
|
body = append(body, '\n')
|
||||||
|
}
|
||||||
|
body = append(body, []byte(strings.Join(txt.Txt, ""))...)
|
||||||
|
}
|
||||||
default:
|
default:
|
||||||
body = []byte("query type is not supported yet")
|
body = []byte("query type is not supported yet")
|
||||||
}
|
}
|
||||||
|
|||||||
+12
-2
@@ -507,6 +507,16 @@ func TestQueryDNS(t *testing.T) {
|
|||||||
expectedDNSCode: "NOERROR",
|
expectedDNSCode: "NOERROR",
|
||||||
expectedBody: "one.one.one.one.",
|
expectedBody: "one.one.one.one.",
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: "test Config with type TXT",
|
||||||
|
inputDNS: dns.Config{
|
||||||
|
QueryType: "TXT",
|
||||||
|
QueryName: "example.com.",
|
||||||
|
},
|
||||||
|
inputURL: "1.1.1.1",
|
||||||
|
expectedDNSCode: "NOERROR",
|
||||||
|
expectedBody: "*v=spf1*",
|
||||||
|
},
|
||||||
{
|
{
|
||||||
name: "test Config with fake type and retrieve error",
|
name: "test Config with fake type and retrieve error",
|
||||||
inputDNS: dns.Config{
|
inputDNS: dns.Config{
|
||||||
@@ -526,8 +536,8 @@ func TestQueryDNS(t *testing.T) {
|
|||||||
if dnsRCode != scenario.expectedDNSCode {
|
if dnsRCode != scenario.expectedDNSCode {
|
||||||
t.Errorf("expected DNSRCode to be %s, got %s", scenario.expectedDNSCode, dnsRCode)
|
t.Errorf("expected DNSRCode to be %s, got %s", scenario.expectedDNSCode, dnsRCode)
|
||||||
}
|
}
|
||||||
if scenario.inputDNS.QueryType == "NS" {
|
if scenario.inputDNS.QueryType == "NS" || scenario.inputDNS.QueryType == "TXT" {
|
||||||
// Because there are often multiple nameservers backing a single domain, we'll only look at the suffix
|
// Some record types can have multiple valid answers, so wildcard matching is used in those scenarios
|
||||||
if !pattern.Match(scenario.expectedBody, string(body)) {
|
if !pattern.Match(scenario.expectedBody, string(body)) {
|
||||||
t.Errorf("got %s, expected result %s,", string(body), scenario.expectedBody)
|
t.Errorf("got %s, expected result %s,", string(body), scenario.expectedBody)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user