mirror of
https://github.com/StackExchange/dnscontrol.git
synced 2024-05-11 05:55:12 +00:00
Make skip_fqdn_check error message easier to understand and fix (#1477)
This commit is contained in:
@@ -1185,3 +1185,18 @@ function DOMAIN_ELSEWHERE_AUTO(domain, registrar, dsplist) {
|
|||||||
D_EXTEND(domain, DnsProvider(arguments[i]));
|
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),
|
||||||
|
// )
|
||||||
|
|||||||
@@ -89,6 +89,16 @@ func validateRecordTypes(rec *models.RecordConfig, domain string, pTypes []strin
|
|||||||
return nil
|
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 {
|
func checkLabel(label string, rType string, target, domain string, meta map[string]string) error {
|
||||||
if label == "@" {
|
if label == "@" {
|
||||||
return nil
|
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 label == domain || strings.HasSuffix(label, "."+domain) {
|
||||||
if m := meta["skip_fqdn_check"]; m != "true" {
|
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))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,9 +1,8 @@
|
|||||||
package normalize
|
package normalize
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"testing"
|
|
||||||
|
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"testing"
|
||||||
|
|
||||||
"github.com/StackExchange/dnscontrol/v3/models"
|
"github.com/StackExchange/dnscontrol/v3/models"
|
||||||
"github.com/StackExchange/dnscontrol/v3/providers"
|
"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)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user