Commit 4aa7b142 authored by Kale Blankenship's avatar Kale Blankenship Committed by Brad Fitzpatrick

net/http: detect Comcast et al DNS and auto-skip DNS tests

Adds helper function to auto-skip tests when DNS returns
a successful response for a domain known not to exist.

The error from `net.LookupHost` is intentionally ignored
because the DNS tests will fail anyway if there are issues
unrelated to NXDOMAIN responses.

Fixes #17884

Change-Id: I729391bd702218507561818668f791331295299e
Reviewed-on: https://go-review.googlesource.com/34516Reviewed-by: default avatarBrad Fitzpatrick <bradfitz@golang.org>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
parent a27b7814
......@@ -3426,16 +3426,26 @@ func testTransportEventTrace(t *testing.T, h2 bool, noHooks bool) {
}
}
func TestTransportEventTraceRealDNS(t *testing.T) {
if testing.Short() && testenv.Builder() == "" {
// Skip this test in short mode (the default for
// all.bash), in case the user is using a shady/ISP
var (
isDNSHijackedOnce sync.Once
isDNSHijacked bool
)
func skipIfDNSHijacked(t *testing.T) {
// Skip this test if the user is using a shady/ISP
// DNS server hijacking queries.
// See issues 16732, 16716.
// Our builders use 8.8.8.8, though, which correctly
// returns NXDOMAIN, so still run this test there.
t.Skip("skipping in short mode")
isDNSHijackedOnce.Do(func() {
addrs, _ := net.LookupHost("dns-should-not-resolve.golang.")
isDNSHijacked = len(addrs) != 0
})
if isDNSHijacked {
t.Skip("skipping; test requires non-hijacking DNS server")
}
}
func TestTransportEventTraceRealDNS(t *testing.T) {
skipIfDNSHijacked(t)
defer afterTest(t)
tr := &Transport{}
defer tr.CloseIdleConnections()
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment