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
pull/1854/head
Justen Walker 4 years ago committed by GitHub
parent befdc7612c
commit 6166d2240f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -816,7 +816,7 @@ func (r *Repository) Endpoints(ctx context.Context, setIds []string) ([]*host.En
opts = append(opts, endpoint.WithIpAddrs(h.GetIpAddresses()))
}
if len(h.GetDnsNames()) > 0 {
opts = append(opts, endpoint.WithIpAddrs(h.GetDnsNames()))
opts = append(opts, endpoint.WithDnsNames(h.GetDnsNames()))
}
addr, err := pref.Choose(ctx, opts...)
if err != nil {

@ -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 {

Loading…
Cancel
Save