mirror of
https://github.com/kubernetes-sigs/external-dns.git
synced 2025-08-06 17:46:57 +02:00
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:
parent
2d898cd88d
commit
c0bde065c2
@ -339,10 +339,16 @@ func filterRecordsForPlan(records []*endpoint.Endpoint, domainFilter endpoint.Ma
|
|||||||
return filtered
|
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
|
// 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
|
// 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 {
|
func normalizeDNSName(dnsName string) string {
|
||||||
s, err := idna.Lookup.ToASCII(strings.TrimSpace(dnsName))
|
s, err := idnaProfile.ToASCII(strings.TrimSpace(dnsName))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Warnf(`Got error while parsing DNSName %s: %v`, dnsName, err)
|
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 {
|
records := []struct {
|
||||||
dnsName string
|
dnsName string
|
||||||
expect string
|
expect string
|
||||||
@ -1061,6 +1061,18 @@ func TestNormalizeDNSName(t *testing.T) {
|
|||||||
"foo.com.",
|
"foo.com.",
|
||||||
"foo.com.",
|
"foo.com.",
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"_foo.com.",
|
||||||
|
"_foo.com.",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"\u005Ffoo.com.",
|
||||||
|
"_foo.com.",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
".foo.com.",
|
||||||
|
".foo.com.",
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"foo123.COM",
|
"foo123.COM",
|
||||||
"foo123.com.",
|
"foo123.com.",
|
||||||
@ -1099,8 +1111,10 @@ func TestNormalizeDNSName(t *testing.T) {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
for _, r := range records {
|
for _, r := range records {
|
||||||
gotName := normalizeDNSName(r.dnsName)
|
tt.Run(r.dnsName, func(t *testing.T) {
|
||||||
assert.Equal(t, r.expect, gotName)
|
gotName := normalizeDNSName(r.dnsName)
|
||||||
|
assert.Equal(t, r.expect, gotName)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user