Skip to content

Commit

Permalink
fix: correctly detect zones if names overlap with subdomain (#478)
Browse files Browse the repository at this point in the history
  • Loading branch information
linki authored Mar 14, 2018
1 parent 0d6f3ce commit cdb9ae0
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
2 changes: 1 addition & 1 deletion provider/zonefinder.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func (z zoneIDName) Add(zoneID, zoneName string) {

func (z zoneIDName) FindZone(hostname string) (suitableZoneID, suitableZoneName string) {
for zoneID, zoneName := range z {
if strings.HasSuffix(hostname, zoneName) {
if hostname == zoneName || strings.HasSuffix(hostname, "."+zoneName) {
if suitableZoneName == "" || len(zoneName) > len(suitableZoneName) {
suitableZoneID = zoneID
suitableZoneName = zoneName
Expand Down
13 changes: 13 additions & 0 deletions provider/zonefinder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,28 @@ func TestZoneIDName(t *testing.T) {
"654321": "foo.qux.baz",
}, z)

// simple entry in a domain
zoneID, zoneName := z.FindZone("name.qux.baz")
assert.Equal(t, "qux.baz", zoneName)
assert.Equal(t, "123456", zoneID)

// simple entry in a domain's subdomain.
zoneID, zoneName = z.FindZone("name.foo.qux.baz")
assert.Equal(t, "foo.qux.baz", zoneName)
assert.Equal(t, "654321", zoneID)

// no possible zone for entry
zoneID, zoneName = z.FindZone("name.qux.foo")
assert.Equal(t, "", zoneName)
assert.Equal(t, "", zoneID)

// entry's suffix matches a subdomain but doesn't belong there
zoneID, zoneName = z.FindZone("name-foo.qux.baz")
assert.Equal(t, "qux.baz", zoneName)
assert.Equal(t, "123456", zoneID)

// entry is an exact match of the domain (e.g. azure provider)
zoneID, zoneName = z.FindZone("foo.qux.baz")
assert.Equal(t, "foo.qux.baz", zoneName)
assert.Equal(t, "654321", zoneID)
}

0 comments on commit cdb9ae0

Please sign in to comment.