Skip to content

Commit 267013e

Browse files
crypto/x509: attempt to prime windows root pool before hybrid test
In TestHybridPool attempt to prime to the windows root pool before the real test actually happens. This is a bit of a band-aid, with a better long term solution discussed in #52108. Updates #51599 Change-Id: I406add8d9cd9e3fae37bfc20b97f5479c10a52c2 Reviewed-on: https://go-review.googlesource.com/c/go/+/405914 Reviewed-by: Bryan Mills <[email protected]> TryBot-Result: Gopher Robot <[email protected]> Run-TryBot: Roland Shoemaker <[email protected]>
1 parent 27ace7a commit 267013e

File tree

1 file changed

+29
-1
lines changed

1 file changed

+29
-1
lines changed

src/crypto/x509/hybrid_pool_test.go

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,40 @@ import (
1919
)
2020

2121
func TestHybridPool(t *testing.T) {
22+
t.Parallel()
2223
if !(runtime.GOOS == "windows" || runtime.GOOS == "darwin" || runtime.GOOS == "ios") {
2324
t.Skipf("platform verifier not available on %s", runtime.GOOS)
2425
}
2526
if !testenv.HasExternalNetwork() {
2627
t.Skip()
2728
}
29+
if runtime.GOOS == "windows" {
30+
// NOTE(#51599): on the Windows builders we sometimes see that the state
31+
// of the root pool is not fully initialized, causing an expected
32+
// platform verification to fail. In part this is because Windows
33+
// dynamically populates roots into its local trust store at time of
34+
// use. We can attempt to prime the pool by attempting TLS connections
35+
// to google.com until it works, suggesting the pool has been properly
36+
// updated. If after we hit the dealine, the pool has _still_ not been
37+
// populated with the expected root, it's unlikely we are ever going to
38+
// get into a good state, and so we just fail the test. #52108 suggests
39+
// a better possible long term solution.
40+
41+
deadline := time.Now().Add(time.Second * 10)
42+
nextSleep := 10 * time.Millisecond
43+
for i := 0; ; i++ {
44+
c, err := tls.Dial("tcp", "google.com:443", nil)
45+
if err == nil {
46+
c.Close()
47+
break
48+
}
49+
nextSleep = nextSleep * time.Duration(i)
50+
if time.Until(deadline) < nextSleep {
51+
t.Fatal("windows root pool appears to be in an uninitialized state (missing root that chains to google.com)")
52+
}
53+
time.Sleep(nextSleep)
54+
}
55+
}
2856

2957
// Get the google.com chain, which should be valid on all platforms we
3058
// are testing
@@ -63,7 +91,7 @@ func TestHybridPool(t *testing.T) {
6391

6492
_, err = googChain[0].Verify(opts)
6593
if err != nil {
66-
t.Fatalf("verification failed for google.com chain (empty pool): %s", err)
94+
t.Fatalf("verification failed for google.com chain (system only pool): %s", err)
6795
}
6896

6997
pool.AddCert(root)

0 commit comments

Comments
 (0)