2020-06-11 19:07:59 +00:00
|
|
|
package sealmigration
|
|
|
|
|
|
|
|
import (
|
2021-03-03 18:59:50 +00:00
|
|
|
"sync/atomic"
|
|
|
|
"testing"
|
|
|
|
|
2020-06-11 19:07:59 +00:00
|
|
|
"github.com/hashicorp/go-hclog"
|
|
|
|
"github.com/hashicorp/vault/helper/testhelpers"
|
|
|
|
"github.com/hashicorp/vault/helper/testhelpers/teststorage"
|
2020-09-17 19:44:29 +00:00
|
|
|
"github.com/hashicorp/vault/sdk/helper/logging"
|
2020-06-11 19:07:59 +00:00
|
|
|
"github.com/hashicorp/vault/vault"
|
|
|
|
)
|
|
|
|
|
|
|
|
type testFunc func(t *testing.T, logger hclog.Logger, storage teststorage.ReusableStorage, basePort int)
|
|
|
|
|
2020-06-16 18:12:22 +00:00
|
|
|
func testVariousBackends(t *testing.T, tf testFunc, basePort int, includeRaft bool) {
|
2020-06-11 19:07:59 +00:00
|
|
|
|
|
|
|
logger := logging.NewVaultLogger(hclog.Debug).Named(t.Name())
|
|
|
|
|
|
|
|
t.Run("inmem", func(t *testing.T) {
|
|
|
|
t.Parallel()
|
|
|
|
|
|
|
|
logger := logger.Named("inmem")
|
|
|
|
storage, cleanup := teststorage.MakeReusableStorage(
|
|
|
|
t, logger, teststorage.MakeInmemBackend(t, logger))
|
|
|
|
defer cleanup()
|
2020-06-16 18:12:22 +00:00
|
|
|
tf(t, logger, storage, basePort+100)
|
2020-06-11 19:07:59 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
if includeRaft {
|
|
|
|
t.Run("raft", func(t *testing.T) {
|
|
|
|
t.Parallel()
|
|
|
|
|
|
|
|
logger := logger.Named("raft")
|
2020-06-16 18:12:22 +00:00
|
|
|
raftBasePort := basePort + 400
|
|
|
|
|
2020-06-23 19:04:13 +00:00
|
|
|
atomic.StoreUint32(&vault.TestingUpdateClusterAddr, 1)
|
2020-06-16 18:12:22 +00:00
|
|
|
addressProvider := testhelpers.NewHardcodedServerAddressProvider(numTestCores, raftBasePort+10)
|
|
|
|
|
|
|
|
storage, cleanup := teststorage.MakeReusableRaftStorage(t, logger, numTestCores, addressProvider)
|
2020-06-11 19:07:59 +00:00
|
|
|
defer cleanup()
|
2020-06-16 18:12:22 +00:00
|
|
|
tf(t, logger, storage, raftBasePort)
|
2020-06-11 19:07:59 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-16 18:12:22 +00:00
|
|
|
// TestSealMigration_ShamirToTransit_Post14 tests shamir-to-transit seal
|
|
|
|
// migration, using the post-1.4 method of bring individual nodes in the cluster
|
|
|
|
// to do the migration.
|
|
|
|
func TestSealMigration_ShamirToTransit_Post14(t *testing.T) {
|
2020-09-15 14:01:26 +00:00
|
|
|
t.Parallel()
|
2020-11-20 12:53:31 +00:00
|
|
|
testVariousBackends(t, ParamTestSealMigrationShamirToTransit_Post14, BasePort_ShamirToTransit_Post14, true)
|
2020-06-16 18:12:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// TestSealMigration_TransitToShamir_Post14 tests transit-to-shamir seal
|
|
|
|
// migration, using the post-1.4 method of bring individual nodes in the
|
|
|
|
// cluster to do the migration.
|
|
|
|
func TestSealMigration_TransitToShamir_Post14(t *testing.T) {
|
2020-09-15 14:01:26 +00:00
|
|
|
t.Parallel()
|
2020-11-20 12:53:31 +00:00
|
|
|
testVariousBackends(t, ParamTestSealMigrationTransitToShamir_Post14, BasePort_TransitToShamir_Post14, true)
|
2020-10-23 18:16:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// TestSealMigration_TransitToTransit tests transit-to-shamir seal
|
|
|
|
// migration, using the post-1.4 method of bring individual nodes in the
|
|
|
|
// cluster to do the migration.
|
|
|
|
func TestSealMigration_TransitToTransit(t *testing.T) {
|
2020-11-20 12:53:31 +00:00
|
|
|
testVariousBackends(t, ParamTestSealMigration_TransitToTransit, BasePort_TransitToTransit, true)
|
2020-06-11 19:07:59 +00:00
|
|
|
}
|