Skip to content

Commit b8170cc

Browse files
szuecstroll-os
authored andcommitted
fix: reduce warning by using idna profile (kubernetes-sigs#5587)
fixes kubernetes-sigs#5581, tested by running test with -v and added println("warn") to the log warning path Signed-off-by: Sandor Szuecs <[email protected]>
1 parent ba78040 commit b8170cc

File tree

2 files changed

+24
-4
lines changed

2 files changed

+24
-4
lines changed

plan/plan.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -346,10 +346,16 @@ func filterRecordsForPlan(records []*endpoint.Endpoint, domainFilter endpoint.Ma
346346
return filtered
347347
}
348348

349+
var idnaProfile = idna.New(
350+
idna.MapForLookup(),
351+
idna.Transitional(true),
352+
idna.StrictDomainName(false),
353+
)
354+
349355
// normalizeDNSName converts a DNS name to a canonical form, so that we can use string equality
350356
// it: removes space, get ASCII version of dnsName complient with Section 5 of RFC 5891, ensures there is a trailing dot
351357
func normalizeDNSName(dnsName string) string {
352-
s, err := idna.Lookup.ToASCII(strings.TrimSpace(dnsName))
358+
s, err := idnaProfile.ToASCII(strings.TrimSpace(dnsName))
353359
if err != nil {
354360
log.Warnf(`Got error while parsing DNSName %s: %v`, dnsName, err)
355361
}

plan/plan_test.go

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1054,7 +1054,7 @@ func validateEntries(t *testing.T, entries, expected []*endpoint.Endpoint) {
10541054
}
10551055
}
10561056

1057-
func TestNormalizeDNSName(t *testing.T) {
1057+
func TestNormalizeDNSName(tt *testing.T) {
10581058
records := []struct {
10591059
dnsName string
10601060
expect string
@@ -1087,6 +1087,18 @@ func TestNormalizeDNSName(t *testing.T) {
10871087
"foo.com.",
10881088
"foo.com.",
10891089
},
1090+
{
1091+
"_foo.com.",
1092+
"_foo.com.",
1093+
},
1094+
{
1095+
"\u005Ffoo.com.",
1096+
"_foo.com.",
1097+
},
1098+
{
1099+
".foo.com.",
1100+
".foo.com.",
1101+
},
10901102
{
10911103
"foo123.COM",
10921104
"foo123.com.",
@@ -1125,8 +1137,10 @@ func TestNormalizeDNSName(t *testing.T) {
11251137
},
11261138
}
11271139
for _, r := range records {
1128-
gotName := normalizeDNSName(r.dnsName)
1129-
assert.Equal(t, r.expect, gotName)
1140+
tt.Run(r.dnsName, func(t *testing.T) {
1141+
gotName := normalizeDNSName(r.dnsName)
1142+
assert.Equal(t, r.expect, gotName)
1143+
})
11301144
}
11311145
}
11321146

0 commit comments

Comments
 (0)