TestPkiWorker always tries to create valid globally scoped root certificates (#2201)
This commit is contained in:
2 files changed
+10
-13
No files matched your search
@@ -2,7 +2,6 @@ package servers_test
|
||||
|
||||
import (
|
||||
"context"
|
||||
"crypto/rand"
|
||||
"fmt"
|
||||
"strings"
|
||||
"testing"
|
||||
@@ -147,10 +146,6 @@ func TestLookupWorkerIdByKeyId(t *testing.T) {
|
||||
repo, err := servers.NewRepository(rw, rw, kmsCache)
|
||||
require.NoError(t, err)
|
||||
ctx := context.Background()
|
||||
// Ensures the global scope contains a valid root key
|
||||
err = kmsCache.CreateKeys(context.Background(), scope.Global.String(), kms.WithRandomReader(rand.Reader))
|
||||
require.NoError(t, err)
|
||||
|
||||
var workerKeyId string
|
||||
w := servers.TestPkiWorker(t, conn, wrapper, servers.WithTestPkiWorkerAuthorizedKeyId(&workerKeyId))
|
||||
t.Run("success", func(t *testing.T) {
|
||||
@@ -260,9 +255,6 @@ func TestUpsertWorkerStatus(t *testing.T) {
|
||||
repo, err := servers.NewRepository(rw, rw, kmsCache)
|
||||
require.NoError(t, err)
|
||||
|
||||
err = kmsCache.CreateKeys(context.Background(), scope.Global.String(), kms.WithRandomReader(rand.Reader))
|
||||
require.NoError(t, err)
|
||||
|
||||
ctx := context.Background()
|
||||
|
||||
t.Run("create an initial kms worker and update status", func(t *testing.T) {
|
||||
|
||||
@@ -2,13 +2,15 @@ package servers
|
||||
|
||||
import (
|
||||
"context"
|
||||
"math/rand"
|
||||
"crypto/rand"
|
||||
mathRand "math/rand"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/hashicorp/boundary/internal/db"
|
||||
"github.com/hashicorp/boundary/internal/db/timestamp"
|
||||
"github.com/hashicorp/boundary/internal/errors"
|
||||
"github.com/hashicorp/boundary/internal/iam"
|
||||
"github.com/hashicorp/boundary/internal/kms"
|
||||
"github.com/hashicorp/boundary/internal/servers/store"
|
||||
@@ -56,7 +58,7 @@ func TestRootCertificate(ctx context.Context, t *testing.T, conn *db.DB, kmsKey
|
||||
privateKey: populateBytes(defaultLength),
|
||||
}
|
||||
|
||||
cert, err := newRootCertificate(ctx, rand.Uint64(), populateBytes(defaultLength), beforeTimestamp, afterTimestamp,
|
||||
cert, err := newRootCertificate(ctx, mathRand.Uint64(), populateBytes(defaultLength), beforeTimestamp, afterTimestamp,
|
||||
rootCertKeys, kmsKey, CurrentState)
|
||||
err = rw.Create(ctx, cert)
|
||||
require.NoError(t, err)
|
||||
@@ -153,8 +155,8 @@ func TestKmsWorker(t *testing.T, conn *db.DB, wrapper wrapping.Wrapper, opt ...O
|
||||
func TestPkiWorker(t *testing.T, conn *db.DB, wrapper wrapping.Wrapper, opt ...Option) *Worker {
|
||||
t.Helper()
|
||||
rw := db.New(conn)
|
||||
kms := kms.TestKms(t, conn, wrapper)
|
||||
serversRepo, err := NewRepository(rw, rw, kms)
|
||||
kmsCache := kms.TestKms(t, conn, wrapper)
|
||||
serversRepo, err := NewRepository(rw, rw, kmsCache)
|
||||
require.NoError(t, err)
|
||||
ctx := context.Background()
|
||||
opts := getOpts(opt...)
|
||||
@@ -179,7 +181,10 @@ func TestPkiWorker(t *testing.T, conn *db.DB, wrapper wrapping.Wrapper, opt ...O
|
||||
require.NoError(t, rw.CreateItems(ctx, tags))
|
||||
}
|
||||
if opts.withTestPkiWorkerAuthorized {
|
||||
rootStorage, err := NewRepositoryStorage(ctx, rw, rw, kms)
|
||||
err = kmsCache.CreateKeys(context.Background(), scope.Global.String(), kms.WithRandomReader(rand.Reader))
|
||||
// We always try to create root global scope keys, but if it already exists, just continue...
|
||||
require.True(t, err == nil || errors.IsUniqueError(err), err)
|
||||
rootStorage, err := NewRepositoryStorage(ctx, rw, rw, kmsCache)
|
||||
require.NoError(t, err)
|
||||
_, err = rotation.RotateRootCertificates(ctx, rootStorage)
|
||||
require.NoError(t, err)
|
||||
|
||||
Reference in new issue
Block a user