package main
import (
+ "errors"
"fmt"
"strings"
"sync"
if err := checkOverflow(s.XXX, "dns probe"); err != nil {
return err
}
+ if s.QueryName == "" {
+ return errors.New("Query name must be set for DNS module")
+ }
return nil
}
}
}
-func TestLoadBadConfig(t *testing.T) {
+func TestLoadBadConfigs(t *testing.T) {
sc := &SafeConfig{
C: &Config{},
}
-
- expected := "unknown fields in dns probe: invalid_extra_field"
-
- err := sc.reloadConfig("testdata/blackbox-bad.yml")
- if err.Error() != expected {
- t.Errorf("\nexpected:\n%v\ngot:\n%v", expected, err.Error())
+ tests := []struct {
+ ConfigFile string
+ ExpectedError string
+ }{
+ {
+ ConfigFile: "testdata/blackbox-bad.yml",
+ ExpectedError: "unknown fields in dns probe: invalid_extra_field",
+ },
+ {
+ ConfigFile: "testdata/invalid-dns-module.yml",
+ ExpectedError: "Query name must be set for DNS module",
+ },
+ }
+ for i, test := range tests {
+ err := sc.reloadConfig(test.ConfigFile)
+ if err.Error() != test.ExpectedError {
+ t.Errorf("In case %v:\nExpected:\n%v\nGot:\n%v", i, test.ExpectedError, err.Error())
+ }
}
}
func TestHideConfigSecrets(t *testing.T) {
-
sc := &SafeConfig{
C: &Config{},
}
}()
var ip *net.IPAddr
- var err error
-
if module.DNS.TransportProtocol == "" {
module.DNS.TransportProtocol = "udp"
}
if module.DNS.TransportProtocol == "udp" || module.DNS.TransportProtocol == "tcp" {
- targetAddr, port, _ := net.SplitHostPort(target)
- if port == "" {
+ targetAddr, port, err := net.SplitHostPort(target)
+ if err != nil {
+ // Target only contains host so fallback to default port and set targetAddr as target.
port = "53"
+ targetAddr = target
}
ip, err = chooseProtocol(module.DNS.PreferredIPProtocol, targetAddr, registry)
if err != nil {
timeoutDeadline, _ := ctx.Deadline()
client.Timeout = timeoutDeadline.Sub(time.Now())
-
response, _, err := client.Exchange(msg, target)
if err != nil {
log.Warnf("Error while sending a DNS query: %s", err)
prober: dns
timeout: 5s
dns:
- preferred_ip_protocol: ip6
+ query_name: example.com
+ preferred_ip_protocol: ip4
validate_answer_rrs:
fail_if_matches_regexp: [test]
--- /dev/null
+modules:
+ dns_test:
+ prober: dns
+ timeout: 5s
+ dns:
+ preferred_ip_protocol: ip6
+ validate_answer_rrs:
+ fail_if_matches_regexp: [test]