fix: reduce warning by using idna profile

fixes https://github.com/kubernetes-sigs/external-dns/issues/5581, tested by running test with -v and added println("warn") to the log warning path

Signed-off-by: Sandor Szuecs <sandor.szuecs@zalando.de>
This commit is contained in:
Sandor Szuecs 2025-06-29 12:06:24 +02:00
parent 2d898cd88d
commit c0bde065c2
No known key found for this signature in database
GPG Key ID: 88AE151C28BECE6B
2 changed files with 24 additions and 4 deletions

View File

@ -339,10 +339,16 @@ func filterRecordsForPlan(records []*endpoint.Endpoint, domainFilter endpoint.Ma
return filtered
}
var idnaProfile = idna.New(
idna.MapForLookup(),
idna.Transitional(true),
idna.StrictDomainName(false),
)
// normalizeDNSName converts a DNS name to a canonical form, so that we can use string equality
// it: removes space, get ASCII version of dnsName complient with Section 5 of RFC 5891, ensures there is a trailing dot
func normalizeDNSName(dnsName string) string {
s, err := idna.Lookup.ToASCII(strings.TrimSpace(dnsName))
s, err := idnaProfile.ToASCII(strings.TrimSpace(dnsName))
if err != nil {
log.Warnf(`Got error while parsing DNSName %s: %v`, dnsName, err)
}

View File

@ -1028,7 +1028,7 @@ func validateEntries(t *testing.T, entries, expected []*endpoint.Endpoint) {
}
}
func TestNormalizeDNSName(t *testing.T) {
func TestNormalizeDNSName(tt *testing.T) {
records := []struct {
dnsName string
expect string
@ -1061,6 +1061,18 @@ func TestNormalizeDNSName(t *testing.T) {
"foo.com.",
"foo.com.",
},
{
"_foo.com.",
"_foo.com.",
},
{
"\u005Ffoo.com.",
"_foo.com.",
},
{
".foo.com.",
".foo.com.",
},
{
"foo123.COM",
"foo123.com.",
@ -1099,8 +1111,10 @@ func TestNormalizeDNSName(t *testing.T) {
},
}
for _, r := range records {
gotName := normalizeDNSName(r.dnsName)
assert.Equal(t, r.expect, gotName)
tt.Run(r.dnsName, func(t *testing.T) {
gotName := normalizeDNSName(r.dnsName)
assert.Equal(t, r.expect, gotName)
})
}
}