aboutsummaryrefslogtreecommitdiff
path: root/plugin
diff options
context:
space:
mode:
authorGravatar Miek Gieben <miek@miek.nl> 2020-03-13 14:23:10 +0100
committerGravatar GitHub <noreply@github.com> 2020-03-13 14:23:10 +0100
commitc52a51fac82e7e0bfc36357997209c78be74d8d5 (patch)
treed9284ae17d894efc1d963728c33b3859d7ae4d10 /plugin
parent68ddba05da4743523cb5ee26838b14af601996d8 (diff)
downloadcoredns-c52a51fac82e7e0bfc36357997209c78be74d8d5.tar.gz
coredns-c52a51fac82e7e0bfc36357997209c78be74d8d5.tar.zst
coredns-c52a51fac82e7e0bfc36357997209c78be74d8d5.zip
parse.HostPortorFile: return error when 0 found (#3742)
* parse.HostPortorFile: return error when 0 found Return an error when we haven't found any nameservers. This is the alternative considered in #3735. It's also slighly less code to be changing. Replaces: #3741 Closes: #3741 #3735 Signed-off-by: Miek Gieben <miek@miek.nl> * Add extra test case here as well Signed-off-by: Miek Gieben <miek@miek.nl>
Diffstat (limited to 'plugin')
-rw-r--r--plugin/forward/setup_test.go5
-rw-r--r--plugin/pkg/parse/host.go3
-rw-r--r--plugin/pkg/parse/host_test.go5
3 files changed, 13 insertions, 0 deletions
diff --git a/plugin/forward/setup_test.go b/plugin/forward/setup_test.go
index 0ac5c3e18..0949e0935 100644
--- a/plugin/forward/setup_test.go
+++ b/plugin/forward/setup_test.go
@@ -139,6 +139,8 @@ nameserver 10.10.255.253`), 0666); err != nil {
}{
// pass
{`forward . ` + resolv, false, "", []string{"10.10.255.252:53", "10.10.255.253:53"}},
+ // fail
+ {`forward . /dev/null`, true, "no nameservers", nil},
}
for i, test := range tests {
@@ -168,6 +170,9 @@ nameserver 10.10.255.253`), 0666); err != nil {
}
}
}
+ if test.shouldErr {
+ continue
+ }
for _, p := range f.proxies {
p.health.Check(p) // this should almost always err, we don't care it shouldn't crash
}
diff --git a/plugin/pkg/parse/host.go b/plugin/pkg/parse/host.go
index c1b7d23e0..67cfa86d8 100644
--- a/plugin/pkg/parse/host.go
+++ b/plugin/pkg/parse/host.go
@@ -69,6 +69,9 @@ func HostPortOrFile(s ...string) ([]string, error) {
}
servers = append(servers, h)
}
+ if len(servers) == 0 {
+ return servers, fmt.Errorf("no nameservers found")
+ }
return servers, nil
}
diff --git a/plugin/pkg/parse/host_test.go b/plugin/pkg/parse/host_test.go
index 1c23c5bee..274eed225 100644
--- a/plugin/pkg/parse/host_test.go
+++ b/plugin/pkg/parse/host_test.go
@@ -54,6 +54,11 @@ func TestHostPortOrFile(t *testing.T) {
"[fd01::1%ens3]:153",
false,
},
+ {
+ "8.9.1043",
+ "",
+ true,
+ },
}
err := ioutil.WriteFile("resolv.conf", []byte("nameserver 127.0.0.1\n"), 0600)