From b57c2b78fd78db29885fa9b3fac517f934acb478 Mon Sep 17 00:00:00 2001 From: Matt Keeler Date: Mon, 27 Jan 2020 14:34:04 -0500 Subject: [PATCH] Unflake the TestAPI_AgentConnectCALeaf test (#7142) * Unflake the TestAPI_AgentConnectCALeaf test * Modify the WaitForActiveCARoot to actually verify that at least one root exists Also verify that the active root id field is set --- api/agent_test.go | 3 +++ sdk/testutil/server.go | 18 ++++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/api/agent_test.go b/api/agent_test.go index d78187906a..5ddcc34235 100644 --- a/api/agent_test.go +++ b/api/agent_test.go @@ -1389,6 +1389,9 @@ func TestAPI_AgentConnectCALeaf(t *testing.T) { c, s := makeClient(t) defer s.Stop() + // ensure we don't try to sign a leaf cert before connect has been initialized + s.WaitForActiveCARoot(t) + agent := c.Agent() // Setup service reg := &AgentServiceRegistration{ diff --git a/sdk/testutil/server.go b/sdk/testutil/server.go index f6f0cbdc18..66c7f43f94 100644 --- a/sdk/testutil/server.go +++ b/sdk/testutil/server.go @@ -433,6 +433,13 @@ func (s *TestServer) WaitForLeader(t *testing.T) { // WaitForActiveCARoot waits until the server can return a Connect CA meaning // connect has completed bootstrapping and is ready to use. func (s *TestServer) WaitForActiveCARoot(t *testing.T) { + // don't need to fully decode the response + type rootsResponse struct { + ActiveRootID string + TrustDomain string + Roots []interface{} + } + retry.Run(t, func(r *retry.R) { // Query the API and check the status code. url := s.url("/v1/agent/connect/ca/roots") @@ -448,6 +455,17 @@ func (s *TestServer) WaitForActiveCARoot(t *testing.T) { if err := s.requireOK(resp); err != nil { r.Fatal("failed OK response", err) } + + var roots rootsResponse + + dec := json.NewDecoder(resp.Body) + if err := dec.Decode(&roots); err != nil { + r.Fatal(err) + } + + if roots.ActiveRootID == "" || len(roots.Roots) < 1 { + r.Fatalf("/v1/agent/connect/ca/roots returned 200 but without roots: %+v", roots) + } }) }