mirror of
https://github.com/StackExchange/dnscontrol.git
synced 2024-05-11 05:55:12 +00:00
Allow for Name's that start with _ (#830)
* Allow for Name's that start with _ * update tests Co-authored-by: Tom Limoncelli <tlimoncelli@stackoverflow.com>
This commit is contained in:
@@ -85,20 +85,6 @@ func validateRecordTypes(rec *models.RecordConfig, domain string, pTypes []strin
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// underscores in names are often used erroneously. They are valid for dns records, but invalid for urls.
|
|
||||||
// here we list common records expected to have underscores. Anything else containing an underscore will print a warning.
|
|
||||||
var labelUnderscores = []string{
|
|
||||||
"_acme-challenge",
|
|
||||||
"_amazonses",
|
|
||||||
"_dmarc",
|
|
||||||
"_domainconnect",
|
|
||||||
"_domainkey",
|
|
||||||
"_jabber",
|
|
||||||
"_mta-sts",
|
|
||||||
"_sip",
|
|
||||||
"_xmpp",
|
|
||||||
}
|
|
||||||
|
|
||||||
// these record types may contain underscores
|
// these record types may contain underscores
|
||||||
var rTypeUnderscores = []string{"SRV", "TLSA", "TXT"}
|
var rTypeUnderscores = []string{"SRV", "TLSA", "TXT"}
|
||||||
|
|
||||||
@@ -127,17 +113,12 @@ func checkLabel(label string, rType string, target, domain string, meta map[stri
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Don't warn for CNAMEs if the target ends with acm-validations.aws
|
// Don't warn for records that start with _
|
||||||
// See https://github.com/StackExchange/dnscontrol/issues/519
|
// See https://github.com/StackExchange/dnscontrol/issues/829
|
||||||
if strings.HasPrefix(label, "_") && rType == "CNAME" && strings.HasSuffix(target, ".acm-validations.aws.") {
|
if strings.HasPrefix(label, "_") || strings.Contains(label, "._") {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
// Don't warn for certain label substrings
|
|
||||||
for _, ex := range labelUnderscores {
|
|
||||||
if strings.Contains(label, ex) {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// Otherwise, warn.
|
// Otherwise, warn.
|
||||||
if strings.ContainsRune(label, '_') {
|
if strings.ContainsRune(label, '_') {
|
||||||
return Warning{fmt.Errorf("label %s.%s contains an underscore", label, domain)}
|
return Warning{fmt.Errorf("label %s.%s contains an underscore", label, domain)}
|
||||||
|
@@ -19,17 +19,18 @@ func TestCheckLabel(t *testing.T) {
|
|||||||
}{
|
}{
|
||||||
{"@", "A", "zap", false, false},
|
{"@", "A", "zap", false, false},
|
||||||
{"foo.bar", "A", "zap", false, false},
|
{"foo.bar", "A", "zap", false, false},
|
||||||
{"_foo", "A", "zap", true, false},
|
{"_foo", "A", "zap", false, false},
|
||||||
{"_foo", "SRV", "zap", false, false},
|
{"_foo", "SRV", "zap", false, false},
|
||||||
{"_foo", "TLSA", "zap", false, false},
|
{"_foo", "TLSA", "zap", false, false},
|
||||||
{"_foo", "TXT", "zap", false, false},
|
{"_foo", "TXT", "zap", false, false},
|
||||||
{"_y2", "CNAME", "foo", true, false},
|
{"_y2", "CNAME", "foo", false, false},
|
||||||
|
{"s1._domainkey", "CNAME", "foo", false, false},
|
||||||
{"_y3", "CNAME", "asfljds.acm-validations.aws.", false, false},
|
{"_y3", "CNAME", "asfljds.acm-validations.aws.", false, false},
|
||||||
{"test.foo.tld", "A", "zap", true, false},
|
{"test.foo.tld", "A", "zap", true, false},
|
||||||
{"test.foo.tld", "A", "zap", false, true},
|
{"test.foo.tld", "A", "zap", false, true},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, test := range tests {
|
for i, test := range tests {
|
||||||
t.Run(fmt.Sprintf("%s %s", test.label, test.rType), func(t *testing.T) {
|
t.Run(fmt.Sprintf("%s %s", test.label, test.rType), func(t *testing.T) {
|
||||||
meta := map[string]string{}
|
meta := map[string]string{}
|
||||||
if test.hasSkipMeta {
|
if test.hasSkipMeta {
|
||||||
@@ -37,10 +38,10 @@ func TestCheckLabel(t *testing.T) {
|
|||||||
}
|
}
|
||||||
err := checkLabel(test.label, test.rType, test.target, "foo.tld", meta)
|
err := checkLabel(test.label, test.rType, test.target, "foo.tld", meta)
|
||||||
if err != nil && !test.isError {
|
if err != nil && !test.isError {
|
||||||
t.Errorf(" Expected no error but got %s", err)
|
t.Errorf("%02d: Expected no error but got %s", i, err)
|
||||||
}
|
}
|
||||||
if err == nil && test.isError {
|
if err == nil && test.isError {
|
||||||
t.Errorf(" Expected error but got none")
|
t.Errorf("%02d: Expected error but got none", i)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user