diff --git a/vault/testing.go b/vault/testing.go index e5c09b253..17d25ef8f 100644 --- a/vault/testing.go +++ b/vault/testing.go @@ -793,9 +793,11 @@ type TestCluster struct { CleanupFunc func() SetupFunc func() - cleanupFuncs []func() - base *CoreConfig - opts *TestClusterOptions + cleanupFuncs []func() + base *CoreConfig + LicensePublicKey ed25519.PublicKey + LicensePrivateKey ed25519.PrivateKey + opts *TestClusterOptions } func (c *TestCluster) Start() { @@ -1620,6 +1622,15 @@ func NewTestCluster(t testing.T, base *CoreConfig, opts *TestClusterOptions) *Te coreConfig.HAPhysical = haPhys.(physical.HABackend) } + if testCluster.LicensePublicKey == nil { + pubKey, priKey, err := GenerateTestLicenseKeys() + if err != nil { + t.Fatalf("err: %v", err) + } + testCluster.LicensePublicKey = pubKey + testCluster.LicensePrivateKey = priKey + } + if opts != nil && opts.InmemClusterLayers { if opts.ClusterLayers != nil { t.Fatalf("cannot specify ClusterLayers when InmemClusterLayers is true") @@ -1654,7 +1665,7 @@ func NewTestCluster(t testing.T, base *CoreConfig, opts *TestClusterOptions) *Te coreConfigs := []*CoreConfig{} for i := 0; i < numCores; i++ { - cleanup, c, localConfig, handler := testCluster.newCore(t, i, coreConfig, opts, listeners[i]) + cleanup, c, localConfig, handler := testCluster.newCore(t, i, coreConfig, opts, listeners[i], testCluster.LicensePublicKey) testCluster.cleanupFuncs = append(testCluster.cleanupFuncs, cleanup) cores = append(cores, c) @@ -1714,6 +1725,11 @@ func NewTestCluster(t testing.T, base *CoreConfig, opts *TestClusterOptions) *Te testCluster.Cores[i].Client = testCluster.getAPIClient(t, opts, listeners[i][0].Address.Port, tlsConfigs[i]) } + // Extra Setup + for _, tcc := range testCluster.Cores { + testExtraTestCoreSetup(t, testCluster.LicensePrivateKey, tcc) + } + // Cleanup testCluster.CleanupFunc = func() { for _, c := range testCluster.cleanupFuncs { @@ -1791,7 +1807,7 @@ func (cluster *TestCluster) StartCore(t testing.T, idx int, opts *TestClusterOpt } // Create a new Core - cleanup, newCore, localConfig, coreHandler := cluster.newCore(t, idx, tcc.CoreConfig, opts, tcc.Listeners) + cleanup, newCore, localConfig, coreHandler := cluster.newCore(t, idx, tcc.CoreConfig, opts, tcc.Listeners, cluster.LicensePublicKey) if coreHandler != nil { tcc.Handler = coreHandler tcc.Server.Handler = coreHandler @@ -1809,6 +1825,7 @@ func (cluster *TestCluster) StartCore(t testing.T, idx int, opts *TestClusterOpt tcc.Client = cluster.getAPIClient(t, opts, tcc.Listeners[0].Address.Port, tcc.tlsConfig) testAdjustUnderlyingStorage(tcc) + testExtraTestCoreSetup(t, cluster.LicensePrivateKey, tcc) // Start listeners for _, ln := range tcc.Listeners { @@ -1819,7 +1836,7 @@ func (cluster *TestCluster) StartCore(t testing.T, idx int, opts *TestClusterOpt tcc.Logger().Info("restarted test core", "core", idx) } -func (testCluster *TestCluster) newCore(t testing.T, idx int, coreConfig *CoreConfig, opts *TestClusterOptions, listeners []*TestListener) (func(), *Core, CoreConfig, http.Handler) { +func (testCluster *TestCluster) newCore(t testing.T, idx int, coreConfig *CoreConfig, opts *TestClusterOptions, listeners []*TestListener, pubKey ed25519.PublicKey) (func(), *Core, CoreConfig, http.Handler) { localConfig := *coreConfig cleanupFunc := func() {} var handler http.Handler @@ -1898,7 +1915,14 @@ func (testCluster *TestCluster) newCore(t testing.T, idx int, coreConfig *CoreCo localConfig.ClusterAddr = "https://" + localConfig.ClusterNetworkLayer.Listeners()[0].Addr().String() } - localConfig.LicensingConfig = testGetLicensingConfig(nil) + switch { + case localConfig.LicensingConfig != nil: + if pubKey != nil { + localConfig.LicensingConfig.AdditionalPublicKeys = append(localConfig.LicensingConfig.AdditionalPublicKeys, pubKey) + } + default: + localConfig.LicensingConfig = testGetLicensingConfig(pubKey) + } if localConfig.MetricsHelper == nil { inm := metrics.NewInmemSink(10*time.Second, time.Minute) diff --git a/vault/testing_util.go b/vault/testing_util.go index 44cbbccfa..8987325e8 100644 --- a/vault/testing_util.go +++ b/vault/testing_util.go @@ -7,10 +7,13 @@ package vault import ( "crypto/ed25519" + + testing "github.com/mitchellh/go-testing-interface" ) func GenerateTestLicenseKeys() (ed25519.PublicKey, ed25519.PrivateKey, error) { return nil, nil, nil } func testGetLicensingConfig(key ed25519.PublicKey) *LicensingConfig { return &LicensingConfig{} } +func testExtraTestCoreSetup(testing.T, ed25519.PrivateKey, *TestClusterCore) {} func testAdjustUnderlyingStorage(tcc *TestClusterCore) { tcc.UnderlyingStorage = tcc.physical }