(t *testing.T)
| 44 | } |
| 45 | |
| 46 | func TestLocalhostAuthIPv6(t *testing.T) { |
| 47 | l, err := net.Listen("tcp", "[::1]:0") |
| 48 | if err != nil { |
| 49 | t.Skip("skipping IPv6 test; can't listen on [::1]:0") |
| 50 | } |
| 51 | _, port, err := net.SplitHostPort(l.Addr().String()) |
| 52 | if err != nil { |
| 53 | t.Fatal(err) |
| 54 | } |
| 55 | |
| 56 | // See if IPv6 works on this machine first. It seems the above |
| 57 | // Listen can pass on Linux but fail here in the dial. |
| 58 | c, err := net.Dial("tcp6", l.Addr().String()) |
| 59 | if err != nil { |
| 60 | t.Skipf("skipping IPv6 test; dial back to %s failed with %v", l.Addr(), err) |
| 61 | } |
| 62 | c.Close() |
| 63 | |
| 64 | ts := testServer(t, l) |
| 65 | defer ts.Close() |
| 66 | |
| 67 | // Use an explicit transport to force IPv6 (http.Get resolves localhost in IPv4 otherwise) |
| 68 | trans := &http.Transport{ |
| 69 | Dial: func(network, addr string) (net.Conn, error) { |
| 70 | c, err := net.Dial("tcp6", addr) |
| 71 | return c, err |
| 72 | }, |
| 73 | } |
| 74 | |
| 75 | testLoginRequest(t, &http.Client{Transport: trans}, "http://[::1]:"+port) |
| 76 | |
| 77 | // See if we can get an IPv6 from resolving localhost |
| 78 | localips, err := net.LookupIP("localhost") |
| 79 | if err != nil { |
| 80 | t.Skipf("skipping IPv6 test; resolving localhost failed with %v", err) |
| 81 | } |
| 82 | if hasIPv6(localips) { |
| 83 | testLoginRequest(t, &http.Client{Transport: trans}, "http://localhost:"+port) |
| 84 | } else { |
| 85 | t.Logf("incomplete IPv6 test; resolving localhost didn't return any IPv6 addresses") |
| 86 | } |
| 87 | } |
| 88 | |
| 89 | func hasIPv6(ips []net.IP) bool { |
| 90 | for _, ip := range ips { |
nothing calls this directly
no test coverage detected