]> Cypherpunks repositories - gostls13.git/commitdiff
net/http: detect Comcast et al DNS and auto-skip DNS tests
authorKale Blankenship <kale@lemnisys.com>
Sun, 18 Dec 2016 04:40:29 +0000 (20:40 -0800)
committerBrad Fitzpatrick <bradfitz@golang.org>
Wed, 1 Feb 2017 23:54:44 +0000 (23:54 +0000)
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/34516
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>

src/net/http/transport_test.go

index a58b1839cc6e09e30d5f1a975a6f8394008dae98..e3de3eb91b40ab5423dafb1379c1fcb60ab1e5c4 100644 (file)
@@ -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
-               // 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")
+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.
+       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()