Fix a test issue with IPv6 localhost interfaces.
This fixes a regression introduced by 24c4bc0dd4
. It could occasionally cause the tests to fail when run on a machine with an IPv6 localhost interface. As a fix I added a wrapper for the new Go 1.15 `LookupIP()` method, and created a partially-functional backport for Go 1.14. This should be easy to delete in the future.
Signed-off-by: Matt Moyer <moyerm@vmware.com>
This commit is contained in:
parent
be8f11fe5a
commit
37c5e121c4
@ -232,11 +232,10 @@ func TestSupervisorTLSTerminationWithDefaultCerts(t *testing.T) {
|
||||
port = hostAndPortSegments[1]
|
||||
}
|
||||
|
||||
ips, err := net.DefaultResolver.LookupIPAddr(ctx, hostname)
|
||||
ips, err := library.LookupIP(ctx, hostname)
|
||||
require.NoError(t, err)
|
||||
ip := ips[0]
|
||||
ipAsString := ip.String()
|
||||
ipWithPort := ipAsString + ":" + port
|
||||
require.NotEmpty(t, ips)
|
||||
ipWithPort := ips[0].String() + ":" + port
|
||||
|
||||
issuerUsingIPAddress := fmt.Sprintf("%s://%s/issuer1", scheme, ipWithPort)
|
||||
issuerUsingHostname := fmt.Sprintf("%s://%s/issuer1", scheme, address)
|
||||
@ -249,7 +248,7 @@ func TestSupervisorTLSTerminationWithDefaultCerts(t *testing.T) {
|
||||
requireEndpointHasTLSErrorBecauseCertificatesAreNotReady(t, issuerUsingIPAddress)
|
||||
|
||||
// Create a Secret at the special name which represents the default TLS cert.
|
||||
defaultCA := createTLSCertificateSecret(ctx, t, ns, "cert-hostname-doesnt-matter", []net.IP{ip.IP}, defaultTLSCertSecretName(env), kubeClient)
|
||||
defaultCA := createTLSCertificateSecret(ctx, t, ns, "cert-hostname-doesnt-matter", []net.IP{ips[0]}, defaultTLSCertSecretName(env), kubeClient)
|
||||
|
||||
// Now that the Secret exists, we should be able to access the endpoints by IP address using the CA.
|
||||
_ = requireDiscoveryEndpointsAreWorking(t, scheme, ipWithPort, string(defaultCA.Bundle()), issuerUsingIPAddress, nil)
|
||||
|
16
test/library/iplookup.go
Normal file
16
test/library/iplookup.go
Normal file
@ -0,0 +1,16 @@
|
||||
// Copyright 2020 the Pinniped contributors. All Rights Reserved.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
// +build !go1.14
|
||||
|
||||
package library
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net"
|
||||
)
|
||||
|
||||
// LookupIP looks up the IP address of the provided hostname, preferring IPv4.
|
||||
func LookupIP(ctx context.Context, hostname string) ([]net.IP, error) {
|
||||
return net.DefaultResolver.LookupIP(ctx, "ip4", hostname)
|
||||
}
|
28
test/library/iplookup_go1.14.go
Normal file
28
test/library/iplookup_go1.14.go
Normal file
@ -0,0 +1,28 @@
|
||||
// Copyright 2020 the Pinniped contributors. All Rights Reserved.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
// +build go1.14
|
||||
|
||||
package library
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net"
|
||||
)
|
||||
|
||||
// LookupIP looks up the IP address of the provided hostname, preferring IPv4.
|
||||
func LookupIP(ctx context.Context, hostname string) ([]net.IP, error) {
|
||||
ips, err := net.DefaultResolver.LookupIPAddr(ctx, hostname)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// Filter out to only IPv4 addresses
|
||||
var results []net.IP
|
||||
for _, ip := range ips {
|
||||
if ip.IP.To4() != nil {
|
||||
results = append(results, ip.IP)
|
||||
}
|
||||
}
|
||||
return results, nil
|
||||
}
|
Loading…
Reference in New Issue
Block a user