bug(plugin): Fix incorrect use of WithIpAddrs in Repository.Endpoints (#1849)

When creating the options for the preferencer, this used WithIpAddrs for both the host addresses and also DNS names. This causes errors when a host contains DNS names that are not IP addresses (ie: whenever dns names are present).

This change will:
- Replace WithIpAddrs with WithDNSNames option for DNS Names when constructing options for the preferencer.
- Add a test which includes a DNS name to prevent regressions

Fixes #1848
This commit is contained in:
Justen Walker authored and GitHub committed 2022-02-10 13:59:35 -07:00
1 parent befdc7612c
commit 6166d2240f
2 files changed
+19 -2

No files matched your search

@@ -1314,12 +1314,14 @@ func TestRepository_Endpoints(t *testing.T) {
hostSet10 := TestSet(t, conn, kms, sched, catalog, plgm, WithName("hostSet10"), WithPreferredEndpoints([]string{"cidr:10.0.0.1/24"}))
hostSet192 := TestSet(t, conn, kms, sched, catalog, plgm, WithName("hostSet192"), WithPreferredEndpoints([]string{"cidr:192.168.0.1/24"}))
hostSet100 := TestSet(t, conn, kms, sched, catalog, plgm, WithName("hostSet100"), WithPreferredEndpoints([]string{"cidr:100.100.100.100/24"}))
hostSetDNS := TestSet(t, conn, kms, sched, catalog, plgm, WithName("hostSetDNS"), WithPreferredEndpoints([]string{"dns:*"}))
hostlessSet := TestSet(t, conn, kms, sched, hostlessCatalog, plgm)
h1 := TestHost(t, conn, catalog.GetPublicId(), "test", withIpAddresses([]string{"10.0.0.5", "192.168.0.5"}))
h1 := TestHost(t, conn, catalog.GetPublicId(), "test", withIpAddresses([]string{"10.0.0.5", "192.168.0.5"}), withDnsNames([]string{"example.com"}))
TestSetMembers(t, conn, hostSet10.GetPublicId(), []*Host{h1})
TestSetMembers(t, conn, hostSet192.GetPublicId(), []*Host{h1})
TestSetMembers(t, conn, hostSet100.GetPublicId(), []*Host{h1})
TestSetMembers(t, conn, hostSetDNS.GetPublicId(), []*Host{h1})
tests := []struct {
name string
@@ -1371,6 +1373,21 @@ func TestRepository_Endpoints(t *testing.T) {
setIds: []string{hostlessSet.GetPublicId()},
want: nil,
},
{
name: "with-dns-names",
setIds: []string{hostSetDNS.GetPublicId()},
want: []*host.Endpoint{
{
HostId: func() string {
s, err := newHostId(ctx, catalog.GetPublicId(), "test")
require.NoError(t, err)
return s
}(),
SetId: hostSetDNS.GetPublicId(),
Address: "example.com",
},
},
},
}
for _, tt := range tests {