Make skip_fqdn_check error message easier to understand and fix (#1477)

This commit is contained in:
Tom Limoncelli 2022-04-04 14:05:49 -04:00 committed by GitHub
parent 2e16f7b142
commit 99210c9d1c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 54 additions and 3 deletions

View file

@ -1185,3 +1185,18 @@ function DOMAIN_ELSEWHERE_AUTO(domain, registrar, dsplist) {
D_EXTEND(domain, DnsProvider(arguments[i]));
}
}
var END = {}; // This is null. It permits the last item to include a comma.
// D("foo.com", ...
// A(...),
// A(...),
// A(...),
// END)
// Record modifiers:
// Permit labels like "foo.bar.com.bar.com" (normally an error):
var DISABLE_REPEATED_DOMAIN_CHECK = { skip_fqdn_check: "true" };
// D("bar.com", ...
// A("foo.bar.com", "10.1.1.1", DISABLE_REPEATED_DOMAIN_CHECK),
// )

View file

@ -89,6 +89,16 @@ func validateRecordTypes(rec *models.RecordConfig, domain string, pTypes []strin
return nil
}
func errorRepeat(label, domain string) string {
shortname := strings.TrimSuffix(label, "."+domain)
return fmt.Sprintf(
`The name "%s.%s." is an error (repeats the domain). Maybe instead of "%s" you intended "%s"? If not add DISABLE_REPEATED_DOMAIN_CHECK to this record to permit this as-is.`,
label, domain,
label,
shortname,
)
}
func checkLabel(label string, rType string, target, domain string, meta map[string]string) error {
if label == "@" {
return nil
@ -101,7 +111,7 @@ func checkLabel(label string, rType string, target, domain string, meta map[stri
}
if label == domain || strings.HasSuffix(label, "."+domain) {
if m := meta["skip_fqdn_check"]; m != "true" {
return fmt.Errorf(`label %q ends with domain name %q. Record names should not be fully qualified. Add {skip_fqdn_check:"true"} to this record if you really want to make %s.%s`, label, domain, label, domain)
return fmt.Errorf(errorRepeat(label, domain))
}
}

View file

@ -1,9 +1,8 @@
package normalize
import (
"testing"
"fmt"
"testing"
"github.com/StackExchange/dnscontrol/v3/models"
"github.com/StackExchange/dnscontrol/v3/providers"
@ -432,3 +431,30 @@ func Test_DSChecks(t *testing.T) {
})
})
}
func Test_errorRepeat(t *testing.T) {
type args struct {
label string
domain string
}
tests := []struct {
name string
args args
want string
}{
{
name: "1",
args: args{label: "foo.bar.com", domain: "bar.com"},
want: `The name "foo.bar.com.bar.com." is an error (repeats the domain).` +
` Maybe instead of "foo.bar.com" you intended "foo"?` +
` If not add DISABLE_REPEATED_DOMAIN_CHECK to this record to permit this as-is.`,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := errorRepeat(tt.args.label, tt.args.domain); got != tt.want {
t.Errorf("errorRepeat() = \n'%s', want\n'%s'", got, tt.want)
}
})
}
}