Merge pull request #757 from enj/enj/t/dns_hacks

concierge_impersonation_proxy_test: check all forms of DNS
This commit is contained in:
Mo Khan 2021-07-29 15:51:22 -04:00 committed by GitHub
commit f1109afa79
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1733,14 +1733,54 @@ func TestImpersonationProxy(t *testing.T) { //nolint:gocyclo // yeah, it's compl
func ensureDNSResolves(t *testing.T, urlString string) { func ensureDNSResolves(t *testing.T, urlString string) {
t.Helper() t.Helper()
parsedURL, err := url.Parse(urlString) parsedURL, err := url.Parse(urlString)
require.NoError(t, err) require.NoError(t, err)
if net.ParseIP(parsedURL.Host) == nil {
testlib.RequireEventually(t, func(requireEventually *require.Assertions) { host := parsedURL.Hostname()
_, err = net.LookupIP(parsedURL.Host)
requireEventually.NoError(err) if net.ParseIP(host) != nil {
}, 5*time.Minute, 1*time.Second) return // ignore IPs
} }
var d net.Dialer
loggingDialer := func(ctx context.Context, network, address string) (net.Conn, error) {
t.Logf("dns lookup, network=%s address=%s", network, address)
conn, connErr := d.DialContext(ctx, network, address)
if connErr != nil {
t.Logf("dns lookup, err=%v", connErr)
} else {
local := conn.LocalAddr()
remote := conn.RemoteAddr()
t.Logf("dns lookup, local conn network=%s addr=%s", local.Network(), local.String())
t.Logf("dns lookup, remote conn network=%s addr=%s", remote.Network(), remote.String())
}
return conn, connErr
}
goResolver := &net.Resolver{
PreferGo: true,
StrictErrors: true,
Dial: loggingDialer,
}
notGoResolver := &net.Resolver{
PreferGo: false,
StrictErrors: true,
Dial: loggingDialer,
}
testlib.RequireEventually(t, func(requireEventually *require.Assertions) {
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
for _, resolver := range []*net.Resolver{goResolver, notGoResolver} {
resolver := resolver
ips, ipErr := resolver.LookupIPAddr(ctx, host)
requireEventually.NoError(ipErr)
requireEventually.NotEmpty(ips)
}
}, 5*time.Minute, 1*time.Second)
} }
func createTestNamespace(t *testing.T, adminClient kubernetes.Interface) string { func createTestNamespace(t *testing.T, adminClient kubernetes.Interface) string {