mirror of
https://github.com/optim-enterprises-bv/vault.git
synced 2025-11-02 19:47:54 +00:00
db plugin multiplexing: add test coverage (#14330)
* db plugin multiplexing: add test coverage * refactor: pass factory func directly
This commit is contained in:
committed by
GitHub
parent
ddebe109dd
commit
3a65a50c62
@@ -47,8 +47,11 @@ func getCluster(t *testing.T) (*vault.TestCluster, logical.SystemView) {
|
|||||||
|
|
||||||
sys := vault.TestDynamicSystemView(cores[0].Core, nil)
|
sys := vault.TestDynamicSystemView(cores[0].Core, nil)
|
||||||
vault.TestAddTestPlugin(t, cores[0].Core, "postgresql-database-plugin", consts.PluginTypeDatabase, "TestBackend_PluginMain_Postgres", []string{}, "")
|
vault.TestAddTestPlugin(t, cores[0].Core, "postgresql-database-plugin", consts.PluginTypeDatabase, "TestBackend_PluginMain_Postgres", []string{}, "")
|
||||||
|
vault.TestAddTestPlugin(t, cores[0].Core, "postgresql-database-plugin-muxed", consts.PluginTypeDatabase, "TestBackend_PluginMain_PostgresMultiplexed", []string{}, "")
|
||||||
vault.TestAddTestPlugin(t, cores[0].Core, "mongodb-database-plugin", consts.PluginTypeDatabase, "TestBackend_PluginMain_Mongo", []string{}, "")
|
vault.TestAddTestPlugin(t, cores[0].Core, "mongodb-database-plugin", consts.PluginTypeDatabase, "TestBackend_PluginMain_Mongo", []string{}, "")
|
||||||
|
vault.TestAddTestPlugin(t, cores[0].Core, "mongodb-database-plugin-muxed", consts.PluginTypeDatabase, "TestBackend_PluginMain_MongoMultiplexed", []string{}, "")
|
||||||
vault.TestAddTestPlugin(t, cores[0].Core, "mongodbatlas-database-plugin", consts.PluginTypeDatabase, "TestBackend_PluginMain_MongoAtlas", []string{}, "")
|
vault.TestAddTestPlugin(t, cores[0].Core, "mongodbatlas-database-plugin", consts.PluginTypeDatabase, "TestBackend_PluginMain_MongoAtlas", []string{}, "")
|
||||||
|
vault.TestAddTestPlugin(t, cores[0].Core, "mongodbatlas-database-plugin-muxed", consts.PluginTypeDatabase, "TestBackend_PluginMain_MongoAtlasMultiplexed", []string{}, "")
|
||||||
|
|
||||||
return cluster, sys
|
return cluster, sys
|
||||||
}
|
}
|
||||||
@@ -66,6 +69,14 @@ func TestBackend_PluginMain_Postgres(t *testing.T) {
|
|||||||
v5.Serve(dbType.(v5.Database))
|
v5.Serve(dbType.(v5.Database))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestBackend_PluginMain_PostgresMultiplexed(t *testing.T) {
|
||||||
|
if os.Getenv(pluginutil.PluginVaultVersionEnv) == "" {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
v5.ServeMultiplex(postgresql.New)
|
||||||
|
}
|
||||||
|
|
||||||
func TestBackend_PluginMain_Mongo(t *testing.T) {
|
func TestBackend_PluginMain_Mongo(t *testing.T) {
|
||||||
if os.Getenv(pluginutil.PluginVaultVersionEnv) == "" {
|
if os.Getenv(pluginutil.PluginVaultVersionEnv) == "" {
|
||||||
return
|
return
|
||||||
@@ -79,6 +90,14 @@ func TestBackend_PluginMain_Mongo(t *testing.T) {
|
|||||||
v5.Serve(dbType.(v5.Database))
|
v5.Serve(dbType.(v5.Database))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestBackend_PluginMain_MongoMultiplexed(t *testing.T) {
|
||||||
|
if os.Getenv(pluginutil.PluginVaultVersionEnv) == "" {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
v5.ServeMultiplex(mongodb.New)
|
||||||
|
}
|
||||||
|
|
||||||
func TestBackend_PluginMain_MongoAtlas(t *testing.T) {
|
func TestBackend_PluginMain_MongoAtlas(t *testing.T) {
|
||||||
if os.Getenv(pluginutil.PluginUnwrapTokenEnv) == "" {
|
if os.Getenv(pluginutil.PluginUnwrapTokenEnv) == "" {
|
||||||
return
|
return
|
||||||
@@ -92,6 +111,14 @@ func TestBackend_PluginMain_MongoAtlas(t *testing.T) {
|
|||||||
v5.Serve(dbType.(v5.Database))
|
v5.Serve(dbType.(v5.Database))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestBackend_PluginMain_MongoAtlasMultiplexed(t *testing.T) {
|
||||||
|
if os.Getenv(pluginutil.PluginUnwrapTokenEnv) == "" {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
v5.ServeMultiplex(mongodbatlas.New)
|
||||||
|
}
|
||||||
|
|
||||||
func TestBackend_RoleUpgrade(t *testing.T) {
|
func TestBackend_RoleUpgrade(t *testing.T) {
|
||||||
storage := &logical.InmemStorage{}
|
storage := &logical.InmemStorage{}
|
||||||
backend := &databaseBackend{}
|
backend := &databaseBackend{}
|
||||||
|
|||||||
@@ -36,6 +36,13 @@ func RunV5() error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Run instantiates a MongoDB object, and runs the RPC server for the plugin
|
||||||
|
func RunV6Multiplexed() error {
|
||||||
|
v5.ServeMultiplex(New)
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
func (m MockDatabaseV5) Initialize(ctx context.Context, req v5.InitializeRequest) (v5.InitializeResponse, error) {
|
func (m MockDatabaseV5) Initialize(ctx context.Context, req v5.InitializeRequest) (v5.InitializeResponse, error) {
|
||||||
log.Default().Info("Initialize called",
|
log.Default().Info("Initialize called",
|
||||||
"req", req)
|
"req", req)
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ func TestPlugin_lifecycle(t *testing.T) {
|
|||||||
|
|
||||||
vault.TestAddTestPlugin(t, cluster.Cores[0].Core, "mock-v4-database-plugin", consts.PluginTypeDatabase, "TestBackend_PluginMain_MockV4", []string{}, "")
|
vault.TestAddTestPlugin(t, cluster.Cores[0].Core, "mock-v4-database-plugin", consts.PluginTypeDatabase, "TestBackend_PluginMain_MockV4", []string{}, "")
|
||||||
vault.TestAddTestPlugin(t, cluster.Cores[0].Core, "mock-v5-database-plugin", consts.PluginTypeDatabase, "TestBackend_PluginMain_MockV5", []string{}, "")
|
vault.TestAddTestPlugin(t, cluster.Cores[0].Core, "mock-v5-database-plugin", consts.PluginTypeDatabase, "TestBackend_PluginMain_MockV5", []string{}, "")
|
||||||
|
vault.TestAddTestPlugin(t, cluster.Cores[0].Core, "mock-v6-database-plugin-muxed", consts.PluginTypeDatabase, "TestBackend_PluginMain_MockV6Multiplexed", []string{}, "")
|
||||||
|
|
||||||
config := logical.TestBackendConfig()
|
config := logical.TestBackendConfig()
|
||||||
config.StorageView = &logical.InmemStorage{}
|
config.StorageView = &logical.InmemStorage{}
|
||||||
@@ -261,6 +262,14 @@ func TestBackend_PluginMain_MockV5(t *testing.T) {
|
|||||||
RunV5()
|
RunV5()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestBackend_PluginMain_MockV6Multiplexed(t *testing.T) {
|
||||||
|
if os.Getenv(pluginutil.PluginVaultVersionEnv) == "" {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
RunV6Multiplexed()
|
||||||
|
}
|
||||||
|
|
||||||
func assertNoRespData(t *testing.T, resp *logical.Response) {
|
func assertNoRespData(t *testing.T, resp *logical.Response) {
|
||||||
t.Helper()
|
t.Helper()
|
||||||
if resp != nil && len(resp.Data) > 0 {
|
if resp != nil && len(resp.Data) > 0 {
|
||||||
|
|||||||
Reference in New Issue
Block a user