diff --git a/client/client.go b/client/client.go index 00a2af44..f82f7ee2 100644 --- a/client/client.go +++ b/client/client.go @@ -499,6 +499,13 @@ func QueryDNS(queryType, queryName, url string) (connected bool, dnsRcode string if srv, ok := rr.(*dns.SRV); ok { 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: body = []byte("query type is not supported yet") } diff --git a/client/client_test.go b/client/client_test.go index 5ed9d8cb..24e31fc4 100644 --- a/client/client_test.go +++ b/client/client_test.go @@ -507,6 +507,16 @@ func TestQueryDNS(t *testing.T) { expectedDNSCode: "NOERROR", 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", inputDNS: dns.Config{ @@ -526,8 +536,8 @@ func TestQueryDNS(t *testing.T) { if dnsRCode != scenario.expectedDNSCode { t.Errorf("expected DNSRCode to be %s, got %s", scenario.expectedDNSCode, dnsRCode) } - if scenario.inputDNS.QueryType == "NS" { - // Because there are often multiple nameservers backing a single domain, we'll only look at the suffix + if scenario.inputDNS.QueryType == "NS" || scenario.inputDNS.QueryType == "TXT" { + // Some record types can have multiple valid answers, so wildcard matching is used in those scenarios if !pattern.Match(scenario.expectedBody, string(body)) { t.Errorf("got %s, expected result %s,", string(body), scenario.expectedBody) }