mirror of
https://github.com/kubernetes-sigs/external-dns.git
synced 2025-08-06 01:26:59 +02:00
fix: reduce warning by using idna profile (#5587)
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:
parent
2d898cd88d
commit
56cca87163
@ -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)
|
||||
}
|
||||
|
@ -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)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user