Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions provider/zonefinder.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ import (
"strings"

log "github.com/sirupsen/logrus"
"golang.org/x/net/idna"

"sigs.k8s.io/external-dns/internal/idna"
)

type ZoneIDName map[string]string
Expand Down Expand Up @@ -48,7 +49,7 @@ func (z ZoneIDName) FindZone(hostname string) (string, string) {
if strings.Contains(label, "_") {
continue
}
convertedLabel, err := idna.Lookup.ToUnicode(label)
convertedLabel, err := idna.Profile.ToUnicode(label)
if err != nil {
log.Warnf("Failed to convert label %q of hostname %q to its Unicode form: %v", label, hostname, err)
convertedLabel = label
Expand Down
10 changes: 8 additions & 2 deletions provider/zonefinder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ func TestZoneIDName(t *testing.T) {
z.Add("123123", "_metadata.example.com")
z.Add("1231231", "_foo._metadata.example.com")
z.Add("456456", "_metadata.エイミー.みんな")
z.Add("123412", "*.example.com")

assert.Equal(t, ZoneIDName{
"123456": "qux.baz",
Expand All @@ -42,6 +43,7 @@ func TestZoneIDName(t *testing.T) {
"123123": "_metadata.example.com",
"1231231": "_foo._metadata.example.com",
"456456": "_metadata.エイミー.みんな",
"123412": "*.example.com",
}, z)

// simple entry in a domain
Expand Down Expand Up @@ -83,8 +85,12 @@ func TestZoneIDName(t *testing.T) {
assert.Equal(t, "_foo._metadata.example.com", zoneName)
assert.Equal(t, "1231231", zoneID)

zoneID, zoneName = z.FindZone("*.example.com")
assert.Equal(t, "*.example.com", zoneName)
assert.Equal(t, "123412", zoneID)

hook := testutils.LogsUnderTestWithLogLevel(log.WarnLevel, t)
_, _ = z.FindZone("???")
_, _ = z.FindZone("xn--not-a-valid-punycode")

testutils.TestHelperLogContains("Failed to convert label \"???\" of hostname \"???\" to its Unicode form: idna: disallowed rune U+003F", hook, t)
testutils.TestHelperLogContains("Failed to convert label \"xn--not-a-valid-punycode\" of hostname \"xn--not-a-valid-punycode\" to its Unicode form: idna: invalid label", hook, t)
}
Loading