aboutsummaryrefslogtreecommitdiff
path: root/plugin/forward/setup_test.go
diff options
context:
space:
mode:
authorGravatar Vancl <liyannois@gmail.com> 2022-08-15 22:16:15 +0800
committerGravatar GitHub <noreply@github.com> 2022-08-15 10:16:15 -0400
commit4033d7aebab8918f92a49fc85cb2b37ef831294e (patch)
treef85e8f9f12b2a8aa8cf6b20f1e0b18bfba782912 /plugin/forward/setup_test.go
parent22e77b2cf2c9f468a9073ce2fa6d012a839927a8 (diff)
downloadcoredns-4033d7aebab8918f92a49fc85cb2b37ef831294e.tar.gz
coredns-4033d7aebab8918f92a49fc85cb2b37ef831294e.tar.zst
coredns-4033d7aebab8918f92a49fc85cb2b37ef831294e.zip
plugin/forward: health_check needs to normalize a specified domain name (#5543)
* plugin/forward: convert the specified domain of health_check to Fqdn * plugin/forward: update readme for health check Signed-off-by: vanceli <vanceli@tencent.com>
Diffstat (limited to 'plugin/forward/setup_test.go')
-rw-r--r--plugin/forward/setup_test.go13
1 files changed, 9 insertions, 4 deletions
diff --git a/plugin/forward/setup_test.go b/plugin/forward/setup_test.go
index 829e1f745..4b1743098 100644
--- a/plugin/forward/setup_test.go
+++ b/plugin/forward/setup_test.go
@@ -8,6 +8,8 @@ import (
"github.com/coredns/caddy"
"github.com/coredns/coredns/core/dnsserver"
+
+ "github.com/miekg/dns"
)
func TestSetup(t *testing.T) {
@@ -22,7 +24,7 @@ func TestSetup(t *testing.T) {
}{
// positive
{"forward . 127.0.0.1", false, ".", nil, 2, options{hcRecursionDesired: true, hcDomain: "."}, ""},
- {"forward . 127.0.0.1 {\nhealth_check 0.5s domain example.org\n}\n", false, ".", nil, 2, options{hcRecursionDesired: true, hcDomain: "example.org"}, ""},
+ {"forward . 127.0.0.1 {\nhealth_check 0.5s domain example.org\n}\n", false, ".", nil, 2, options{hcRecursionDesired: true, hcDomain: "example.org."}, ""},
{"forward . 127.0.0.1 {\nexcept miek.nl\n}\n", false, ".", nil, 2, options{hcRecursionDesired: true, hcDomain: "."}, ""},
{"forward . 127.0.0.1 {\nmax_fails 3\n}\n", false, ".", nil, 3, options{hcRecursionDesired: true, hcDomain: "."}, ""},
{"forward . 127.0.0.1 {\nforce_tcp\n}\n", false, ".", nil, 2, options{forceTCP: true, hcRecursionDesired: true, hcDomain: "."}, ""},
@@ -243,13 +245,16 @@ func TestSetupHealthCheck(t *testing.T) {
{"forward . 127.0.0.1\n", false, true, ".", ""},
{"forward . 127.0.0.1 {\nhealth_check 0.5s\n}\n", false, true, ".", ""},
{"forward . 127.0.0.1 {\nhealth_check 0.5s no_rec\n}\n", false, false, ".", ""},
- {"forward . 127.0.0.1 {\nhealth_check 0.5s no_rec domain example.org\n}\n", false, false, "example.org", ""},
- {"forward . 127.0.0.1 {\nhealth_check 0.5s domain example.org\n}\n", false, true, "example.org", ""},
+ {"forward . 127.0.0.1 {\nhealth_check 0.5s no_rec domain example.org\n}\n", false, false, "example.org.", ""},
+ {"forward . 127.0.0.1 {\nhealth_check 0.5s domain example.org\n}\n", false, true, "example.org.", ""},
+ {"forward . 127.0.0.1 {\nhealth_check 0.5s domain .\n}\n", false, true, ".", ""},
+ {"forward . 127.0.0.1 {\nhealth_check 0.5s domain example.org.\n}\n", false, true, "example.org.", ""},
// negative
{"forward . 127.0.0.1 {\nhealth_check no_rec\n}\n", true, true, ".", "time: invalid duration"},
{"forward . 127.0.0.1 {\nhealth_check domain example.org\n}\n", true, true, "example.org", "time: invalid duration"},
{"forward . 127.0.0.1 {\nhealth_check 0.5s rec\n}\n", true, true, ".", "health_check: unknown option rec"},
{"forward . 127.0.0.1 {\nhealth_check 0.5s domain\n}\n", true, true, ".", "Wrong argument count or unexpected line ending after 'domain'"},
+ {"forward . 127.0.0.1 {\nhealth_check 0.5s domain example..org\n}\n", true, true, ".", "health_check: invalid domain name"},
}
for i, test := range tests {
@@ -275,7 +280,7 @@ func TestSetupHealthCheck(t *testing.T) {
f := fs[0]
if f.opts.hcRecursionDesired != test.expectedRecVal || f.proxies[0].health.GetRecursionDesired() != test.expectedRecVal ||
- f.opts.hcDomain != test.expectedDomain || f.proxies[0].health.GetDomain() != test.expectedDomain {
+ f.opts.hcDomain != test.expectedDomain || f.proxies[0].health.GetDomain() != test.expectedDomain || !dns.IsFqdn(f.proxies[0].health.GetDomain()) {
t.Errorf("Test %d: expectedRec: %v, got: %v. expectedDomain: %s, got: %s. ", i, test.expectedRecVal, f.opts.hcRecursionDesired, test.expectedDomain, f.opts.hcDomain)
}
}