Modify some tests to expose error cases that weren't being exposed (#3302)

This commit is contained in:
Jeff Mitchell authored and GitHub committed 2023-06-09 11:13:15 -04:00
1 parent e4f49e1bb0
commit 929ede1c18
3 files changed
+15 -31

No files matched your search

+7
View File
@@ -546,8 +546,15 @@ func NewTestMultihopWorkers(t testing.TB,
Config: childKmsWorkerConf,
WorkerAuthKms: childDownstreamWrapper2,
WorkerAuthDebuggingEnabled: enableAuthDebugging,
DisableAutoStart: true,
})
childKmsWorker.w.conf.WorkerAuthStorageKms = nil
err = childKmsWorker.w.Start()
t.Cleanup(childKmsWorker.Shutdown)
if err != nil {
t.Fatal(err)
}
// Sleep so that workers can startup and connect.
time.Sleep(12 * time.Second)
+5
View File
@@ -202,6 +202,11 @@ func TestNewTestMultihopWorkers(t *testing.T) {
assert.Equal(t, pkiTags, pkiW.GetConfigTags())
assert.Equal(t, childPkiTags, childPkiW.GetConfigTags())
assert.Equal(t, childKmsTags, childKmsW.GetConfigTags())
require.NoError(t, c.WaitForNextWorkerStatusUpdate(kmsWorker.Name()))
require.NoError(t, c.WaitForNextWorkerStatusUpdate(pkiWorker.Name()))
require.NoError(t, c.WaitForNextWorkerStatusUpdate(childPkiWorker.Name()))
require.NoError(t, c.WaitForNextWorkerStatusUpdate(childKmsWorker.Name()))
}
func createTestCert(t *testing.T) ([]byte, ed25519.PublicKey, ed25519.PrivateKey) {
@@ -4,9 +4,6 @@
package cluster
import (
"context"
"os"
"strings"
"sync"
"testing"
"time"
@@ -53,6 +50,8 @@ func TestWorkerUpgradeKmsAuthMethod(t *testing.T) {
// Give time for it to connect
time.Sleep(10 * time.Second)
require.NoError(t, c1.WaitForNextWorkerStatusUpdate(w1.Name()))
// Verify it's KMS type
workers, err := serversRepo.ListWorkers(c1.Context(), []string{scope.Global.String()})
require.NoError(t, err)
@@ -60,11 +59,6 @@ func TestWorkerUpgradeKmsAuthMethod(t *testing.T) {
assert.Equal(t, "kms", workers[0].Type)
oldId := workers[0].PublicId
// Assert that the worker has connected
logBuf, err := os.ReadFile(ec.AllEvents.Name())
require.NoError(t, err)
require.Equal(t, 1, strings.Count(string(logBuf), "worker successfully authed"))
require.NoError(t, w1.Worker().Shutdown())
// Now, start up again, using the new method
@@ -75,29 +69,7 @@ func TestWorkerUpgradeKmsAuthMethod(t *testing.T) {
})
defer w1.Shutdown()
timeout := time.Minute
ctx, cancel := context.WithTimeout(context.Background(), timeout)
defer cancel()
for {
logBuf, err = os.ReadFile(ec.AllEvents.Name())
require.NoError(t, err)
if strings.Count(string(logBuf), "worker has successfully authenticated") == 2 {
break
}
select {
case <-ctx.Done():
t.Fatal("worker had not successfully connected after ", timeout.String())
case <-time.After(time.Second):
// Try again
}
}
// We should find only one nonce, and one successful worker authentication,
// both in the output and in the database
ec.AllEvents.Close()
logBuf, err = os.ReadFile(ec.AllEvents.Name())
require.NoError(t, err)
require.Equal(t, 2, strings.Count(string(logBuf), "worker has successfully authenticated"))
require.NoError(t, c1.WaitForNextWorkerStatusUpdate(w1.Name()))
// Verify it's PKI type
workers, err = serversRepo.ListWorkers(c1.Context(), []string{scope.Global.String()})