diff --git a/cmd/tenant-manager-cli/cli_test.go b/cmd/tenant-manager-cli/cli_test.go index 8d40fc78..7a91f087 100644 --- a/cmd/tenant-manager-cli/cli_test.go +++ b/cmd/tenant-manager-cli/cli_test.go @@ -23,10 +23,8 @@ import ( eventprocessor "github.com/openkcm/cmk/internal/event-processor" "github.com/openkcm/cmk/internal/manager" "github.com/openkcm/cmk/internal/model" - cmkpluginregistry "github.com/openkcm/cmk/internal/pluginregistry" "github.com/openkcm/cmk/internal/repo/sql" "github.com/openkcm/cmk/internal/testutils" - "github.com/openkcm/cmk/internal/testutils/testplugins" integrationutils "github.com/openkcm/cmk/test/integration/integration_utils" "github.com/openkcm/cmk/utils/base62" ) @@ -59,14 +57,11 @@ func (s *CLISuite) SetupSuite() { ctx := s.T().Context() - ps, psCfg := testutils.NewTestPlugins(testplugins.NewIdentityManagement()) cfg := &config.Config{ - Plugins: psCfg, Database: dbCfg, } r := sql.NewRepository(s.db) - svcRegistry, err := cmkpluginregistry.New(ctx, cfg, cmkpluginregistry.WithBuiltInPlugins(ps)) - s.NoError(err) + svcRegistry := testutils.NewTestPlugins() cmkAuditor := auditor.New(ctx, cfg) diff --git a/cmd/tenant-manager-cli/commands/commands.go b/cmd/tenant-manager-cli/commands/commands.go index 51e400c6..952f6bd1 100644 --- a/cmd/tenant-manager-cli/commands/commands.go +++ b/cmd/tenant-manager-cli/commands/commands.go @@ -11,7 +11,7 @@ import ( "github.com/openkcm/cmk/internal/db" eventprocessor "github.com/openkcm/cmk/internal/event-processor" "github.com/openkcm/cmk/internal/manager" - cmkpluginregistry "github.com/openkcm/cmk/internal/pluginregistry" + serviceapi "github.com/openkcm/cmk/internal/pluginregistry/service/api" "github.com/openkcm/cmk/internal/repo" "github.com/openkcm/cmk/internal/repo/sql" ) @@ -27,7 +27,7 @@ func NewCommandFactory( ctx context.Context, cfg *config.Config, dbCon *multitenancy.DB, - svcRegistry *cmkpluginregistry.Registry, + svcRegistry serviceapi.Registry, ) (*CommandFactory, error) { r := sql.NewRepository(dbCon) diff --git a/cmd/tenant-manager-cli/main.go b/cmd/tenant-manager-cli/main.go index c27dddee..e06cbd13 100644 --- a/cmd/tenant-manager-cli/main.go +++ b/cmd/tenant-manager-cli/main.go @@ -19,6 +19,7 @@ import ( "github.com/openkcm/cmk/internal/db" "github.com/openkcm/cmk/internal/log" cmkpluginregistry "github.com/openkcm/cmk/internal/pluginregistry" + serviceapi "github.com/openkcm/cmk/internal/pluginregistry/service/api" ) func runFuncWithSignalHandling(f func(context.Context, *config.Config) error) int { @@ -93,7 +94,7 @@ func setupCommands( ctx context.Context, cfg *config.Config, dbCon *multitenancy.DB, - svcRegistry *cmkpluginregistry.Registry, + svcRegistry serviceapi.Registry, ) (*cobra.Command, error) { factory, err := commands.NewCommandFactory(ctx, cfg, dbCon, svcRegistry) if err != nil { diff --git a/cmd/tenant-manager-cli/main_test.go b/cmd/tenant-manager-cli/main_test.go index cf58903d..4ff2016e 100644 --- a/cmd/tenant-manager-cli/main_test.go +++ b/cmd/tenant-manager-cli/main_test.go @@ -12,9 +12,7 @@ import ( tmCLI "github.com/openkcm/cmk/cmd/tenant-manager-cli" "github.com/openkcm/cmk/internal/config" - cmkpluginregistry "github.com/openkcm/cmk/internal/pluginregistry" "github.com/openkcm/cmk/internal/testutils" - "github.com/openkcm/cmk/internal/testutils/testplugins" ) var errTest = errors.New("test error") @@ -37,16 +35,12 @@ func TestSetupCommands(t *testing.T) { CreateDatabase: true, }) - ps, psCfg := testutils.NewTestPlugins(testplugins.NewIdentityManagement()) + svcRegistry := testutils.NewTestPlugins() cfg := &config.Config{ - Plugins: psCfg, Database: dbCfg, } - svcRegistry, err := cmkpluginregistry.New(t.Context(), cfg, cmkpluginregistry.WithBuiltInPlugins(ps)) - assert.NoError(t, err, "Failed to create catalog") - rootCmd, err := tmCLI.SetupCommands(ctx, cfg, nil, svcRegistry) assert.NoError(t, err) diff --git a/internal/api/transform/key/transformer/transformer.go b/internal/api/transform/key/transformer/transformer.go index bb080f7c..a2a95ad5 100644 --- a/internal/api/transform/key/transformer/transformer.go +++ b/internal/api/transform/key/transformer/transformer.go @@ -11,7 +11,7 @@ import ( "github.com/openkcm/cmk/internal/api/cmkapi" "github.com/openkcm/cmk/internal/api/transform/key/keyshared" "github.com/openkcm/cmk/internal/errs" - cmkpluginregistry "github.com/openkcm/cmk/internal/pluginregistry" + serviceapi "github.com/openkcm/cmk/internal/pluginregistry/service/api" "github.com/openkcm/cmk/internal/pluginregistry/service/api/keymanagement" ) @@ -53,7 +53,7 @@ type PluginProviderTransformer struct { } func NewPluginProviderTransformer( - pluginCatalog *cmkpluginregistry.Registry, + pluginCatalog serviceapi.Registry, provider string, ) (*PluginProviderTransformer, error) { keyManagements, err := pluginCatalog.KeyManagements() diff --git a/internal/api/transform/key/transformer/transformer_test.go b/internal/api/transform/key/transformer/transformer_test.go index d814baa1..23e8226c 100644 --- a/internal/api/transform/key/transformer/transformer_test.go +++ b/internal/api/transform/key/transformer/transformer_test.go @@ -7,21 +7,14 @@ import ( "github.com/openkcm/cmk/internal/api/cmkapi" "github.com/openkcm/cmk/internal/api/transform/key/transformer" - "github.com/openkcm/cmk/internal/config" - cmkpluginregistry "github.com/openkcm/cmk/internal/pluginregistry" "github.com/openkcm/cmk/internal/testutils" - "github.com/openkcm/cmk/internal/testutils/testplugins" "github.com/openkcm/cmk/utils/ptr" ) func getPluginProviderTransformer(t *testing.T) *transformer.PluginProviderTransformer { t.Helper() - ps, psCfg := testutils.NewTestPlugins(testplugins.NewKeystoreOperator()) - - cfg := &config.Config{Plugins: psCfg} - svcRegistry, err := cmkpluginregistry.New(t.Context(), cfg, cmkpluginregistry.WithBuiltInPlugins(ps)) - assert.NoError(t, err) + svcRegistry := testutils.NewTestPlugins() tf, err := transformer.NewPluginProviderTransformer(svcRegistry, "TEST") assert.NoError(t, err) diff --git a/internal/controllers/cmk/base_controller.go b/internal/controllers/cmk/base_controller.go index fc118def..56d58d87 100644 --- a/internal/controllers/cmk/base_controller.go +++ b/internal/controllers/cmk/base_controller.go @@ -12,13 +12,13 @@ import ( eventprocessor "github.com/openkcm/cmk/internal/event-processor" "github.com/openkcm/cmk/internal/log" "github.com/openkcm/cmk/internal/manager" - cmkpluginregistry "github.com/openkcm/cmk/internal/pluginregistry" + serviceapi "github.com/openkcm/cmk/internal/pluginregistry/service/api" "github.com/openkcm/cmk/internal/repo" ) // APIController handles API requests related to CMK (Customer Managed Keys). type APIController struct { - pluginCatalog *cmkpluginregistry.Registry + pluginCatalog serviceapi.Registry Repository repo.Repo Manager *manager.Manager config *config.Config @@ -33,7 +33,7 @@ func NewAPIController( config *config.Config, clientsFactory clients.Factory, migrator db.Migrator, - svcRegistry *cmkpluginregistry.Registry, + svcRegistry serviceapi.Registry, authzLoader *authz_loader.AuthzLoader[authz.APIResourceTypeName, authz.APIAction], ) *APIController { eventFactory, err := eventprocessor.NewEventFactory(ctx, config, r) diff --git a/internal/controllers/cmk/group_controller_test.go b/internal/controllers/cmk/group_controller_test.go index 9385ae8a..fd69ec82 100644 --- a/internal/controllers/cmk/group_controller_test.go +++ b/internal/controllers/cmk/group_controller_test.go @@ -7,7 +7,6 @@ import ( "testing" "github.com/google/uuid" - "github.com/openkcm/plugin-sdk/pkg/catalog" "github.com/stretchr/testify/assert" multitenancy "github.com/bartventer/gorm-multitenancy/v8" @@ -16,7 +15,6 @@ import ( "github.com/openkcm/cmk/internal/constants" "github.com/openkcm/cmk/internal/repo/sql" "github.com/openkcm/cmk/internal/testutils" - "github.com/openkcm/cmk/internal/testutils/testplugins" "github.com/openkcm/cmk/utils/ptr" ) @@ -26,9 +24,7 @@ func startAPIGroups(t *testing.T) (*multitenancy.DB, cmkapi.ServeMux, string) { db, tenants, _ := testutils.NewTestDB(t, testutils.TestDBConfig{}) r := testutils.NewAPIServer( - t, db, testutils.TestAPIServerConfig{ - Plugins: []catalog.BuiltInPlugin{testplugins.NewIdentityManagement()}, - }, + t, db, testutils.TestAPIServerConfig{}, ) return db, r, tenants[0] diff --git a/internal/controllers/cmk/key_controller_test.go b/internal/controllers/cmk/key_controller_test.go index 029aab68..30044646 100644 --- a/internal/controllers/cmk/key_controller_test.go +++ b/internal/controllers/cmk/key_controller_test.go @@ -12,7 +12,6 @@ import ( "time" "github.com/google/uuid" - "github.com/openkcm/plugin-sdk/pkg/catalog" "github.com/stretchr/testify/assert" "gorm.io/gorm" @@ -24,7 +23,6 @@ import ( "github.com/openkcm/cmk/internal/repo" "github.com/openkcm/cmk/internal/repo/sql" "github.com/openkcm/cmk/internal/testutils" - "github.com/openkcm/cmk/internal/testutils/testplugins" cmkcontext "github.com/openkcm/cmk/utils/context" "github.com/openkcm/cmk/utils/ptr" ) @@ -37,7 +35,7 @@ var ( }) ) -func startAPIKeys(t *testing.T, plugins ...catalog.BuiltInPlugin) (*multitenancy.DB, cmkapi.ServeMux, string) { +func startAPIKeys(t *testing.T) (*multitenancy.DB, cmkapi.ServeMux, string) { t.Helper() db, tenants, dbCfg := testutils.NewTestDB(t, testutils.TestDBConfig{ @@ -45,8 +43,8 @@ func startAPIKeys(t *testing.T, plugins ...catalog.BuiltInPlugin) (*multitenancy }) return db, testutils.NewAPIServer(t, db, testutils.TestAPIServerConfig{ - Plugins: plugins, - Config: config.Config{Database: dbCfg}, + Registry: testutils.NewTestPlugins(), + Config: config.Config{Database: dbCfg}, }), tenants[0] } @@ -261,7 +259,7 @@ func TestKeyControllerGetKeysPagination(t *testing.T) { } func TestKeyControllerPostKeys(t *testing.T) { - db, sv, tenant := startAPIKeys(t, testplugins.NewKeystoreOperator()) + db, sv, tenant := startAPIKeys(t) r := sql.NewRepository(db) ctx := cmkcontext.CreateTenantContext(t.Context(), tenant) @@ -487,7 +485,7 @@ func TestKeyControllerPostKeys(t *testing.T) { } func TestKeyControllerPostKeysDrainedKeystorePool(t *testing.T) { - db, sv, tenant := startAPIKeys(t, testplugins.NewKeystoreOperator()) + db, sv, tenant := startAPIKeys(t) ctx := cmkcontext.CreateTenantContext(t.Context(), tenant) r := sql.NewRepository(db) @@ -623,7 +621,7 @@ func TestKeyControllerGetKeysKeyID(t *testing.T) { } func TestKeyControllerDeleteKeysKeyID(t *testing.T) { - db, sv, tenant := startAPIKeys(t, testplugins.NewKeystoreOperator()) + db, sv, tenant := startAPIKeys(t) ctx := cmkcontext.CreateTenantContext(t.Context(), tenant) r := sql.NewRepository(db) @@ -729,7 +727,7 @@ func TestKeyControllerDeleteKeysKeyID(t *testing.T) { } func TestKeyControllerUpdateKey(t *testing.T) { - db, sv, tenant := startAPIKeys(t, testplugins.NewKeystoreOperator()) + db, sv, tenant := startAPIKeys(t) ctx := cmkcontext.CreateTenantContext(t.Context(), tenant) r := sql.NewRepository(db) @@ -1086,7 +1084,7 @@ func TestKeyControllerGetImportParams(t *testing.T) { } func TestKeyControllerImportKeyMaterial(t *testing.T) { - db, sv, tenant := startAPIKeys(t, testplugins.NewKeystoreOperator()) + db, sv, tenant := startAPIKeys(t) ctx := cmkcontext.CreateTenantContext(t.Context(), tenant) r := sql.NewRepository(db) diff --git a/internal/controllers/cmk/keyconfiguration_controller_test.go b/internal/controllers/cmk/keyconfiguration_controller_test.go index 3943c6fc..676df82e 100644 --- a/internal/controllers/cmk/keyconfiguration_controller_test.go +++ b/internal/controllers/cmk/keyconfiguration_controller_test.go @@ -14,7 +14,6 @@ import ( "github.com/google/uuid" "github.com/openkcm/common-sdk/pkg/auth" "github.com/openkcm/common-sdk/pkg/commoncfg" - "github.com/openkcm/plugin-sdk/pkg/catalog" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" "gopkg.in/yaml.v3" @@ -29,7 +28,6 @@ import ( "github.com/openkcm/cmk/internal/repo" "github.com/openkcm/cmk/internal/repo/sql" "github.com/openkcm/cmk/internal/testutils" - "github.com/openkcm/cmk/internal/testutils/testplugins" cmkcontext "github.com/openkcm/cmk/utils/context" "github.com/openkcm/cmk/utils/crypto" "github.com/openkcm/cmk/utils/ptr" @@ -46,9 +44,7 @@ func startAPIKeyConfig(t *testing.T) ( tenant := tenants[0] - sv := testutils.NewAPIServer(t, db, testutils.TestAPIServerConfig{ - Plugins: []catalog.BuiltInPlugin{testplugins.NewIdentityManagement()}, - }) + sv := testutils.NewAPIServer(t, db, testutils.TestAPIServerConfig{}) ctx := cmkcontext.CreateTenantContext(t.Context(), tenant) r := sql.NewRepository(db) diff --git a/internal/controllers/cmk/keyversion_controller_test.go b/internal/controllers/cmk/keyversion_controller_test.go index 857baafa..9b3b2b47 100644 --- a/internal/controllers/cmk/keyversion_controller_test.go +++ b/internal/controllers/cmk/keyversion_controller_test.go @@ -18,7 +18,6 @@ import ( "github.com/openkcm/cmk/internal/model" "github.com/openkcm/cmk/internal/repo/sql" "github.com/openkcm/cmk/internal/testutils" - "github.com/openkcm/cmk/internal/testutils/testplugins" cmkcontext "github.com/openkcm/cmk/utils/context" "github.com/openkcm/cmk/utils/ptr" ) @@ -408,7 +407,7 @@ func TestKeyVersionController_GetKeyVersions_IsPrimaryWithPagination(t *testing. } func TestKeyVersionRefreshAndDisable(t *testing.T) { - db, sv, tenant := startAPIKeys(t, testplugins.NewKeystoreOperator()) + db, sv, tenant := startAPIKeys(t) ctx := cmkcontext.CreateTenantContext(t.Context(), tenant) r := sql.NewRepository(db) diff --git a/internal/controllers/cmk/system_controller_test.go b/internal/controllers/cmk/system_controller_test.go index 3c4b55a4..2d9d5018 100644 --- a/internal/controllers/cmk/system_controller_test.go +++ b/internal/controllers/cmk/system_controller_test.go @@ -8,7 +8,6 @@ import ( "testing" "github.com/google/uuid" - "github.com/openkcm/plugin-sdk/pkg/catalog" "github.com/stretchr/testify/assert" "google.golang.org/grpc" @@ -23,7 +22,6 @@ import ( "github.com/openkcm/cmk/internal/repo" "github.com/openkcm/cmk/internal/repo/sql" "github.com/openkcm/cmk/internal/testutils" - "github.com/openkcm/cmk/internal/testutils/testplugins" cmkcontext "github.com/openkcm/cmk/utils/context" "github.com/openkcm/cmk/utils/ptr" ) @@ -719,7 +717,6 @@ func TestLinkSystemAction(t *testing.T) { ) db, sv, tenant := startAPISystems(t, testutils.TestAPIServerConfig{ - Plugins: []catalog.BuiltInPlugin{testplugins.NewSystemInformation()}, GRPCCon: grpcCon, }) ctx := cmkcontext.CreateTenantContext(t.Context(), tenant) @@ -881,9 +878,7 @@ func TestLinkSystemAction(t *testing.T) { } func TestUnlinkSystemAction(t *testing.T) { - db, sv, tenant := startAPISystems(t, testutils.TestAPIServerConfig{ - Plugins: []catalog.BuiltInPlugin{testplugins.NewSystemInformation()}, - }) + db, sv, tenant := startAPISystems(t, testutils.TestAPIServerConfig{}) ctx := cmkcontext.CreateTenantContext(t.Context(), tenant) r := sql.NewRepository(db) diff --git a/internal/controllers/cmk/workflow_controller_test.go b/internal/controllers/cmk/workflow_controller_test.go index 8bcd23b1..e828835d 100644 --- a/internal/controllers/cmk/workflow_controller_test.go +++ b/internal/controllers/cmk/workflow_controller_test.go @@ -11,7 +11,6 @@ import ( "testing" "github.com/google/uuid" - "github.com/openkcm/plugin-sdk/pkg/catalog" "github.com/stretchr/testify/assert" multitenancy "github.com/bartventer/gorm-multitenancy/v8" @@ -23,7 +22,6 @@ import ( "github.com/openkcm/cmk/internal/repo" cmksql "github.com/openkcm/cmk/internal/repo/sql" "github.com/openkcm/cmk/internal/testutils" - "github.com/openkcm/cmk/internal/testutils/testplugins" wfMechanism "github.com/openkcm/cmk/internal/workflow" cmkcontext "github.com/openkcm/cmk/utils/context" "github.com/openkcm/cmk/utils/ptr" @@ -37,8 +35,7 @@ func startAPIWorkflows(t *testing.T) (*multitenancy.DB, cmkapi.ServeMux, string) db, tenants, dbCfg := testutils.NewTestDB(t, testutils.TestDBConfig{}) sv := testutils.NewAPIServer(t, db, testutils.TestAPIServerConfig{ - Config: config.Config{Database: dbCfg}, - Plugins: []catalog.BuiltInPlugin{testplugins.NewIdentityManagement()}, + Config: config.Config{Database: dbCfg}, }) return db, sv, tenants[0] diff --git a/internal/event-processor/reconciler.go b/internal/event-processor/reconciler.go index 3021c8cf..8691977f 100644 --- a/internal/event-processor/reconciler.go +++ b/internal/event-processor/reconciler.go @@ -25,7 +25,7 @@ import ( "github.com/openkcm/cmk/internal/config" "github.com/openkcm/cmk/internal/errs" "github.com/openkcm/cmk/internal/log" - cmkpluginregistry "github.com/openkcm/cmk/internal/pluginregistry" + serviceapi "github.com/openkcm/cmk/internal/pluginregistry/service/api" "github.com/openkcm/cmk/internal/repo" ) @@ -80,7 +80,7 @@ type CryptoReconciler struct { manager *orbital.Manager targets map[string]struct{} initiators []orbital.Initiator - svcRegistry *cmkpluginregistry.Registry + svcRegistry serviceapi.Registry jobHandlerMap map[JobType]JobHandler tracer trace.Tracer } @@ -92,7 +92,7 @@ func NewCryptoReconciler( ctx context.Context, cfg *config.Config, repository repo.Repo, - svcRegistry *cmkpluginregistry.Registry, + svcRegistry serviceapi.Registry, clientsFactory clients.Factory, opts ...Option, ) (*CryptoReconciler, error) { diff --git a/internal/event-processor/reconciler_test.go b/internal/event-processor/reconciler_test.go index 26a80f3e..b5c8ab38 100644 --- a/internal/event-processor/reconciler_test.go +++ b/internal/event-processor/reconciler_test.go @@ -30,7 +30,6 @@ import ( eventprocessor "github.com/openkcm/cmk/internal/event-processor" eventProto "github.com/openkcm/cmk/internal/event-processor/proto" "github.com/openkcm/cmk/internal/model" - cmkpluginregistry "github.com/openkcm/cmk/internal/pluginregistry" "github.com/openkcm/cmk/internal/repo" "github.com/openkcm/cmk/internal/repo/sql" "github.com/openkcm/cmk/internal/testutils" @@ -49,7 +48,7 @@ type TestInstance struct { fakeService *systems.FakeService reconciler *eventprocessor.CryptoReconciler traceRecorder *tracetest.SpanRecorder - pluginOp *testplugins.KeystoreOperator + pluginOp *testplugins.TestKeyManagement } func setupTestInstance( @@ -63,12 +62,11 @@ func setupTestInstance( }) r := sql.NewRepository(db) - pluginOp := testplugins.NewKeystoreOperatorInstance() - ps, psCfg := testutils.NewTestPlugins(testplugins.NewKeystoreOperatorFromInstance(pluginOp)) + pluginOp := testplugins.NewTestKeyManagement(true, true) + svcRegistry := testutils.NewTestPlugins(testplugins.WithKeyManagement(testplugins.Name, pluginOp)) cfg := &config.Config{ Database: dbCfg, - Plugins: psCfg, Landscape: config.Landscape{ Region: uuid.NewString(), }, @@ -99,9 +97,6 @@ func setupTestInstance( } } - svcRegistry, err := cmkpluginregistry.New(t.Context(), cfg, cmkpluginregistry.WithBuiltInPlugins(ps)) - assert.NoError(t, err) - logger := testutils.SetupLoggerWithBuffer() systemService := systems.NewFakeService(logger) mappingService := mapping.NewFakeService() diff --git a/internal/event-processor/resolvers.go b/internal/event-processor/resolvers.go index 38250089..cb4f452e 100644 --- a/internal/event-processor/resolvers.go +++ b/internal/event-processor/resolvers.go @@ -17,7 +17,7 @@ import ( "github.com/openkcm/cmk/internal/event-processor/proto" "github.com/openkcm/cmk/internal/log" "github.com/openkcm/cmk/internal/model" - cmkpluginregistry "github.com/openkcm/cmk/internal/pluginregistry" + serviceapi "github.com/openkcm/cmk/internal/pluginregistry/service/api" "github.com/openkcm/cmk/internal/pluginregistry/service/api/keymanagement" "github.com/openkcm/cmk/internal/repo" cmkcontext "github.com/openkcm/cmk/utils/context" @@ -28,7 +28,7 @@ import ( type SystemTaskInfoResolver struct { repo repo.Repo targets map[string]struct{} - svcRegistry *cmkpluginregistry.Registry + svcRegistry serviceapi.Registry cfg *config.Config } diff --git a/internal/manager/base.go b/internal/manager/base.go index f570220f..fd19f3a3 100644 --- a/internal/manager/base.go +++ b/internal/manager/base.go @@ -9,7 +9,7 @@ import ( "github.com/openkcm/cmk/internal/config" "github.com/openkcm/cmk/internal/db" eventprocessor "github.com/openkcm/cmk/internal/event-processor" - cmkpluginregistry "github.com/openkcm/cmk/internal/pluginregistry" + serviceapi "github.com/openkcm/cmk/internal/pluginregistry/service/api" "github.com/openkcm/cmk/internal/repo" ) @@ -28,7 +28,7 @@ type Manager struct { Tenant Tenant - Catalog *cmkpluginregistry.Registry + Catalog serviceapi.Registry EventFactory *eventprocessor.EventFactory Auditor *auditor.Auditor } @@ -39,7 +39,7 @@ func New( repo repo.Repo, config *config.Config, clientsFactory clients.Factory, - svcRegistry *cmkpluginregistry.Registry, + svcRegistry serviceapi.Registry, eventFactory *eventprocessor.EventFactory, asyncClient async.Client, migrator db.Migrator, diff --git a/internal/manager/base_test.go b/internal/manager/base_test.go index ee7b8fac..30da9174 100644 --- a/internal/manager/base_test.go +++ b/internal/manager/base_test.go @@ -8,10 +8,8 @@ import ( "github.com/openkcm/cmk/internal/clients" "github.com/openkcm/cmk/internal/config" "github.com/openkcm/cmk/internal/manager" - cmkpluginregistry "github.com/openkcm/cmk/internal/pluginregistry" "github.com/openkcm/cmk/internal/repo/sql" "github.com/openkcm/cmk/internal/testutils" - "github.com/openkcm/cmk/internal/testutils/testplugins" ) const providerTest = "TEST" @@ -20,13 +18,9 @@ func TestNewManager(t *testing.T) { db, _, _ := testutils.NewTestDB(t, testutils.TestDBConfig{}) dbRepo := sql.NewRepository(db) - ps, psCfg := testutils.NewTestPlugins(testplugins.NewSystemInformation()) + svcRegistry := testutils.NewTestPlugins() - cfg := &config.Config{ - Plugins: psCfg, - } - svcRegistry, err := cmkpluginregistry.New(t.Context(), cfg, cmkpluginregistry.WithBuiltInPlugins(ps)) - assert.NoError(t, err) + cfg := &config.Config{} factory, err := clients.NewFactory(cfg.Services) assert.NoError(t, err) diff --git a/internal/manager/certificate.go b/internal/manager/certificate.go index 9d4cc049..5be2bbb6 100644 --- a/internal/manager/certificate.go +++ b/internal/manager/certificate.go @@ -17,7 +17,7 @@ import ( "github.com/openkcm/cmk/internal/errs" "github.com/openkcm/cmk/internal/log" "github.com/openkcm/cmk/internal/model" - cmkpluginregistry "github.com/openkcm/cmk/internal/pluginregistry" + serviceapi "github.com/openkcm/cmk/internal/pluginregistry/service/api" "github.com/openkcm/cmk/internal/pluginregistry/service/api/certificateissuer" "github.com/openkcm/cmk/internal/repo" cmkcontext "github.com/openkcm/cmk/utils/context" @@ -52,7 +52,7 @@ type CertificateManager struct { func NewCertificateManager( ctx context.Context, repo repo.Repo, - svcRegistry *cmkpluginregistry.Registry, + svcRegistry serviceapi.Registry, cfg *config.Config, ) *CertificateManager { certIssuer, err := svcRegistry.CertificateIssuer() diff --git a/internal/manager/certificate_test.go b/internal/manager/certificate_test.go index e76891b6..cbeb758d 100644 --- a/internal/manager/certificate_test.go +++ b/internal/manager/certificate_test.go @@ -19,12 +19,10 @@ import ( "github.com/openkcm/cmk/internal/config" "github.com/openkcm/cmk/internal/manager" "github.com/openkcm/cmk/internal/model" - cmkpluginregistry "github.com/openkcm/cmk/internal/pluginregistry" "github.com/openkcm/cmk/internal/pluginregistry/service/api/certificateissuer" "github.com/openkcm/cmk/internal/repo" "github.com/openkcm/cmk/internal/repo/sql" "github.com/openkcm/cmk/internal/testutils" - "github.com/openkcm/cmk/internal/testutils/testplugins" cmkcontext "github.com/openkcm/cmk/utils/context" "github.com/openkcm/cmk/utils/crypto" "github.com/openkcm/cmk/utils/ptr" @@ -58,20 +56,13 @@ func SetupCertificateManager( dbRepository := sql.NewRepository(db) - ps, psCfg := testutils.NewTestPlugins(testplugins.NewCertificateIssuer()) - cfg := &config.Config{Plugins: psCfg} - - catalog, err := cmkpluginregistry.New( - t.Context(), - cfg, - cmkpluginregistry.WithBuiltInPlugins(ps), - ) - assert.NoError(t, err) + svcRegistry := testutils.NewTestPlugins() + cfg := &config.Config{} m := manager.NewCertificateManager( t.Context(), dbRepository, - catalog, + svcRegistry, cfg, ) diff --git a/internal/manager/group.go b/internal/manager/group.go index 7f00af07..f69fe946 100644 --- a/internal/manager/group.go +++ b/internal/manager/group.go @@ -14,7 +14,7 @@ import ( "github.com/openkcm/cmk/internal/errs" "github.com/openkcm/cmk/internal/log" "github.com/openkcm/cmk/internal/model" - cmkpluginregistry "github.com/openkcm/cmk/internal/pluginregistry" + serviceapi "github.com/openkcm/cmk/internal/pluginregistry/service/api" "github.com/openkcm/cmk/internal/pluginregistry/service/api/identitymanagement" "github.com/openkcm/cmk/internal/repo" cmkcontext "github.com/openkcm/cmk/utils/context" @@ -22,13 +22,13 @@ import ( type GroupManager struct { repo repo.Repo - svcRegistry *cmkpluginregistry.Registry + svcRegistry serviceapi.Registry userManager User } func NewGroupManager( repository repo.Repo, - svcRegistry *cmkpluginregistry.Registry, + svcRegistry serviceapi.Registry, userManager User, ) *GroupManager { return &GroupManager{ diff --git a/internal/manager/group_test.go b/internal/manager/group_test.go index 6ae0bf16..0afe61bc 100644 --- a/internal/manager/group_test.go +++ b/internal/manager/group_test.go @@ -14,11 +14,9 @@ import ( "github.com/openkcm/cmk/internal/constants" "github.com/openkcm/cmk/internal/manager" "github.com/openkcm/cmk/internal/model" - cmkpluginregistry "github.com/openkcm/cmk/internal/pluginregistry" "github.com/openkcm/cmk/internal/repo" "github.com/openkcm/cmk/internal/repo/sql" "github.com/openkcm/cmk/internal/testutils" - "github.com/openkcm/cmk/internal/testutils/testplugins" "github.com/openkcm/cmk/utils/ptr" ) @@ -31,14 +29,7 @@ func SetupGroupManager(t *testing.T) (*manager.GroupManager, *multitenancy.DB, s }, ) - ps, psCfg := testutils.NewTestPlugins(testplugins.NewIdentityManagement()) - - svcRegistry, err := cmkpluginregistry.New( - t.Context(), &config.Config{ - Plugins: psCfg, - }, cmkpluginregistry.WithBuiltInPlugins(ps), - ) - assert.NoError(t, err) + svcRegistry := testutils.NewTestPlugins() dbRepository := sql.NewRepository(db) diff --git a/internal/manager/key.go b/internal/manager/key.go index 8738ebfc..e0cf0173 100644 --- a/internal/manager/key.go +++ b/internal/manager/key.go @@ -23,7 +23,7 @@ import ( eventprocessor "github.com/openkcm/cmk/internal/event-processor" "github.com/openkcm/cmk/internal/log" "github.com/openkcm/cmk/internal/model" - cmkpluginregistry "github.com/openkcm/cmk/internal/pluginregistry" + serviceapi "github.com/openkcm/cmk/internal/pluginregistry/service/api" "github.com/openkcm/cmk/internal/pluginregistry/service/api/common" "github.com/openkcm/cmk/internal/pluginregistry/service/api/keymanagement" "github.com/openkcm/cmk/internal/repo" @@ -64,7 +64,7 @@ type KeyManager struct { func NewKeyManager( repo repo.Repo, - svcRegistry *cmkpluginregistry.Registry, + svcRegistry serviceapi.Registry, tenantConfigs *TenantConfigManager, keyConfigManager *KeyConfigManager, user User, diff --git a/internal/manager/key_test.go b/internal/manager/key_test.go index 4c02d252..9b96c757 100644 --- a/internal/manager/key_test.go +++ b/internal/manager/key_test.go @@ -20,7 +20,6 @@ import ( "github.com/openkcm/cmk/internal/event-processor/proto" "github.com/openkcm/cmk/internal/manager" "github.com/openkcm/cmk/internal/model" - cmkpluginregistry "github.com/openkcm/cmk/internal/pluginregistry" "github.com/openkcm/cmk/internal/pluginregistry/service/api/common" "github.com/openkcm/cmk/internal/pluginregistry/service/api/keymanagement" "github.com/openkcm/cmk/internal/repo" @@ -50,10 +49,7 @@ func SetupKeyTest(t *testing.T) ( ctx := testutils.CreateCtxWithTenant(tenant) r := sql.NewRepository(db) - ps, psCfg := testutils.NewTestPlugins( - testplugins.NewKeystoreOperator(), - ) - + svcRegistry := testutils.NewTestPlugins() cryptoCerts := []manager.ClientCertificate{ { Name: "crypto-1", @@ -71,7 +67,6 @@ func SetupKeyTest(t *testing.T) ( require.NoError(t, err) cfg := &config.Config{ - Plugins: psCfg, Database: dbConf, CryptoLayer: config.CryptoLayer{ CertX509Trusts: commoncfg.SourceRef{ @@ -80,8 +75,6 @@ func SetupKeyTest(t *testing.T) ( }, }, } - svcRegistry, err := cmkpluginregistry.New(ctx, cfg, cmkpluginregistry.WithBuiltInPlugins(ps)) - assert.NoError(t, err) cmkAuditor := auditor.New(ctx, cfg) @@ -1307,7 +1300,7 @@ func TestKeyRotationTime(t *testing.T) { keystoreRotationTimeStr := keystoreRotationTime.Format(time.RFC3339) // Setup plugin with custom rotation time - pluginOps := testplugins.NewKeystoreOperatorInstance() + pluginOps := testplugins.NewTestKeyManagement(true, true) // Register the key in the plugin first pluginOps.HandleKeyRecord("test-native-id", testplugins.EnabledKeyStatus) pluginOps.SetKeyVersionInfo("test-native-id", "version-1", keystoreRotationTimeStr) @@ -1321,7 +1314,7 @@ func TestKeyRotationTime(t *testing.T) { ctx := testutils.CreateCtxWithTenant(tenant) r := sql.NewRepository(db) - ps, psCfg := testutils.NewTestPlugins(testplugins.NewKeystoreOperatorFromInstance(pluginOps)) + svcRegistry := testutils.NewTestPlugins(testplugins.WithKeyManagement(testplugins.Name, pluginOps)) cryptoCerts := []manager.ClientCertificate{ { Name: "crypto-1", @@ -1335,7 +1328,6 @@ func TestKeyRotationTime(t *testing.T) { require.NoError(t, err) cfg := &config.Config{ - Plugins: psCfg, Database: dbConf, CryptoLayer: config.CryptoLayer{ CertX509Trusts: commoncfg.SourceRef{ @@ -1344,8 +1336,6 @@ func TestKeyRotationTime(t *testing.T) { }, }, } - svcRegistry, err := cmkpluginregistry.New(ctx, cfg, cmkpluginregistry.WithBuiltInPlugins(ps)) - require.NoError(t, err) cmkAuditor := auditor.New(ctx, cfg) tenantConfigManager := manager.NewTenantConfigManager(r, svcRegistry, nil) @@ -1481,15 +1471,12 @@ func TestKeyRotationTime(t *testing.T) { t.Run("Fallback to current time when keystore doesn't provide rotation time", func(t *testing.T) { // Setup plugin without rotation time - pluginOpsNoTime := testplugins.NewKeystoreOperatorInstance() + pluginOpsNoTime := testplugins.NewTestKeyManagement(true, true) // Register key but don't set rotation time (empty string) pluginOpsNoTime.HandleKeyRecord("test-native-id-no-time", testplugins.EnabledKeyStatus) pluginOpsNoTime.SetKeyVersionInfo("test-native-id-no-time", "version-1", "") // Empty rotation time - ps2, psCfg2 := testutils.NewTestPlugins(testplugins.NewKeystoreOperatorFromInstance(pluginOpsNoTime)) - cfg2 := config.Config{Plugins: psCfg2} - svcRegistry2, err := cmkpluginregistry.New(ctx, &cfg2, cmkpluginregistry.WithBuiltInPlugins(ps2)) - require.NoError(t, err) + svcRegistry2 := testutils.NewTestPlugins(testplugins.WithKeyManagement(testplugins.Name, pluginOpsNoTime)) km2 := manager.NewKeyManager(r, svcRegistry2, tenantConfigManager, keyConfigManager, userManager, certManager, nil, cmkAuditor) diff --git a/internal/manager/keyversion.go b/internal/manager/keyversion.go index e212a5e3..bda5b56f 100644 --- a/internal/manager/keyversion.go +++ b/internal/manager/keyversion.go @@ -11,7 +11,7 @@ import ( "github.com/openkcm/cmk/internal/auditor" "github.com/openkcm/cmk/internal/errs" "github.com/openkcm/cmk/internal/model" - cmkpluginregistry "github.com/openkcm/cmk/internal/pluginregistry" + serviceapi "github.com/openkcm/cmk/internal/pluginregistry/service/api" "github.com/openkcm/cmk/internal/repo" ) @@ -31,7 +31,7 @@ type KeyVersionManager struct { func NewKeyVersionManager( repo repo.Repo, - svcRegistry *cmkpluginregistry.Registry, + svcRegistry serviceapi.Registry, tenantConfigs *TenantConfigManager, certManager *CertificateManager, cmkAuditor *auditor.Auditor, diff --git a/internal/manager/keyversion_test.go b/internal/manager/keyversion_test.go index 0299dfde..f5610011 100644 --- a/internal/manager/keyversion_test.go +++ b/internal/manager/keyversion_test.go @@ -13,11 +13,9 @@ import ( "github.com/openkcm/cmk/internal/constants" "github.com/openkcm/cmk/internal/manager" "github.com/openkcm/cmk/internal/model" - cmkpluginregistry "github.com/openkcm/cmk/internal/pluginregistry" "github.com/openkcm/cmk/internal/repo" "github.com/openkcm/cmk/internal/repo/sql" "github.com/openkcm/cmk/internal/testutils" - "github.com/openkcm/cmk/internal/testutils/testplugins" ) var ( @@ -51,13 +49,9 @@ func (s *KeyVersionManagerSuit) SetupSuite() { s.ctx = testutils.CreateCtxWithTenant(s.tenant) s.r = sql.NewRepository(db) - ps, psCfg := testutils.NewTestPlugins( - testplugins.NewKeystoreOperator(), - ) + svcRegistry := testutils.NewTestPlugins() - cfg := config.Config{Plugins: psCfg} - svcRegistry, err := cmkpluginregistry.New(s.ctx, &cfg, cmkpluginregistry.WithBuiltInPlugins(ps)) - s.Require().NoError(err) + cfg := config.Config{} certManager := manager.NewCertificateManager( s.ctx, s.r, svcRegistry, diff --git a/internal/manager/providerconfigmanager.go b/internal/manager/providerconfigmanager.go index fac04d40..a85a297b 100644 --- a/internal/manager/providerconfigmanager.go +++ b/internal/manager/providerconfigmanager.go @@ -16,11 +16,10 @@ import ( "github.com/openkcm/cmk/internal/errs" "github.com/openkcm/cmk/internal/log" "github.com/openkcm/cmk/internal/model" - cmkpluginregistry "github.com/openkcm/cmk/internal/pluginregistry" + serviceapi "github.com/openkcm/cmk/internal/pluginregistry/service/api" "github.com/openkcm/cmk/internal/pluginregistry/service/api/common" "github.com/openkcm/cmk/internal/pluginregistry/service/api/keymanagement" "github.com/openkcm/cmk/internal/pluginregistry/service/api/keystoremanagement" - servicewrapper "github.com/openkcm/cmk/internal/pluginregistry/service/wrapper" "github.com/openkcm/cmk/internal/repo" cmkcontext "github.com/openkcm/cmk/utils/context" pluginHelpers "github.com/openkcm/cmk/utils/plugins" @@ -67,7 +66,7 @@ func (c ProviderConfig) IsExpired() bool { } type ProviderConfigManager struct { - svcRegistry *cmkpluginregistry.Registry + svcRegistry serviceapi.Registry providers map[ProviderCachedKey]*ProviderConfig mu sync.RWMutex tenantConfigs *TenantConfigManager @@ -77,7 +76,7 @@ type ProviderConfigManager struct { } func NewProviderConfigManager( - svcRegistry *cmkpluginregistry.Registry, + svcRegistry serviceapi.Registry, providers map[ProviderCachedKey]*ProviderConfig, tenantConfigs *TenantConfigManager, certs *CertificateManager, @@ -269,16 +268,16 @@ func (pmc *ProviderConfigManager) GetDefaultKeystoreFromCatalog() (string, error return "", errs.Wrapf(ErrGetDefaultKeystore, "no plugin catalog available") } - plugins := pmc.svcRegistry.LookupByType(servicewrapper.KeyManagementType) - if len(plugins) == 0 { + plugins, err := pmc.svcRegistry.KeyManagementList() + if err != nil || len(plugins) == 0 { return "", errs.Wrapf(ErrGetDefaultKeystore, "no keystore plugins found in catalog") } providers := make([]string, 0) for _, plugin := range plugins { - if pluginHelpers.HasTag(plugin.Info().Tags(), constants.DefaultKeyStore) { - providers = append(providers, plugin.Info().Name()) + if pluginHelpers.HasTag(plugin.ServiceInfo().Tags(), constants.DefaultKeyStore) { + providers = append(providers, plugin.ServiceInfo().Name()) } } diff --git a/internal/manager/providerconfigmanager_test.go b/internal/manager/providerconfigmanager_test.go index cf27afde..eb00c46f 100644 --- a/internal/manager/providerconfigmanager_test.go +++ b/internal/manager/providerconfigmanager_test.go @@ -11,27 +11,17 @@ import ( "github.com/openkcm/cmk/internal/constants" "github.com/openkcm/cmk/internal/manager" "github.com/openkcm/cmk/internal/model" - cmkpluginregistry "github.com/openkcm/cmk/internal/pluginregistry" "github.com/openkcm/cmk/internal/repo" "github.com/openkcm/cmk/internal/repo/sql" "github.com/openkcm/cmk/internal/testutils" - "github.com/openkcm/cmk/internal/testutils/testplugins" cmkcontext "github.com/openkcm/cmk/utils/context" ) func SetupProviderManager(t *testing.T) (*manager.ProviderConfigManager, string, *multitenancy.DB) { t.Helper() - ps, psCfg := testutils.NewTestPlugins( - testplugins.NewKeystoreOperator(), - testplugins.NewKeystoreManagement(), - ) - - cfg := &config.Config{ - Plugins: psCfg, - } - svcRegistry, err := cmkpluginregistry.New(t.Context(), cfg, cmkpluginregistry.WithBuiltInPlugins(ps)) - assert.NoError(t, err) + svcRegistry := testutils.NewTestPlugins() + cfg := &config.Config{} db, tenants, _ := testutils.NewTestDB(t, testutils.TestDBConfig{}) r := sql.NewRepository(db) diff --git a/internal/manager/system.go b/internal/manager/system.go index 697082b3..7d5cdacf 100644 --- a/internal/manager/system.go +++ b/internal/manager/system.go @@ -24,7 +24,7 @@ import ( eventprocessor "github.com/openkcm/cmk/internal/event-processor" "github.com/openkcm/cmk/internal/log" "github.com/openkcm/cmk/internal/model" - cmkpluginregistry "github.com/openkcm/cmk/internal/pluginregistry" + serviceapi "github.com/openkcm/cmk/internal/pluginregistry/service/api" "github.com/openkcm/cmk/internal/repo" cmkcontext "github.com/openkcm/cmk/utils/context" "github.com/openkcm/cmk/utils/ptr" @@ -135,7 +135,7 @@ func NewSystemManager( repository repo.Repo, clientsFactory clients.Factory, eventFactory *eventprocessor.EventFactory, - svcRegistry *cmkpluginregistry.Registry, + svcRegistry serviceapi.Registry, cfg *config.Config, keyConfigManager *KeyConfigManager, user User, diff --git a/internal/manager/system_test.go b/internal/manager/system_test.go index 0ca03a38..1d90fb24 100644 --- a/internal/manager/system_test.go +++ b/internal/manager/system_test.go @@ -25,11 +25,9 @@ import ( eventprocessor "github.com/openkcm/cmk/internal/event-processor" "github.com/openkcm/cmk/internal/manager" "github.com/openkcm/cmk/internal/model" - cmkpluginregistry "github.com/openkcm/cmk/internal/pluginregistry" "github.com/openkcm/cmk/internal/repo" "github.com/openkcm/cmk/internal/repo/sql" "github.com/openkcm/cmk/internal/testutils" - "github.com/openkcm/cmk/internal/testutils/testplugins" "github.com/openkcm/cmk/utils/ptr" ) @@ -42,12 +40,7 @@ func SetupSystemManager(t *testing.T, clientsFactory clients.Factory) ( db, tenants, dbCfg := testutils.NewTestDB(t, testutils.TestDBConfig{}) - ps, psCfg := testutils.NewTestPlugins( - testplugins.NewSystemInformation(), - ) - cfg := config.Config{ - Plugins: psCfg, BaseConfig: commoncfg.BaseConfig{ Audit: commoncfg.Audit{ Endpoint: "http://localhost:4318/v1/logs", @@ -56,8 +49,8 @@ func SetupSystemManager(t *testing.T, clientsFactory clients.Factory) ( Database: dbCfg, } - svcRegistry, err := cmkpluginregistry.New(t.Context(), &cfg, cmkpluginregistry.WithBuiltInPlugins(ps)) - require.NoError(t, err) + svcRegistry := testutils.NewTestPlugins() + var err error r := sql.NewRepository(db) diff --git a/internal/manager/systeminformation.go b/internal/manager/systeminformation.go index d8fa0823..8b866823 100644 --- a/internal/manager/systeminformation.go +++ b/internal/manager/systeminformation.go @@ -11,7 +11,7 @@ import ( "github.com/openkcm/cmk/internal/errs" "github.com/openkcm/cmk/internal/log" "github.com/openkcm/cmk/internal/model" - cmkpluginregistry "github.com/openkcm/cmk/internal/pluginregistry" + serviceapi "github.com/openkcm/cmk/internal/pluginregistry/service/api" "github.com/openkcm/cmk/internal/pluginregistry/service/api/systeminformation" "github.com/openkcm/cmk/internal/repo" ) @@ -32,7 +32,7 @@ type SystemInformation struct { func NewSystemInformationManager( repo repo.Repo, - svcRegistry *cmkpluginregistry.Registry, + svcRegistry serviceapi.Registry, systemCfg *config.System, ) (*SystemInformation, error) { svc, err := svcRegistry.SystemInformation() diff --git a/internal/manager/systeminformation_test.go b/internal/manager/systeminformation_test.go index ad7d863b..295a7ee3 100644 --- a/internal/manager/systeminformation_test.go +++ b/internal/manager/systeminformation_test.go @@ -6,7 +6,6 @@ import ( "testing" "github.com/openkcm/plugin-sdk/api" - "github.com/openkcm/plugin-sdk/pkg/catalog" "github.com/stretchr/testify/assert" multitenancy "github.com/bartventer/gorm-multitenancy/v8" @@ -14,7 +13,6 @@ import ( "github.com/openkcm/cmk/internal/config" "github.com/openkcm/cmk/internal/manager" "github.com/openkcm/cmk/internal/model" - cmkpluginregistry "github.com/openkcm/cmk/internal/pluginregistry" "github.com/openkcm/cmk/internal/pluginregistry/service/api/systeminformation" "github.com/openkcm/cmk/internal/pluginregistry/service/wrapper/system_information" "github.com/openkcm/cmk/internal/repo" @@ -39,12 +37,7 @@ func SetupSystemInfoManager(t *testing.T) ( db, tenants, _ := testutils.NewTestDB(t, testutils.TestDBConfig{}) dbRepository := sql.NewRepository(db) - ps, psCfg := testutils.NewTestPlugins( - testplugins.NewSystemInformation(), - ) - - svcRegistry, err := cmkpluginregistry.New(t.Context(), &config.Config{Plugins: psCfg}, cmkpluginregistry.WithBuiltInPlugins(ps)) - assert.NoError(t, err) + svcRegistry := testutils.NewTestPlugins() systemManager, err := manager.NewSystemInformationManager( dbRepository, svcRegistry, @@ -136,42 +129,33 @@ func createSystemForTests() *model.System { func TestNewSystemInformationManager(t *testing.T) { tests := []struct { name string - plugins []catalog.BuiltInPlugin + opts []testplugins.RegistryOption expectedError error }{ { name: "NoPluginInCatalog", - plugins: []catalog.BuiltInPlugin{}, + opts: []testplugins.RegistryOption{testplugins.WithNoSystemInformation()}, expectedError: system_information.ErrNotConfigured, }, { name: "ValidPluginInCatalog", - plugins: []catalog.BuiltInPlugin{testplugins.NewSystemInformation()}, + opts: nil, expectedError: nil, }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - ps, psCfg := testutils.NewTestPlugins( - tt.plugins..., - ) - cfg := config.Config{ - Plugins: psCfg, - ContextModels: config.ContextModels{ - System: config.System{ - OptionalProperties: map[string]config.SystemProperty{ - SystemRole: {}, - SystemRoleID: {}, - SystemName: {}, - }, - }, + svcRegistry := testutils.NewTestPlugins(tt.opts...) + cfg := config.System{ + OptionalProperties: map[string]config.SystemProperty{ + SystemRole: {}, + SystemRoleID: {}, + SystemName: {}, }, } - svcRegistry, err := cmkpluginregistry.New(t.Context(), &cfg, cmkpluginregistry.WithBuiltInPlugins(ps)) - assert.NoError(t, err) - _, err = manager.NewSystemInformationManager(nil, svcRegistry, &cfg.ContextModels.System) + _, err := manager.NewSystemInformationManager(nil, svcRegistry, &cfg) if tt.expectedError != nil { assert.ErrorIs(t, err, tt.expectedError) } else { diff --git a/internal/manager/tenantconfigs.go b/internal/manager/tenantconfigs.go index 9d1f6f0f..d569114c 100644 --- a/internal/manager/tenantconfigs.go +++ b/internal/manager/tenantconfigs.go @@ -13,8 +13,7 @@ import ( "github.com/openkcm/cmk/internal/constants" "github.com/openkcm/cmk/internal/errs" "github.com/openkcm/cmk/internal/model" - cmkpluginregistry "github.com/openkcm/cmk/internal/pluginregistry" - servicewrapper "github.com/openkcm/cmk/internal/pluginregistry/service/wrapper" + serviceapi "github.com/openkcm/cmk/internal/pluginregistry/service/api" "github.com/openkcm/cmk/internal/repo" pluginHelpers "github.com/openkcm/cmk/utils/plugins" ) @@ -34,14 +33,14 @@ var ( type TenantConfigManager struct { repo repo.Repo - svcRegistry *cmkpluginregistry.Registry + svcRegistry serviceapi.Registry keystorePool *Pool cfg *config.Config } func NewTenantConfigManager( repo repo.Repo, - svcRegistry *cmkpluginregistry.Registry, + svcRegistry serviceapi.Registry, deploymentConfig *config.Config, ) *TenantConfigManager { return &TenantConfigManager{ @@ -283,20 +282,24 @@ func (m *TenantConfigManager) getTenantConfigsHyokKeystore() HYOKKeystore { return HYOKKeystore{} } - plugins := m.svcRegistry.LookupByType(servicewrapper.KeyManagementType) - if len(plugins) == 0 { + plugins, err := m.svcRegistry.KeyManagementList() + if err != nil || len(plugins) == 0 { return HYOKKeystore{} } providers := make([]string, 0) for _, plugin := range plugins { - if pluginHelpers.HasTag(plugin.Info().Tags(), constants.KeyTypeHYOK) { - providers = append(providers, plugin.Info().Name()) + if pluginHelpers.HasTag(plugin.ServiceInfo().Tags(), constants.KeyTypeHYOK) { + providers = append(providers, plugin.ServiceInfo().Name()) } } - return HYOKKeystore{Provider: providers, Allow: len(providers) > 0} + if len(providers) == 0 { + return HYOKKeystore{} + } + + return HYOKKeystore{Provider: providers, Allow: true} } func (m *TenantConfigManager) getKeystoreConfigFromPool(ctx context.Context) (*model.KeystoreConfig, error) { diff --git a/internal/manager/tenantconfigs_test.go b/internal/manager/tenantconfigs_test.go index 1e9c27f1..86e6f3e7 100644 --- a/internal/manager/tenantconfigs_test.go +++ b/internal/manager/tenantconfigs_test.go @@ -8,7 +8,6 @@ import ( "github.com/google/uuid" "github.com/openkcm/common-sdk/pkg/commoncfg" - "github.com/openkcm/plugin-sdk/pkg/catalog" "github.com/stretchr/testify/assert" multitenancy "github.com/bartventer/gorm-multitenancy/v8" @@ -19,7 +18,6 @@ import ( "github.com/openkcm/cmk/internal/constants" "github.com/openkcm/cmk/internal/manager" "github.com/openkcm/cmk/internal/model" - cmkpluginregistry "github.com/openkcm/cmk/internal/pluginregistry" "github.com/openkcm/cmk/internal/repo/sql" "github.com/openkcm/cmk/internal/testutils" "github.com/openkcm/cmk/internal/testutils/testplugins" @@ -28,7 +26,7 @@ import ( var ErrForced = errors.New("forced") -func SetupTenantConfigManager(t *testing.T, plugins []catalog.BuiltInPlugin) (*manager.TenantConfigManager, +func SetupTenantConfigManager(t *testing.T, opts ...testplugins.RegistryOption) (*manager.TenantConfigManager, *multitenancy.DB, string, ) { t.Helper() @@ -36,25 +34,21 @@ func SetupTenantConfigManager(t *testing.T, plugins []catalog.BuiltInPlugin) (*m db, tenants, _ := testutils.NewTestDB(t, testutils.TestDBConfig{}) r := sql.NewRepository(db) - ps, psCfg := testutils.NewTestPlugins(plugins...) + svcRegistry := testutils.NewTestPlugins(opts...) cfg := &config.Config{ - Plugins: psCfg, Certificates: config.Certificates{ RootCertURL: TestCertURL, ValidityDays: config.MinCertificateValidityDays, }, } - svcRegistry, err := cmkpluginregistry.New(t.Context(), cfg, cmkpluginregistry.WithBuiltInPlugins(ps)) - assert.NoError(t, err) - tenantManager := manager.NewTenantConfigManager(r, svcRegistry, cfg) return tenantManager, db, tenants[0] } // SetupTenantConfigManagerWithRole creates a test tenant with a specific role -func SetupTenantConfigManagerWithRole(t *testing.T, role string, plugins []catalog.BuiltInPlugin) (*manager.TenantConfigManager, +func SetupTenantConfigManagerWithRole(t *testing.T, role string, opts ...testplugins.RegistryOption) (*manager.TenantConfigManager, *multitenancy.DB, string, ) { t.Helper() @@ -62,18 +56,14 @@ func SetupTenantConfigManagerWithRole(t *testing.T, role string, plugins []catal db, tenants, _ := testutils.NewTestDB(t, testutils.TestDBConfig{}, testutils.WithTenantRole(model.TenantRole(role))) r := sql.NewRepository(db) - ps, psCfg := testutils.NewTestPlugins(plugins...) - cfg := config.Config{Plugins: psCfg} - svcRegistry, err := cmkpluginregistry.New(t.Context(), &cfg, cmkpluginregistry.WithBuiltInPlugins(ps)) - assert.NoError(t, err) - + svcRegistry := testutils.NewTestPlugins(opts...) tenantManager := manager.NewTenantConfigManager(r, svcRegistry, nil) return tenantManager, db, tenants[0] } func TestNewTenantConfigManager(t *testing.T) { - m, _, _ := SetupTenantConfigManager(t, nil) + m, _, _ := SetupTenantConfigManager(t) assert.NotNil(t, m) } @@ -82,7 +72,7 @@ func TestNewTenantConfigManager(t *testing.T) { func TestGetDefaultKeystore(t *testing.T) { t.Run("DefaultKeystore tenant config not exists, get from pool", func(t *testing.T) { // Arrange - configManager, db, tenant := SetupTenantConfigManager(t, nil) + configManager, db, tenant := SetupTenantConfigManager(t) // Add a keystore configuration to the pool ctx := testutils.CreateCtxWithTenant(tenant) r := sql.NewRepository(db) @@ -112,7 +102,7 @@ func TestGetDefaultKeystore(t *testing.T) { t.Run("Config Exists", func(t *testing.T) { // Arrange - configManager, db, tenant := SetupTenantConfigManager(t, nil) + configManager, db, tenant := SetupTenantConfigManager(t) tenantConfigRepo := sql.NewRepository(db) ksConfigJSON, err := json.Marshal(&model.KeystoreConfig{ @@ -150,7 +140,7 @@ func TestGetDefaultKeystore(t *testing.T) { func TestSetDefaultKeystore(t *testing.T) { t.Run("DefaultKeystore tenant config not exists, set default keystore", func(t *testing.T) { // Arrange - configManager, _, tenant := SetupTenantConfigManager(t, nil) + configManager, _, tenant := SetupTenantConfigManager(t) ctx := testutils.CreateCtxWithTenant(tenant) // Act @@ -173,7 +163,7 @@ func TestSetDefaultKeystore(t *testing.T) { t.Run("Update existing default keystore config", func(t *testing.T) { // Arrange - configManager, _, tenant := SetupTenantConfigManager(t, nil) + configManager, _, tenant := SetupTenantConfigManager(t) ctx := testutils.CreateCtxWithTenant(tenant) err := configManager.SetDefaultKeystore( ctx, @@ -231,17 +221,12 @@ func TestGetTenantConfigsHyokKeystore(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - cfg := config.Config{} - var ps []catalog.BuiltInPlugin - var psCfg []catalog.PluginConfig - if tt.enabledPlugins { - ps, psCfg = testutils.NewTestPlugins(testplugins.NewKeystoreOperator()) - } - - cfg.Plugins = psCfg - - svcRegistry, err := cmkpluginregistry.New(t.Context(), &cfg, cmkpluginregistry.WithBuiltInPlugins(ps)) - assert.NoError(t, err) + svcRegistry := testutils.NewTestPlugins( + testplugins.WithKeyManagement( + testplugins.Name, + testplugins.NewTestKeyManagement(tt.enabledPlugins, false), + ), + ) mgr := manager.NewTenantConfigManager(nil, svcRegistry, nil) @@ -253,14 +238,16 @@ func TestGetTenantConfigsHyokKeystore(t *testing.T) { func TestGetTenantsKeystore(t *testing.T) { t.Run("Should get tenant keystores with hyok", func(t *testing.T) { - m, _, tenant := SetupTenantConfigManager(t, []catalog.BuiltInPlugin{testplugins.NewKeystoreOperator()}) + m, _, tenant := SetupTenantConfigManager(t, + testplugins.WithKeyManagement(testplugins.Name, testplugins.NewTestKeyManagement(true, false))) res, err := m.GetTenantsKeystores(testutils.CreateCtxWithTenant(tenant)) assert.NoError(t, err) assert.NotEmpty(t, res.HYOK) }) t.Run("Should get tenant keystores with no hyok providers", func(t *testing.T) { - m, _, tenant := SetupTenantConfigManager(t, nil) + m, _, tenant := SetupTenantConfigManager(t, + testplugins.WithKeyManagement(testplugins.Name, testplugins.NewTestKeyManagement(false, true))) res, err := m.GetTenantsKeystores(testutils.CreateCtxWithTenant(tenant)) assert.NoError(t, err) assert.Empty(t, res.HYOK) @@ -268,14 +255,14 @@ func TestGetTenantsKeystore(t *testing.T) { }) t.Run("Should keep BYOK disabled when feature gate is missing", func(t *testing.T) { - m, _, tenant := SetupTenantConfigManager(t, nil) + m, _, tenant := SetupTenantConfigManager(t) res, err := m.GetTenantsKeystores(testutils.CreateCtxWithTenant(tenant)) assert.NoError(t, err) assert.False(t, res.AllowBYOK) }) t.Run("Should enable BYOK when allow-byok feature gate is true", func(t *testing.T) { - _, db, tenant := SetupTenantConfigManager(t, nil) + _, db, tenant := SetupTenantConfigManager(t) r := sql.NewRepository(db) cfg := &config.Config{ BaseConfig: commoncfg.BaseConfig{ @@ -302,7 +289,7 @@ func TestUpdateWorkflowConfig(t *testing.T) { } t.Run("Should update workflow config with partial update", func(t *testing.T) { - configManager, _, tenant := SetupTenantConfigManager(t, nil) + configManager, _, tenant := SetupTenantConfigManager(t) ctx := testutils.CreateCtxWithTenant(tenant) setupConfig(t, configManager, ctx, testutils.NewDefaultWorkflowConfig(true)) @@ -318,7 +305,7 @@ func TestUpdateWorkflowConfig(t *testing.T) { }) t.Run("Should update multiple fields at once", func(t *testing.T) { - configManager, _, tenant := SetupTenantConfigManager(t, nil) + configManager, _, tenant := SetupTenantConfigManager(t) ctx := testutils.CreateCtxWithTenant(tenant) setupConfig(t, configManager, ctx, testutils.NewDefaultWorkflowConfig(true)) @@ -336,7 +323,7 @@ func TestUpdateWorkflowConfig(t *testing.T) { }) t.Run("Should fail when retention period is less than minimum", func(t *testing.T) { - configManager, _, tenant := SetupTenantConfigManager(t, nil) + configManager, _, tenant := SetupTenantConfigManager(t) ctx := testutils.CreateCtxWithTenant(tenant) setupConfig(t, configManager, ctx, testutils.NewDefaultWorkflowConfig(true)) @@ -350,7 +337,7 @@ func TestUpdateWorkflowConfig(t *testing.T) { }) t.Run("Should create default config when updating non-existent config", func(t *testing.T) { - configManager, _, tenant := SetupTenantConfigManager(t, nil) + configManager, _, tenant := SetupTenantConfigManager(t) ctx := testutils.CreateCtxWithTenant(tenant) result, err := configManager.UpdateWorkflowConfig(ctx, &cmkapi.TenantWorkflowConfiguration{ @@ -363,7 +350,7 @@ func TestUpdateWorkflowConfig(t *testing.T) { }) t.Run("Should handle nil update gracefully", func(t *testing.T) { - configManager, _, tenant := SetupTenantConfigManager(t, nil) + configManager, _, tenant := SetupTenantConfigManager(t) ctx := testutils.CreateCtxWithTenant(tenant) setupConfig(t, configManager, ctx, testutils.NewDefaultWorkflowConfig(true)) @@ -395,9 +382,9 @@ func TestUpdateWorkflowConfig(t *testing.T) { var tenant string if tt.role == tenantpb.Role_ROLE_TEST.String() { - configManager, _, tenant = SetupTenantConfigManagerWithRole(t, tt.role, nil) + configManager, _, tenant = SetupTenantConfigManagerWithRole(t, tt.role) } else { - configManager, _, tenant = SetupTenantConfigManager(t, nil) + configManager, _, tenant = SetupTenantConfigManager(t) } ctx := testutils.CreateCtxWithTenant(tenant) @@ -420,7 +407,7 @@ func TestUpdateWorkflowConfig(t *testing.T) { } t.Run("ROLE_LIVE can update other fields without changing Enabled", func(t *testing.T) { - configManager, _, tenant := SetupTenantConfigManager(t, nil) + configManager, _, tenant := SetupTenantConfigManager(t) ctx := testutils.CreateCtxWithTenant(tenant) setupConfig(t, configManager, ctx, testutils.NewDefaultWorkflowConfig(true)) @@ -438,7 +425,7 @@ func TestUpdateWorkflowConfig(t *testing.T) { t.Run("ROLE_TEST can update Enabled with other fields simultaneously", func(t *testing.T) { configManager, _, tenant := SetupTenantConfigManagerWithRole(t, - tenantpb.Role_ROLE_TEST.String(), nil) + tenantpb.Role_ROLE_TEST.String()) ctx := testutils.CreateCtxWithTenant(tenant) setupConfig(t, configManager, ctx, testutils.NewDefaultWorkflowConfig(false)) @@ -456,7 +443,7 @@ func TestUpdateWorkflowConfig(t *testing.T) { }) t.Run("Setting same Enabled value does not trigger role validation", func(t *testing.T) { - configManager, _, tenant := SetupTenantConfigManager(t, nil) + configManager, _, tenant := SetupTenantConfigManager(t) ctx := testutils.CreateCtxWithTenant(tenant) setupConfig(t, configManager, ctx, testutils.NewDefaultWorkflowConfig(true)) diff --git a/internal/manager/workflow.go b/internal/manager/workflow.go index 2a6e7501..55fe4b21 100644 --- a/internal/manager/workflow.go +++ b/internal/manager/workflow.go @@ -24,7 +24,7 @@ import ( "github.com/openkcm/cmk/internal/model" "github.com/openkcm/cmk/internal/notifier" wn "github.com/openkcm/cmk/internal/notifier/workflow" - cmkpluginregistry "github.com/openkcm/cmk/internal/pluginregistry" + serviceapi "github.com/openkcm/cmk/internal/pluginregistry/service/api" "github.com/openkcm/cmk/internal/pluginregistry/service/api/identitymanagement" "github.com/openkcm/cmk/internal/repo" wf "github.com/openkcm/cmk/internal/workflow" @@ -85,13 +85,13 @@ type WorkflowManager struct { userManager User asyncClient async.Client tenantConfigManager *TenantConfigManager - svcRegistry *cmkpluginregistry.Registry + svcRegistry serviceapi.Registry cfg *config.Config } func NewWorkflowManager( repository repo.Repo, - svcRegistry *cmkpluginregistry.Registry, + svcRegistry serviceapi.Registry, keyManager *KeyManager, keyConfigurationManager *KeyConfigManager, systemManager *SystemManager, diff --git a/internal/manager/workflow_test.go b/internal/manager/workflow_test.go index 4bf4de38..1984f366 100644 --- a/internal/manager/workflow_test.go +++ b/internal/manager/workflow_test.go @@ -19,11 +19,9 @@ import ( "github.com/openkcm/cmk/internal/errs" "github.com/openkcm/cmk/internal/manager" "github.com/openkcm/cmk/internal/model" - cmkpluginregistry "github.com/openkcm/cmk/internal/pluginregistry" "github.com/openkcm/cmk/internal/repo" "github.com/openkcm/cmk/internal/repo/sql" "github.com/openkcm/cmk/internal/testutils" - "github.com/openkcm/cmk/internal/testutils/testplugins" "github.com/openkcm/cmk/internal/workflow" cmkcontext "github.com/openkcm/cmk/utils/context" "github.com/openkcm/cmk/utils/ptr" @@ -58,12 +56,9 @@ func SetupWorkflowManager( r := sql.NewRepository(db) - ps, psCfg := testutils.NewTestPlugins(testplugins.NewIdentityManagement()) + svcRegistry := testutils.NewTestPlugins() - cfg.Plugins = psCfg - - svcRegistry, err := cmkpluginregistry.New(t.Context(), cfg, cmkpluginregistry.WithBuiltInPlugins(ps)) - assert.NoError(t, err) + cfg.Plugins = nil certManager := manager.NewCertificateManager(t.Context(), r, svcRegistry, cfg) tenantConfigManager := manager.NewTenantConfigManager(r, svcRegistry, nil) diff --git a/internal/notifier/client/client.go b/internal/notifier/client/client.go index f27d55d2..aaa7aaf4 100644 --- a/internal/notifier/client/client.go +++ b/internal/notifier/client/client.go @@ -5,7 +5,7 @@ import ( "errors" "github.com/openkcm/cmk/internal/log" - cmkpluginregistry "github.com/openkcm/cmk/internal/pluginregistry" + serviceapi "github.com/openkcm/cmk/internal/pluginregistry/service/api" "github.com/openkcm/cmk/internal/pluginregistry/service/api/notification" ) @@ -25,7 +25,7 @@ type Client struct { func New( ctx context.Context, - svcRegistry *cmkpluginregistry.Registry, + svcRegistry serviceapi.Registry, ) (*Client, error) { svc, err := svcRegistry.Notification() if err != nil { diff --git a/internal/notifier/client/client_test.go b/internal/notifier/client/client_test.go index fd7ee604..52c93076 100644 --- a/internal/notifier/client/client_test.go +++ b/internal/notifier/client/client_test.go @@ -7,12 +7,9 @@ import ( "github.com/openkcm/plugin-sdk/api" "github.com/stretchr/testify/assert" - "github.com/openkcm/cmk/internal/config" "github.com/openkcm/cmk/internal/notifier/client" - cmkpluginregistry "github.com/openkcm/cmk/internal/pluginregistry" "github.com/openkcm/cmk/internal/pluginregistry/service/api/notification" "github.com/openkcm/cmk/internal/testutils" - "github.com/openkcm/cmk/internal/testutils/testplugins" ) type NotificationMock struct { @@ -44,27 +41,18 @@ func TestCreateNotificationManager(t *testing.T) { Body: "Test Notification", } - ps, psCfg := testutils.NewTestPlugins(testplugins.NewNotification()) - cfg := config.Config{Plugins: psCfg} - svcRegistry, err := cmkpluginregistry.New(t.Context(), &cfg, cmkpluginregistry.WithBuiltInPlugins(ps)) - assert.NoError(t, err) - + svcRegistry := testutils.NewTestPlugins() defer svcRegistry.Close() t.Run("Success", func(t *testing.T) { - // Setup - c, err := client.New(t.Context(), svcRegistry) assert.NoError(t, err) c.SetService(NotificationMock{}) - // Act err = c.CreateNotification(t.Context(), msg) - // Verify assert.NoError(t, err) }) t.Run("Failure", func(t *testing.T) { - // Setup c, err := client.New(t.Context(), svcRegistry) assert.NoError(t, err) c.SetService(NotificationMock{ @@ -75,10 +63,7 @@ func TestCreateNotificationManager(t *testing.T) { return nil, assert.AnError }, }) - // Act err = c.CreateNotification(t.Context(), msg) - - // Verify assert.Error(t, err) }) } diff --git a/internal/operator/operator_test.go b/internal/operator/operator_test.go index c3ae270a..257e9ba5 100644 --- a/internal/operator/operator_test.go +++ b/internal/operator/operator_test.go @@ -38,14 +38,13 @@ import ( "github.com/openkcm/cmk/internal/manager" "github.com/openkcm/cmk/internal/model" "github.com/openkcm/cmk/internal/operator" - cmkpluginregistry "github.com/openkcm/cmk/internal/pluginregistry" + serviceapi "github.com/openkcm/cmk/internal/pluginregistry/service/api" "github.com/openkcm/cmk/internal/repo" "github.com/openkcm/cmk/internal/repo/sql" "github.com/openkcm/cmk/internal/testutils" mockClient "github.com/openkcm/cmk/internal/testutils/clients" "github.com/openkcm/cmk/internal/testutils/clients/registry" sessionmanager "github.com/openkcm/cmk/internal/testutils/clients/session-manager" - "github.com/openkcm/cmk/internal/testutils/testplugins" integrationutils "github.com/openkcm/cmk/test/integration/integration_utils" tmdb "github.com/openkcm/cmk/utils/base62" cmkcontext "github.com/openkcm/cmk/utils/context" @@ -84,7 +83,7 @@ func createManagers( t *testing.T, dbCon *multitenancy.DB, cfg *config.Config, - svcRegistry *cmkpluginregistry.Registry, + svcRegistry serviceapi.Registry, ) (*manager.TenantManager, *manager.GroupManager) { t.Helper() @@ -174,10 +173,7 @@ func TestNewTenantOperator(t *testing.T) { dbConn := &multitenancy.DB{} fts := tenants.NewFakeTenantService() - ps, psCfg := testutils.NewTestPlugins(testplugins.NewIdentityManagement()) - cfg := &config.Config{ - Plugins: psCfg, Database: testutils.TestDB, } @@ -197,8 +193,7 @@ func TestNewTenantOperator(t *testing.T) { sessionmanager.NewMockService(sessionmanager.NewFakeSessionManagerClient()), ) - svcRegistry, err := cmkpluginregistry.New(t.Context(), cfg, cmkpluginregistry.WithBuiltInPlugins(ps)) - assert.NoError(t, err) + svcRegistry := testutils.NewTestPlugins() tenantManager, groupManager := createManagers(t, dbConn, cfg, svcRegistry) @@ -717,14 +712,11 @@ func TestHandleBlockTenant(t *testing.T) { taskType := tenantgrpc.ACTION_ACTION_BLOCK_TENANT.String() - ps, psCfg := testutils.NewTestPlugins(testplugins.NewIdentityManagement()) cfg := &config.Config{ - Plugins: psCfg, Database: testutils.TestDB, } - svcRegistry, err := cmkpluginregistry.New(t.Context(), cfg, cmkpluginregistry.WithBuiltInPlugins(ps)) - assert.NoError(t, err) + svcRegistry := testutils.NewTestPlugins() tenantManager, groupManager := createManagers(t, unusedDB, cfg, svcRegistry) @@ -847,14 +839,11 @@ func TestHandleUnblockTenant(t *testing.T) { taskType := tenantgrpc.ACTION_ACTION_UNBLOCK_TENANT.String() - ps, psCfg := testutils.NewTestPlugins(testplugins.NewIdentityManagement()) cfg := &config.Config{ - Plugins: psCfg, Database: testutils.TestDB, } - svcRegistry, err := cmkpluginregistry.New(t.Context(), cfg, cmkpluginregistry.WithBuiltInPlugins(ps)) - assert.NoError(t, err) + svcRegistry := testutils.NewTestPlugins() tenantManager, groupManager := createManagers(t, unusedDB, cfg, svcRegistry) @@ -974,14 +963,11 @@ func TestHandleTerminateTenant_RemoveAuth(t *testing.T) { unusedDB := &multitenancy.DB{} _, clientCon := testutils.NewGRPCSuite(t) unusedRegistryClient := tenantgrpc.NewServiceClient(clientCon) - ps, psCfg := testutils.NewTestPlugins(testplugins.NewIdentityManagement()) cfg := &config.Config{ - Plugins: psCfg, Database: testutils.TestDB, } - svcRegistry, err := cmkpluginregistry.New(t.Context(), cfg, cmkpluginregistry.WithBuiltInPlugins(ps)) - assert.NoError(t, err) + svcRegistry := testutils.NewTestPlugins() _, groupManager := createManagers(t, unusedDB, cfg, svcRegistry) mockTenantManager := &MockTenantManager{} @@ -1102,14 +1088,11 @@ func TestHandleTerminateTenant(t *testing.T) { unusedDB := &multitenancy.DB{} _, clientCon := testutils.NewGRPCSuite(t) unusedRegistryClient := tenantgrpc.NewServiceClient(clientCon) - ps, psCfg := testutils.NewTestPlugins(testplugins.NewIdentityManagement()) cfg := &config.Config{ - Plugins: psCfg, Database: testutils.TestDB, } - svcRegistry, err := cmkpluginregistry.New(t.Context(), cfg, cmkpluginregistry.WithBuiltInPlugins(ps)) - assert.NoError(t, err) + svcRegistry := testutils.NewTestPlugins() sessionManagerClient := sessionmanager.NewFakeSessionManagerClient() sessionManagerClient.MockRemoveOIDCMapping = func( @@ -1434,9 +1417,7 @@ func TestTenantOperatorTracing(t *testing.T) { }, })) - ps, psCfg := testutils.NewTestPlugins(testplugins.NewIdentityManagement()) cfg := &config.Config{ - Plugins: psCfg, Database: dbCfg, BaseConfig: commoncfg.BaseConfig{ Application: commoncfg.Application{ @@ -1458,8 +1439,7 @@ func TestTenantOperatorTracing(t *testing.T) { sessionmanager.NewMockService(sessionManagerClient), ) - svcRegistry, err := cmkpluginregistry.New(t.Context(), cfg, cmkpluginregistry.WithBuiltInPlugins(ps)) - assert.NoError(t, err) + svcRegistry := testutils.NewTestPlugins() tenantManager, groupManager := createManagers(t, dbConn, cfg, svcRegistry) op, err := operator.NewTenantOperator(dbConn, cfg, target, clientFactory, @@ -1536,9 +1516,7 @@ func newTestOperator(t *testing.T, opts ...testutils.TestDBConfigOpt) TestConfig }, ) - ps, psCfg := testutils.NewTestPlugins(testplugins.NewIdentityManagement()) cfg := &config.Config{ - Plugins: psCfg, Database: cfgDB, } @@ -1553,8 +1531,7 @@ func newTestOperator(t *testing.T, opts ...testutils.TestDBConfigOpt) TestConfig sessionmanager.NewMockService(sessionManagerClient), ) - svcRegistry, err := cmkpluginregistry.New(t.Context(), cfg, cmkpluginregistry.WithBuiltInPlugins(ps)) - assert.NoError(t, err) + svcRegistry := testutils.NewTestPlugins() tenantManager, groupManager := createManagers(t, multitenancyDB, cfg, svcRegistry) tenantOperator, err := operator.NewTenantOperator( diff --git a/internal/operator/probe_test.go b/internal/operator/probe_test.go index 73a9d78f..65587a2a 100644 --- a/internal/operator/probe_test.go +++ b/internal/operator/probe_test.go @@ -14,11 +14,9 @@ import ( "github.com/openkcm/cmk/internal/manager" "github.com/openkcm/cmk/internal/model" "github.com/openkcm/cmk/internal/operator" - cmkpluginregistry "github.com/openkcm/cmk/internal/pluginregistry" "github.com/openkcm/cmk/internal/repo" "github.com/openkcm/cmk/internal/repo/sql" "github.com/openkcm/cmk/internal/testutils" - "github.com/openkcm/cmk/internal/testutils/testplugins" cmkcontext "github.com/openkcm/cmk/utils/context" ) @@ -37,15 +35,11 @@ func SetupProbeTest(t *testing.T) (*manager.GroupManager, *manager.TenantManager dbRepository := sql.NewRepository(db) - ps, psCfg := testutils.NewTestPlugins(testplugins.NewIdentityManagement()) - cfg := &config.Config{ - Plugins: psCfg, Database: cfgDB, } - svcRegistry, err := cmkpluginregistry.New(t.Context(), cfg, cmkpluginregistry.WithBuiltInPlugins(ps)) - assert.NoError(t, err) + var svcRegistry = testutils.NewTestPlugins() tm, gm := createManagers(t, db, cfg, svcRegistry) diff --git a/internal/pluginregistry/plugin_registry_test.go b/internal/pluginregistry/plugin_registry_test.go index a375c22b..353757e2 100644 --- a/internal/pluginregistry/plugin_registry_test.go +++ b/internal/pluginregistry/plugin_registry_test.go @@ -12,7 +12,6 @@ import ( "github.com/openkcm/cmk/internal/config" cmkpluginregistry "github.com/openkcm/cmk/internal/pluginregistry" "github.com/openkcm/cmk/internal/testutils" - "github.com/openkcm/cmk/internal/testutils/testplugins" ) func TestNew(t *testing.T) { @@ -77,15 +76,7 @@ func TestNew(t *testing.T) { } t.Run("Should use custom builtin", func(t *testing.T) { - ps, pscfg := testutils.NewTestPlugins(testplugins.NewCertificateIssuer()) - svcRegistry, err := cmkpluginregistry.New( - t.Context(), - &config.Config{ - Plugins: pscfg, - }, - cmkpluginregistry.WithBuiltInPlugins(ps), - ) - require.NoError(t, err) + svcRegistry := testutils.NewTestPlugins() res, err := svcRegistry.CertificateIssuer() require.NoError(t, err) require.Equal(t, "TEST", res.ServiceInfo().Name()) diff --git a/internal/testutils/api.go b/internal/testutils/api.go index 3b77460c..adaf2c9a 100644 --- a/internal/testutils/api.go +++ b/internal/testutils/api.go @@ -14,7 +14,6 @@ import ( "github.com/getkin/kin-openapi/openapi3filter" "github.com/openkcm/common-sdk/pkg/commoncfg" "github.com/openkcm/common-sdk/pkg/commongrpc" - "github.com/openkcm/plugin-sdk/pkg/catalog" "github.com/stretchr/testify/assert" multitenancy "github.com/bartventer/gorm-multitenancy/v8" @@ -31,7 +30,7 @@ import ( "github.com/openkcm/cmk/internal/db" "github.com/openkcm/cmk/internal/handlers" "github.com/openkcm/cmk/internal/middleware" - cmkpluginregistry "github.com/openkcm/cmk/internal/pluginregistry" + serviceapi "github.com/openkcm/cmk/internal/pluginregistry/service/api" "github.com/openkcm/cmk/internal/repo/sql" ) @@ -40,9 +39,9 @@ const TestCertURL = "https://aia.pki.co.test.com/aia/TEST%20Cloud%20Root%20CA.cr const TestHostPrefix = "https://kms.test/cmk/v1/" type TestAPIServerConfig struct { - Plugins []catalog.BuiltInPlugin // Plugins only set if needed - GRPCCon *commongrpc.DynamicClientConn // GRPCClient only set if needed - Config config.Config + Registry serviceapi.Registry // Registry is optional; defaults to testplugins.NewRegistry() + GRPCCon *commongrpc.DynamicClientConn // GRPCClient only set if needed + Config config.Config } // NewAPIServer creates a new API server with the given database connection @@ -55,8 +54,10 @@ func NewAPIServer( cfg := testCfg.Config - ps, psCfg := NewTestPlugins(testCfg.Plugins...) - cfg.Plugins = psCfg + svcRegistry := testCfg.Registry + if svcRegistry == nil { + svcRegistry = NewTestPlugins() + } cfg.Certificates.RootCertURL = TestCertURL if cfg.Database == (config.Database{}) { @@ -100,9 +101,6 @@ func NewAPIServer( authzRepo := authz_repo.NewAuthzRepo(r, authzRepoLoader) - svcRegistry, err := cmkpluginregistry.New(tb.Context(), &cfg, cmkpluginregistry.WithBuiltInPlugins(ps)) - assert.NoError(tb, err) - controller := cmk.NewAPIController(tb.Context(), authzRepo, &cfg, factory, migrator, svcRegistry, authzAPILoader) return startAPIServer(tb, controller) diff --git a/internal/testutils/plugin.go b/internal/testutils/plugin.go index 7ff596a5..bfb9dca3 100644 --- a/internal/testutils/plugin.go +++ b/internal/testutils/plugin.go @@ -1,53 +1,15 @@ package testutils import ( - plugincatalog "github.com/openkcm/plugin-sdk/pkg/catalog" - - servicewrapper "github.com/openkcm/cmk/internal/pluginregistry/service/wrapper" + serviceapi "github.com/openkcm/cmk/internal/pluginregistry/service/api" + "github.com/openkcm/cmk/internal/testutils/testplugins" ) -type PluginConfig struct { - Tags []string - YamlConfiguration string -} - -// map[pluginType]tags -var pluginTags = map[string]PluginConfig{ - servicewrapper.IdentityManagementType: {}, - servicewrapper.CertificateIssuerType: {}, - servicewrapper.NotificationType: {}, - servicewrapper.SystemInformationType: {}, - servicewrapper.KeystoreManagementType: { - Tags: []string{"keystore_provider"}, - }, - servicewrapper.KeyManagementType: { - Tags: []string{"hyok", "default_keystore"}, - }, -} - -var ValidKeystoreAccountInfo = map[string]string{ - "AccountID": "111122223333", - "UserID": "123456789012", -} - -func NewTestPlugins(plugins ...plugincatalog.BuiltInPlugin) ( - []plugincatalog.BuiltInPlugin, - []plugincatalog.PluginConfig, -) { - pluginCfgs := make([]plugincatalog.PluginConfig, 0, len(plugins)) - for _, p := range plugins { - pluginCfg := plugincatalog.PluginConfig{ - Name: p.Name(), - Type: p.Type(), - Tags: p.Tags(), - } - - values, ok := pluginTags[p.Type()] - if ok { - pluginCfg.Tags = values.Tags - } +// ValidKeystoreAccountInfo is test account data used by the keystore operator. +var ValidKeystoreAccountInfo = testplugins.ValidKeystoreAccountInfo - pluginCfgs = append(pluginCfgs, pluginCfg) - } - return plugins, pluginCfgs +// NewTestPlugins returns a serviceapi.Registry pre-configured with default test +// service implementations. Pass RegistryOptions to override specific services. +func NewTestPlugins(opts ...testplugins.RegistryOption) serviceapi.Registry { + return testplugins.NewRegistry(opts...) } diff --git a/internal/testutils/testplugins/certificate_issuer.go b/internal/testutils/testplugins/certificate_issuer.go index 5232f794..94a74843 100644 --- a/internal/testutils/testplugins/certificate_issuer.go +++ b/internal/testutils/testplugins/certificate_issuer.go @@ -2,40 +2,30 @@ package testplugins import ( "context" - "log/slog" - "github.com/openkcm/plugin-sdk/pkg/catalog" + "github.com/openkcm/plugin-sdk/api" - certificateissuerv1 "github.com/openkcm/plugin-sdk/proto/plugin/certificate_issuer/v1" - configv1 "github.com/openkcm/plugin-sdk/proto/service/common/config/v1" + "github.com/openkcm/cmk/internal/pluginregistry/service/api/certificateissuer" + servicewrapper "github.com/openkcm/cmk/internal/pluginregistry/service/wrapper" ) -type CertificateIssuer struct { - certificateissuerv1.UnsafeCertificateIssuerServiceServer - configv1.UnsafeConfigServer -} +type TestCertificateIssuer struct{} -func NewCertificateIssuer() catalog.BuiltInPlugin { - p := &CertificateIssuer{} - return catalog.MakeBuiltIn( - Name, - certificateissuerv1.CertificateIssuerServicePluginServer(p), - configv1.ConfigServiceServer(p), - ) -} +var _ certificateissuer.CertificateIssuer = (*TestCertificateIssuer)(nil) -func (p *CertificateIssuer) Configure( - _ context.Context, - req *configv1.ConfigureRequest, -) (*configv1.ConfigureResponse, error) { - slog.Info("Configuring plugin") +func NewTestCertificateIssuer() *TestCertificateIssuer { + return &TestCertificateIssuer{} +} - return &configv1.ConfigureResponse{}, nil +func (s *TestCertificateIssuer) ServiceInfo() api.Info { + return testInfo{ + configuredType: servicewrapper.CertificateIssuerServiceType, + } } -func (p *CertificateIssuer) GetCertificate( +func (s *TestCertificateIssuer) IssueCertificate( _ context.Context, - _ *certificateissuerv1.GetCertificateRequest, -) (*certificateissuerv1.GetCertificateResponse, error) { - return &certificateissuerv1.GetCertificateResponse{}, nil + _ *certificateissuer.IssueCertificateRequest, +) (*certificateissuer.IssueCertificateResponse, error) { + return &certificateissuer.IssueCertificateResponse{}, nil } diff --git a/internal/testutils/testplugins/common.go b/internal/testutils/testplugins/common.go index 989c5cd2..10effc4e 100644 --- a/internal/testutils/testplugins/common.go +++ b/internal/testutils/testplugins/common.go @@ -1,3 +1,8 @@ package testplugins const Name = "TEST" + +var ValidKeystoreAccountInfo = map[string]string{ + "AccountID": "111122223333", + "UserID": "123456789012", +} diff --git a/internal/testutils/testplugins/identity_management.go b/internal/testutils/testplugins/identity_management.go index 2b0c1c38..6427833b 100644 --- a/internal/testutils/testplugins/identity_management.go +++ b/internal/testutils/testplugins/identity_management.go @@ -2,14 +2,13 @@ package testplugins import ( "context" - "log/slog" - "github.com/openkcm/plugin-sdk/pkg/catalog" + "github.com/openkcm/plugin-sdk/api" "google.golang.org/grpc/codes" "google.golang.org/grpc/status" - idmangv1 "github.com/openkcm/plugin-sdk/proto/plugin/identity_management/v1" - configv1 "github.com/openkcm/plugin-sdk/proto/service/common/config/v1" + "github.com/openkcm/cmk/internal/pluginregistry/service/api/identitymanagement" + servicewrapper "github.com/openkcm/cmk/internal/pluginregistry/service/wrapper" ) type IdentityManagementUserRef struct { @@ -33,85 +32,71 @@ var IdentityManagementGroupMembership = map[string][]IdentityManagementUserRef{ }, } -type IdentityManagement struct { - configv1.UnsafeConfigServer - idmangv1.UnsafeIdentityManagementServiceServer -} +type TestIdentityManagement struct{} -func NewIdentityManagement() catalog.BuiltInPlugin { - p := &IdentityManagement{} - return catalog.MakeBuiltIn( - Name, - idmangv1.IdentityManagementServicePluginServer(p), - configv1.ConfigServiceServer(p), - ) -} +var _ identitymanagement.IdentityManagement = (*TestIdentityManagement)(nil) -func (p *IdentityManagement) GetUser( - _ context.Context, - _ *idmangv1.GetUserRequest, -) (*idmangv1.GetUserResponse, error) { - return &idmangv1.GetUserResponse{}, nil +func NewTestIdentityManagement() *TestIdentityManagement { + return &TestIdentityManagement{} } -func (p *IdentityManagement) Configure( - _ context.Context, - _ *configv1.ConfigureRequest, -) (*configv1.ConfigureResponse, error) { - slog.Info("Configuring plugin") - - return &configv1.ConfigureResponse{}, nil +func (s *TestIdentityManagement) ServiceInfo() api.Info { + return testInfo{ + configuredType: servicewrapper.IdentityManagementServiceType, + } } -func (p *IdentityManagement) GetUsersForGroup( +func (s *TestIdentityManagement) GetGroup( _ context.Context, - req *idmangv1.GetUsersForGroupRequest, -) (*idmangv1.GetUsersForGroupResponse, error) { - users, ok := IdentityManagementGroupMembership[req.GetGroupId()] - respUsers := make([]*idmangv1.User, 0, len(users)) - - if ok { - for _, u := range users { - respUsers = append(respUsers, &idmangv1.User{ - Id: u.ID, - Email: u.Email, - }) - } - - return &idmangv1.GetUsersForGroupResponse{ - Users: respUsers, + req *identitymanagement.GetGroupRequest, +) (*identitymanagement.GetGroupResponse, error) { + if g, ok := IdentityManagementGroups[req.GroupName]; ok { + return &identitymanagement.GetGroupResponse{ + Group: identitymanagement.Group{ + ID: g, + Name: req.GroupName, + }, }, nil } - - return &idmangv1.GetUsersForGroupResponse{}, nil + return nil, status.New(codes.NotFound, "group does not exist").Err() } -func (p *IdentityManagement) GetGroupsForUser( +func (s *TestIdentityManagement) GetUser( _ context.Context, - _ *idmangv1.GetGroupsForUserRequest, -) (*idmangv1.GetGroupsForUserResponse, error) { - return &idmangv1.GetGroupsForUserResponse{}, nil + _ *identitymanagement.GetUserRequest, +) (*identitymanagement.GetUserResponse, error) { + return &identitymanagement.GetUserResponse{}, nil } -func (p *IdentityManagement) GetAllGroups( +func (s *TestIdentityManagement) ListGroups( _ context.Context, - _ *idmangv1.GetAllGroupsRequest, -) (*idmangv1.GetAllGroupsResponse, error) { - return &idmangv1.GetAllGroupsResponse{}, nil + _ *identitymanagement.ListGroupsRequest, +) (*identitymanagement.ListGroupsResponse, error) { + return &identitymanagement.ListGroupsResponse{}, nil } -func (p *IdentityManagement) GetGroup( +func (s *TestIdentityManagement) ListGroupUsers( _ context.Context, - req *idmangv1.GetGroupRequest, -) (*idmangv1.GetGroupResponse, error) { - if g, ok := IdentityManagementGroups[req.GetGroupName()]; ok { - return &idmangv1.GetGroupResponse{ - Group: &idmangv1.Group{ - Id: g, - Name: req.GetGroupName(), - }, - }, nil + req *identitymanagement.ListGroupUsersRequest, +) (*identitymanagement.ListGroupUsersResponse, error) { + members, ok := IdentityManagementGroupMembership[req.GroupID] + if !ok { + return &identitymanagement.ListGroupUsersResponse{}, nil } - return nil, status.New(codes.NotFound, "group does not exist").Err() + users := make([]identitymanagement.User, 0, len(members)) + for _, u := range members { + users = append(users, identitymanagement.User{ + ID: u.ID, + Email: u.Email, + }) + } + return &identitymanagement.ListGroupUsersResponse{Users: users}, nil +} + +func (s *TestIdentityManagement) ListUserGroups( + _ context.Context, + _ *identitymanagement.ListUserGroupsRequest, +) (*identitymanagement.ListUserGroupsResponse, error) { + return &identitymanagement.ListUserGroupsResponse{}, nil } diff --git a/internal/testutils/testplugins/info.go b/internal/testutils/testplugins/info.go new file mode 100644 index 00000000..2e2b6e12 --- /dev/null +++ b/internal/testutils/testplugins/info.go @@ -0,0 +1,19 @@ +package testplugins + +import ( + "github.com/openkcm/plugin-sdk/api" +) + +// testInfo implements api.Info for test service implementations. +type testInfo struct { + configuredTags []string + configuredType string +} + +func (testInfo) Name() string { return Name } +func (t testInfo) Type() string { return t.configuredType } +func (t testInfo) Tags() []string { return t.configuredTags } +func (testInfo) Build() string { return "{}" } +func (testInfo) Version() uint { return 1 } + +var _ api.Info = testInfo{} diff --git a/internal/testutils/testplugins/key_management.go b/internal/testutils/testplugins/key_management.go new file mode 100644 index 00000000..861d69fb --- /dev/null +++ b/internal/testutils/testplugins/key_management.go @@ -0,0 +1,265 @@ +package testplugins + +import ( + "context" + "encoding/json" + "errors" + "time" + + "github.com/google/uuid" + "github.com/openkcm/plugin-sdk/api" + "google.golang.org/protobuf/encoding/protojson" + "google.golang.org/protobuf/types/known/structpb" + + "github.com/openkcm/cmk/internal/errs" + "github.com/openkcm/cmk/internal/pluginregistry/service/api/keymanagement" + servicewrapper "github.com/openkcm/cmk/internal/pluginregistry/service/wrapper" +) + +var ( + EnabledKeyStatus = "ENABLED" + DisabledKeyStatus = "DISABLED" + PendingImportKeyStatus = "PENDING_IMPORT" + PendingDeletionKeyStatus = "PENDING_DELETION" + + ErrKeyIDIsNil = errors.New("keyId is nil") + ErrTransformAccessData = errors.New("failed to transform access data") +) + +const importParamsValidityHours = 24 + +type KeyRecord struct { + KeyID string `gorm:"primaryKey;column:key_id"` + Status string + VersionID string + RotationTime string // RFC3339 format +} + +var InitialKeys = map[string]KeyRecord{ + "mock-key/11111111": {Status: EnabledKeyStatus}, + "mock-key/22222222": {Status: EnabledKeyStatus}, + "mock-key/33333333": {Status: EnabledKeyStatus}, +} + +type TestKeyManagement struct { + KeyStore map[string]*KeyRecord + IsHYOK bool + IsDefault bool +} + +var _ keymanagement.KeyManagement = (*TestKeyManagement)(nil) + +func NewTestKeyManagement(isHYOK, isDefault bool) *TestKeyManagement { + km := &TestKeyManagement{ + KeyStore: make(map[string]*KeyRecord), + IsHYOK: isHYOK, + IsDefault: isDefault, + } + for keyID, record := range InitialKeys { + km.HandleKeyRecord(keyID, record.Status) + } + return km +} + +func (s *TestKeyManagement) ServiceInfo() api.Info { + var tags []string + if s.IsHYOK { + tags = append(tags, "hyok") + } + if s.IsDefault { + tags = append(tags, "default_keystore") + } + + return testInfo{ + configuredType: servicewrapper.KeyManagementType, + configuredTags: tags, + } +} + +func (s *TestKeyManagement) HandleKeyRecord(keyID, status string) { + record, exists := s.KeyStore[keyID] + if !exists { + record = &KeyRecord{KeyID: keyID, Status: status} + s.KeyStore[keyID] = record + } + record.Status = status +} + +// SetKeyVersionInfo sets version and rotation metadata for a key, mirroring the +// KeystoreOperator helper used in tests. +func (s *TestKeyManagement) SetKeyVersionInfo(keyID, versionID, rotationTime string) { + record, exists := s.KeyStore[keyID] + if !exists { + record = &KeyRecord{KeyID: keyID, Status: EnabledKeyStatus} + s.KeyStore[keyID] = record + } + record.VersionID = versionID + record.RotationTime = rotationTime +} + +func (s *TestKeyManagement) GetKey( + _ context.Context, + req *keymanagement.GetKeyRequest, +) (*keymanagement.GetKeyResponse, error) { + cfg := req.Parameters.Config.Values + if cfg["authType"] == "AUTH_TYPE_CERTIFICATE" && + (cfg["AccountID"] != ValidKeystoreAccountInfo["AccountID"] || + cfg["UserID"] != ValidKeystoreAccountInfo["UserID"]) { + return nil, keymanagement.ErrProviderAuthenticationFailed + } + + record, exists := s.KeyStore[req.Parameters.KeyID] + if !exists { + return nil, keymanagement.ErrHYOKKeyNotFound + } + + resp := &keymanagement.GetKeyResponse{ + KeyAlgorithm: keymanagement.AES256, + Status: record.Status, + } + + if record.VersionID != "" { + resp.LatestKeyVersionId = record.VersionID + } + + if record.RotationTime != "" { + t, err := time.Parse(time.RFC3339Nano, record.RotationTime) + if err != nil { + t, err = time.Parse(time.RFC3339, record.RotationTime) + } + if err == nil { + resp.RotationTime = &t + } + } + + return resp, nil +} + +func (s *TestKeyManagement) CreateKey( + _ context.Context, + req *keymanagement.CreateKeyRequest, +) (*keymanagement.CreateKeyResponse, error) { + st := EnabledKeyStatus + if req.KeyType == keymanagement.BYOK { + st = PendingImportKeyStatus + } + + keyID := "mock-key/" + uuid.NewString() + s.HandleKeyRecord(keyID, st) + + return &keymanagement.CreateKeyResponse{ + KeyID: keyID, + Status: st, + }, nil +} + +func (s *TestKeyManagement) DeleteKey( + _ context.Context, + req *keymanagement.DeleteKeyRequest, +) (*keymanagement.DeleteKeyResponse, error) { + if req != nil && req.Parameters.KeyID != "" { + s.HandleKeyRecord(req.Parameters.KeyID, PendingDeletionKeyStatus) + } + return &keymanagement.DeleteKeyResponse{}, nil +} + +func (s *TestKeyManagement) EnableKey( + _ context.Context, + req *keymanagement.EnableKeyRequest, +) (*keymanagement.EnableKeyResponse, error) { + if req.Parameters.KeyID == "" { + return nil, ErrKeyIDIsNil + } + s.HandleKeyRecord(req.Parameters.KeyID, EnabledKeyStatus) + return &keymanagement.EnableKeyResponse{}, nil +} + +func (s *TestKeyManagement) DisableKey( + _ context.Context, + req *keymanagement.DisableKeyRequest, +) (*keymanagement.DisableKeyResponse, error) { + if req.Parameters.KeyID == "" { + return nil, ErrKeyIDIsNil + } + s.HandleKeyRecord(req.Parameters.KeyID, DisabledKeyStatus) + return &keymanagement.DisableKeyResponse{}, nil +} + +func (s *TestKeyManagement) GetImportParameters( + _ context.Context, + req *keymanagement.GetImportParametersRequest, +) (*keymanagement.GetImportParametersResponse, error) { + validTime := time.Now().Add(importParamsValidityHours * time.Hour) + return &keymanagement.GetImportParametersResponse{ + KeyID: req.Parameters.KeyID, + ImportParameters: map[string]any{ + "publicKey": "mock-public-key-from-provider", + "wrappingAlgorithm": "CKM_RSA_AES_KEY_WRAP", + "hashFunction": "SHA256", + "providerParams": "mock-provider-params-from-provider", + "validTo": validTime.Format(time.RFC3339), + }, + }, nil +} + +func (s *TestKeyManagement) ImportKeyMaterial( + _ context.Context, + req *keymanagement.ImportKeyMaterialRequest, +) (*keymanagement.ImportKeyMaterialResponse, error) { + if req.Parameters.KeyID != "" { + s.HandleKeyRecord(req.Parameters.KeyID, EnabledKeyStatus) + } + return &keymanagement.ImportKeyMaterialResponse{}, nil +} + +func (s *TestKeyManagement) ValidateKey( + _ context.Context, + _ *keymanagement.ValidateKeyRequest, +) (*keymanagement.ValidateKeyResponse, error) { + return &keymanagement.ValidateKeyResponse{IsValid: true}, nil +} + +func (s *TestKeyManagement) ValidateKeyAccessData( + _ context.Context, + req *keymanagement.ValidateKeyAccessDataRequest, +) (*keymanagement.ValidateKeyAccessDataResponse, error) { + if len(req.Management) == 0 || len(req.Crypto) == 0 { + return nil, keymanagement.ErrHYOKKeyNotFound + } + return &keymanagement.ValidateKeyAccessDataResponse{IsValid: true}, nil +} + +func (s *TestKeyManagement) TransformCryptoAccessData( + _ context.Context, + req *keymanagement.TransformCryptoAccessDataRequest, +) (*keymanagement.TransformCryptoAccessDataResponse, error) { + cryptoAccessDataMap := make(map[string]json.RawMessage) + if err := json.Unmarshal(req.AccessData, &cryptoAccessDataMap); err != nil { + return nil, errs.Wrap(ErrTransformAccessData, err) + } + + transformed := make(map[string][]byte, len(cryptoAccessDataMap)) + for instanceName, instanceData := range cryptoAccessDataMap { + data := &structpb.Struct{} + if err := protojson.Unmarshal(instanceData, data); err != nil { + return nil, errs.Wrap(ErrTransformAccessData, err) + } + data.Fields["keyID"] = structpb.NewStringValue(req.NativeKeyID) + b, err := protojson.Marshal(data) + if err != nil { + return nil, errs.Wrap(ErrTransformAccessData, err) + } + transformed[instanceName] = b + } + + return &keymanagement.TransformCryptoAccessDataResponse{ + TransformedAccessData: transformed, + }, nil +} + +func (s *TestKeyManagement) ExtractKeyRegion( + _ context.Context, + _ *keymanagement.ExtractKeyRegionRequest, +) (*keymanagement.ExtractKeyRegionResponse, error) { + return &keymanagement.ExtractKeyRegionResponse{Region: "test-region"}, nil +} diff --git a/internal/testutils/testplugins/key_management_test.go b/internal/testutils/testplugins/key_management_test.go new file mode 100644 index 00000000..7d95ac8f --- /dev/null +++ b/internal/testutils/testplugins/key_management_test.go @@ -0,0 +1,199 @@ +package testplugins_test + +import ( + "encoding/json" + "testing" + + "github.com/stretchr/testify/assert" + + "github.com/openkcm/cmk/internal/pluginregistry/service/api/common" + "github.com/openkcm/cmk/internal/pluginregistry/service/api/keymanagement" + "github.com/openkcm/cmk/internal/testutils/testplugins" + "github.com/openkcm/cmk/utils/ptr" +) + +func setupTest() *testplugins.TestKeyManagement { + return testplugins.NewTestKeyManagement(true, true) +} + +func TestGetKey(t *testing.T) { + p := setupTest() + + _, err := p.GetKey(t.Context(), &keymanagement.GetKeyRequest{ + Parameters: keymanagement.RequestParameters{KeyID: "mock-key/11111111"}, + }) + if err != nil { + t.Errorf("Expected no error, got %v", err) + } +} + +func TestGetKeyUpdateState(t *testing.T) { + p := setupTest() + + _, err := p.GetKey(t.Context(), &keymanagement.GetKeyRequest{ + Parameters: keymanagement.RequestParameters{KeyID: "mock-key/22222222"}, + }) + if err != nil { + t.Errorf("Expected no error, got %v", err) + } + + _, _ = p.DisableKey(t.Context(), &keymanagement.DisableKeyRequest{ + Parameters: keymanagement.RequestParameters{KeyID: "test-key-id"}, + }) + + resp, err := p.GetKey(t.Context(), &keymanagement.GetKeyRequest{ + Parameters: keymanagement.RequestParameters{KeyID: "test-key-id"}, + }) + if err != nil { + t.Errorf("Expected no error, got %v", err) + } + + assert.Equal(t, testplugins.DisabledKeyStatus, resp.Status, "Expected key status to be DISABLED") +} + +func TestCreateKeyVersion(t *testing.T) { + p := setupTest() + + resp, err := p.CreateKey(t.Context(), &keymanagement.CreateKeyRequest{ + KeyAlgorithm: keymanagement.AES256, + }) + if err != nil { + t.Errorf("Expected no error, got %v", err) + } + + assert.NotEmpty(t, resp.KeyID) +} + +func TestDeleteKeyVersion(t *testing.T) { + p := setupTest() + + _, err := p.DeleteKey(t.Context(), &keymanagement.DeleteKeyRequest{ + Parameters: keymanagement.RequestParameters{KeyID: "test-key-id"}, + Window: ptr.PointTo(int32(7)), + }) + if err != nil { + t.Errorf("Expected no error, got %v", err) + } +} + +func TestEnableKeyVersion(t *testing.T) { + p := setupTest() + + response, err := p.EnableKey(t.Context(), &keymanagement.EnableKeyRequest{ + Parameters: keymanagement.RequestParameters{KeyID: "test-key-id"}, + }) + if err != nil { + t.Errorf("Expected no error, got %v", err) + } + + assert.NotNil(t, response) +} + +func TestEnableKeyVersion_Failed_EmptyKeyID(t *testing.T) { + p := setupTest() + + response, err := p.EnableKey(t.Context(), &keymanagement.EnableKeyRequest{ + Parameters: keymanagement.RequestParameters{KeyID: ""}, + }) + + assert.Error(t, err) + assert.Nil(t, response) +} + +func TestDisableKeyVersion(t *testing.T) { + p := setupTest() + + response, err := p.DisableKey(t.Context(), &keymanagement.DisableKeyRequest{ + Parameters: keymanagement.RequestParameters{KeyID: "test-key-id"}, + }) + if err != nil { + t.Errorf("Expected no error, got %v", err) + } + + assert.NotNil(t, response) +} + +func TestDisableKeyVersion_Failed_EmptyKeyID(t *testing.T) { + p := setupTest() + + response, err := p.DisableKey(t.Context(), &keymanagement.DisableKeyRequest{ + Parameters: keymanagement.RequestParameters{KeyID: ""}, + }) + + assert.Error(t, err) + assert.Nil(t, response) +} + +func TestGetImportParameters(t *testing.T) { + p := setupTest() + + resp, err := p.GetImportParameters(t.Context(), &keymanagement.GetImportParametersRequest{ + Parameters: keymanagement.RequestParameters{KeyID: "test-key-id"}, + KeyAlgorithm: keymanagement.AES256, + }) + + assert.NoError(t, err) + assert.Equal(t, "CKM_RSA_AES_KEY_WRAP", resp.ImportParameters["wrappingAlgorithm"]) + assert.Equal(t, "SHA256", resp.ImportParameters["hashFunction"]) + assert.Equal(t, "mock-public-key-from-provider", resp.ImportParameters["publicKey"]) + assert.Equal(t, "mock-provider-params-from-provider", resp.ImportParameters["providerParams"]) +} + +func TestImportKeyMaterial(t *testing.T) { + p := setupTest() + + _, err := p.ImportKeyMaterial(t.Context(), &keymanagement.ImportKeyMaterialRequest{ + Parameters: keymanagement.RequestParameters{KeyID: "test-key-id"}, + EncryptedKeyMaterial: "abcdefghijklmnopqrstuvwxyz", + }) + + assert.NoError(t, err) +} + +func TestTransformCryptoAccessData(t *testing.T) { + p := setupTest() + + input := func() []byte { + data := map[string]map[string]any{ + "instance-1": {"field1": "value1", "field2": "value2"}, + "instance-2": {"field1": "value2", "field2": "value2"}, + } + b, err := json.Marshal(data) + assert.NoError(t, err) + return b + }() + + resp, err := p.TransformCryptoAccessData(t.Context(), &keymanagement.TransformCryptoAccessDataRequest{ + NativeKeyID: "test-key-id", + AccessData: input, + }) + + assert.NoError(t, err) + assert.NotNil(t, resp) +} + +func TestConfigure(t *testing.T) { + p := setupTest() + + cfg := p.ServiceInfo() + assert.Equal(t, testplugins.Name, cfg.Name()) +} + +func TestDeleteKeyVersion_SetsStatus(t *testing.T) { + p := setupTest() + + keyID := "mock-key/11111111" + _, err := p.DeleteKey(t.Context(), &keymanagement.DeleteKeyRequest{ + Parameters: keymanagement.RequestParameters{KeyID: keyID}, + }) + assert.NoError(t, err) + + resp, err := p.GetKey(t.Context(), &keymanagement.GetKeyRequest{ + Parameters: keymanagement.RequestParameters{ + KeyID: keyID, + Config: common.KeystoreConfig{Values: map[string]any{}}, + }, + }) + assert.NoError(t, err) + assert.Equal(t, testplugins.PendingDeletionKeyStatus, resp.Status) +} diff --git a/internal/testutils/testplugins/keystore_management.go b/internal/testutils/testplugins/keystore_management.go index f2324d43..58828ffc 100644 --- a/internal/testutils/testplugins/keystore_management.go +++ b/internal/testutils/testplugins/keystore_management.go @@ -4,81 +4,49 @@ import ( "context" "github.com/google/uuid" - "github.com/hashicorp/go-hclog" - "github.com/openkcm/plugin-sdk/pkg/catalog" - "google.golang.org/protobuf/types/known/structpb" + "github.com/openkcm/plugin-sdk/api" - kscommonv1 "github.com/openkcm/plugin-sdk/proto/plugin/keystore/common/v1" - keymanv1 "github.com/openkcm/plugin-sdk/proto/plugin/keystore/management/v1" - configv1 "github.com/openkcm/plugin-sdk/proto/service/common/config/v1" + "github.com/openkcm/cmk/internal/pluginregistry/service/api/common" + "github.com/openkcm/cmk/internal/pluginregistry/service/api/keystoremanagement" + servicewrapper "github.com/openkcm/cmk/internal/pluginregistry/service/wrapper" ) -type KeystoreManagement struct { - keymanv1.UnsafeKeystoreProviderServer - configv1.UnsafeConfigServer +type TestKeystoreManagement struct{} - logger hclog.Logger -} +var _ keystoremanagement.KeystoreManagement = (*TestKeystoreManagement)(nil) -func NewKeystoreManagement() catalog.BuiltInPlugin { - p := &KeystoreManagement{} - return catalog.MakeBuiltIn( - Name, - keymanv1.KeystoreProviderPluginServer(p), - configv1.ConfigServiceServer(p), - ) +func NewTestKeystoreManagement() *TestKeystoreManagement { + return &TestKeystoreManagement{} } -func (p *KeystoreManagement) SetLogger(logger hclog.Logger) { - p.logger = logger - p.logger.Info("SetLogger method has been called;") +func (s *TestKeystoreManagement) ServiceInfo() api.Info { + return testInfo{ + configuredType: servicewrapper.KeystoreManagementType, + } } -func (p *KeystoreManagement) CreateKeystore( +func (s *TestKeystoreManagement) CreateKeystore( _ context.Context, - _ *keymanv1.CreateKeystoreRequest, -) (*keymanv1.CreateKeystoreResponse, error) { - p.logger.Info("CreateKeystore method has been called;") - - config := &structpb.Struct{ - Fields: map[string]*structpb.Value{ - "locality": structpb.NewStringValue("test-uuid"), - "commonName": structpb.NewStringValue("default.kms.test"), - "managementAccessData": structpb.NewStructValue(&structpb.Struct{ - Fields: map[string]*structpb.Value{ - "accountId": structpb.NewStringValue("mock-account"), - "userId": structpb.NewStringValue("mock-user"), - "random": structpb.NewStringValue(uuid.NewString()), + _ *keystoremanagement.CreateKeystoreRequest, +) (*keystoremanagement.CreateKeystoreResponse, error) { + return &keystoremanagement.CreateKeystoreResponse{ + Config: common.KeystoreConfig{ + Values: map[string]any{ + "locality": "test-uuid", + "commonName": "default.kms.test", + "managementAccessData": map[string]any{ + "accountId": "mock-account", + "userId": "mock-user", + "random": uuid.NewString(), }, - }), - }, - } - - return &keymanv1.CreateKeystoreResponse{ - Config: &kscommonv1.KeystoreInstanceConfig{ - Values: config, + }, }, }, nil } -func (p *KeystoreManagement) DeleteKeystore( +func (s *TestKeystoreManagement) DeleteKeystore( _ context.Context, - _ *keymanv1.DeleteKeystoreRequest, -) (*keymanv1.DeleteKeystoreResponse, error) { - return &keymanv1.DeleteKeystoreResponse{}, nil -} - -// Configure configures the plugin. - -func (p *KeystoreManagement) Configure( - _ context.Context, - _ *configv1.ConfigureRequest, -) (*configv1.ConfigureResponse, error) { - p.logger.Info("Configure method has been called;") - - buildInfo := "{}" - - return &configv1.ConfigureResponse{ - BuildInfo: &buildInfo, - }, nil + _ *keystoremanagement.DeleteKeystoreRequest, +) (*keystoremanagement.DeleteKeystoreResponse, error) { + return &keystoremanagement.DeleteKeystoreResponse{}, nil } diff --git a/internal/testutils/testplugins/keystore_operator.go b/internal/testutils/testplugins/keystore_operator.go deleted file mode 100644 index aeb9852f..00000000 --- a/internal/testutils/testplugins/keystore_operator.go +++ /dev/null @@ -1,387 +0,0 @@ -package testplugins - -import ( - "context" - "encoding/json" - "errors" - "time" - - "github.com/google/uuid" - "github.com/hashicorp/go-hclog" - "github.com/openkcm/plugin-sdk/pkg/catalog" - "google.golang.org/protobuf/encoding/protojson" - "google.golang.org/protobuf/types/known/structpb" - "google.golang.org/protobuf/types/known/timestamppb" - - commonErrs "github.com/openkcm/plugin-sdk/pkg/plugin/keystore/errors" - keyopv1 "github.com/openkcm/plugin-sdk/proto/plugin/keystore/operations/v1" - configv1 "github.com/openkcm/plugin-sdk/proto/service/common/config/v1" - - "github.com/openkcm/cmk/internal/testutils" -) - -var ( - EnabledKeyStatus = "ENABLED" - DisabledKeyStatus = "DISABLED" - CreatedKeyStatus = "CREATED" - PendingImportKeyStatus = "PENDING_IMPORT" - PendingDeletionKeyStatus = "PENDING_DELETION" - UnknownKeyStatus = "UNKNOWN" - - ErrRequestIsNil = errors.New("request is nil") - ErrParameterIsNil = errors.New("parameter is nil") - ErrKeyIDIsNil = errors.New("keyId is nil") - ErrUnmarshalJSON = errors.New("failed to unmarshal JSON access data") - ErrUnmarshalProtoJSON = errors.New("failed to unmarshal protoJSON access data") - ErrMarshalProto = errors.New("failed to marshal proto access data") -) - -const importParamsValidityHours = 24 - -type KeyRecord struct { - KeyID string `gorm:"primaryKey;column:key_id"` - Status string - VersionID string - RotationTime string // RFC3339 format -} - -type KeystoreOperator struct { - keyopv1.UnsafeKeystoreInstanceKeyOperationServer - configv1.UnsafeConfigServer - - logger hclog.Logger - KeyStore map[string]*KeyRecord -} - -var InitialKeys = map[string]KeyRecord{ - "mock-key/11111111": {Status: EnabledKeyStatus}, - "mock-key/22222222": {Status: EnabledKeyStatus}, - "mock-key/33333333": {Status: EnabledKeyStatus}, -} - -func NewKeystoreOperator() catalog.BuiltInPlugin { - p := NewKeystoreOperatorInstance() - return NewKeystoreOperatorFromInstance(p) -} - -func NewKeystoreOperatorInstance() *KeystoreOperator { - p := &KeystoreOperator{ - KeyStore: make(map[string]*KeyRecord), - } - - for keyID, record := range InitialKeys { - p.HandleKeyRecord(keyID, record.Status) - } - return p -} - -func NewKeystoreOperatorFromInstance(p *KeystoreOperator) catalog.BuiltInPlugin { - return catalog.MakeBuiltIn( - Name, - keyopv1.KeystoreInstanceKeyOperationPluginServer(p), - configv1.ConfigServiceServer(p), - ) -} - -func (p *KeystoreOperator) CreateKey( - _ context.Context, - request *keyopv1.CreateKeyRequest, -) (*keyopv1.CreateKeyResponse, error) { - p.logger.Info("CreateKey method has been called;") - - status := EnabledKeyStatus - if request.GetKeyType() == keyopv1.KeyType_KEY_TYPE_BYOK { - status = PendingImportKeyStatus - } - - keyID := "mock-key/" + uuid.NewString() - - p.HandleKeyRecord(keyID, status) - - return &keyopv1.CreateKeyResponse{ - KeyId: keyID, - Status: status, - }, nil -} - -func (p *KeystoreOperator) DeleteKey( - _ context.Context, - request *keyopv1.DeleteKeyRequest, -) (*keyopv1.DeleteKeyResponse, error) { - p.logger.Info("DeleteKey method has been called;") - - if request != nil && request.GetParameters() != nil { - keyID := request.GetParameters().GetKeyId() - if keyID != "" { - if p.KeyStore != nil { - p.HandleKeyRecord(keyID, PendingDeletionKeyStatus) - } - } - } - - return &keyopv1.DeleteKeyResponse{}, nil -} - -func (p *KeystoreOperator) EnableKey( - _ context.Context, - request *keyopv1.EnableKeyRequest, -) (*keyopv1.EnableKeyResponse, error) { - if request == nil { - return nil, ErrRequestIsNil - } - - if request.GetParameters() == nil { - return nil, ErrParameterIsNil - } - - keyID := request.GetParameters().GetKeyId() - if keyID == "" { - return nil, ErrKeyIDIsNil - } - - p.logger.Info("EnableKey method has been called;") - - p.HandleKeyRecord(keyID, EnabledKeyStatus) - - return &keyopv1.EnableKeyResponse{}, nil -} - -func (p *KeystoreOperator) DisableKey( - _ context.Context, - request *keyopv1.DisableKeyRequest, -) (*keyopv1.DisableKeyResponse, error) { - if request == nil { - return nil, ErrRequestIsNil - } - - if request.GetParameters() == nil { - return nil, ErrParameterIsNil - } - - keyID := request.GetParameters().GetKeyId() - if keyID == "" { - return nil, ErrKeyIDIsNil - } - - p.logger.Info("DisableKey method has been called;") - - p.HandleKeyRecord(keyID, DisabledKeyStatus) - - return &keyopv1.DisableKeyResponse{}, nil -} - -func (p *KeystoreOperator) GetKey( - _ context.Context, - request *keyopv1.GetKeyRequest, -) (*keyopv1.GetKeyResponse, error) { - p.logger.Info("Get method has been called;") - - config := request.GetParameters().GetConfig().GetValues().AsMap() - if config["authType"] == "AUTH_TYPE_CERTIFICATE" && - (config["AccountID"] != testutils.ValidKeystoreAccountInfo["AccountID"] || - config["UserID"] != testutils.ValidKeystoreAccountInfo["UserID"]) { - return nil, commonErrs.NewGrpcErrorWithDetails( - commonErrs.StatusProviderAuthenticationError, - "Invalid account information", nil, - ) - } - - keyID := request.GetParameters().GetKeyId() - - if p.KeyStore == nil { - p.KeyStore = make(map[string]*KeyRecord) - } - - record, exists := p.KeyStore[keyID] - - var status string - - if !exists { - return nil, commonErrs.StatusKeyNotFound.Err() - } - - status = record.Status - - response := &keyopv1.GetKeyResponse{ - Algorithm: keyopv1.KeyAlgorithm_KEY_ALGORITHM_AES256, - Status: status, - } - - // Add version info if available - if record.VersionID != "" { - response.LatestKeyVersionId = record.VersionID - } - - // Add rotation time if available - if record.RotationTime != "" { - // Parse RFC3339Nano string (fallback to RFC3339) and convert to protobuf timestamp - rotTime, err := time.Parse(time.RFC3339Nano, record.RotationTime) - if err != nil { - // Fallback to RFC3339 if Nano parsing fails - rotTime, err = time.Parse(time.RFC3339, record.RotationTime) - } - if err == nil { - response.LatestRotationTime = timestamppb.New(rotTime) - } - } - - return response, nil -} - -func (p *KeystoreOperator) GetImportParameters( - _ context.Context, - request *keyopv1.GetImportParametersRequest, -) (*keyopv1.GetImportParametersResponse, error) { - p.logger.Info("GetImportParameters method has been called;") - - validTime := time.Now().Add(importParamsValidityHours * time.Hour) - validTimeStr := validTime.Format(time.RFC3339) - - importParametersStruct, _ := structpb.NewStruct(map[string]any{ - "publicKey": "mock-public-key-from-provider", - "wrappingAlgorithm": "CKM_RSA_AES_KEY_WRAP", - "hashFunction": "SHA256", - "providerParams": "mock-provider-params-from-provider", - "validTo": validTimeStr, - }) - - return &keyopv1.GetImportParametersResponse{ - KeyId: request.GetParameters().GetKeyId(), - ImportParameters: importParametersStruct, - }, nil -} - -func (p *KeystoreOperator) ImportKeyMaterial( - _ context.Context, - request *keyopv1.ImportKeyMaterialRequest, -) (*keyopv1.ImportKeyMaterialResponse, error) { - p.logger.Info("ImportKeyMaterial method has been called;") - - keyID := request.GetParameters().GetKeyId() - if keyID != "" { - p.HandleKeyRecord(keyID, EnabledKeyStatus) - } - - return &keyopv1.ImportKeyMaterialResponse{}, nil -} - -func (p *KeystoreOperator) ValidateKey( - _ context.Context, - _ *keyopv1.ValidateKeyRequest, -) (*keyopv1.ValidateKeyResponse, error) { - p.logger.Info("ValidateKey method has been called;") - return &keyopv1.ValidateKeyResponse{IsValid: true}, nil -} - -func (p *KeystoreOperator) ValidateKeyAccessData( - _ context.Context, - req *keyopv1.ValidateKeyAccessDataRequest, -) (*keyopv1.ValidateKeyAccessDataResponse, error) { - p.logger.Info("ValidateKeyAccessData method has been called;") - - if len(req.GetManagement().GetFields()) == 0 || len(req.GetCrypto().GetFields()) == 0 { - return nil, commonErrs.StatusInvalidKeyAccessData.Err() - } - - return &keyopv1.ValidateKeyAccessDataResponse{IsValid: true}, nil -} - -func (p *KeystoreOperator) TransformCryptoAccessData( - _ context.Context, - request *keyopv1.TransformCryptoAccessDataRequest, -) (*keyopv1.TransformCryptoAccessDataResponse, error) { - p.logger.Info("TransformCryptoAccessData method has been called;") - - cryptoAccessDataMap := make(map[string]json.RawMessage) - transformedCryptoAccessDataMap := make(map[string][]byte) - - err := json.Unmarshal(request.GetAccessData(), &cryptoAccessDataMap) - if err != nil { - return nil, ErrUnmarshalJSON - } - - for instanceName, instanceData := range cryptoAccessDataMap { - data := &structpb.Struct{} - - err = protojson.Unmarshal(instanceData, data) - if err != nil { - return nil, ErrUnmarshalProtoJSON - } - - data.Fields["keyID"] = structpb.NewStringValue(request.GetNativeKeyId()) - - instanceBytes, err := protojson.Marshal(data) - if err != nil { - return nil, ErrMarshalProto - } - - transformedCryptoAccessDataMap[instanceName] = instanceBytes - } - - return &keyopv1.TransformCryptoAccessDataResponse{ - TransformedAccessData: transformedCryptoAccessDataMap, - }, nil -} - -func (p *KeystoreOperator) ExtractKeyRegion( - _ context.Context, - _ *keyopv1.ExtractKeyRegionRequest, -) (*keyopv1.ExtractKeyRegionResponse, error) { - p.logger.Info("ExtractKeyRegion method has been called;") - return &keyopv1.ExtractKeyRegionResponse{Region: "test-region"}, nil -} - -func (p *KeystoreOperator) SetLogger(logger hclog.Logger) { - p.logger = logger - p.logger.Info("SetLogger method has been called;") -} - -// Configure configures the plugin. - -func (p *KeystoreOperator) Configure( - _ context.Context, - _ *configv1.ConfigureRequest, -) (*configv1.ConfigureResponse, error) { - p.logger.Info("Configure method has been called;") - - buildInfo := "{}" - - return &configv1.ConfigureResponse{ - BuildInfo: &buildInfo, - }, nil -} - -func (p *KeystoreOperator) HandleKeyRecord(keyID, status string) { - if p.KeyStore == nil { - p.KeyStore = make(map[string]*KeyRecord) - } - - record, exists := p.KeyStore[keyID] - if !exists { - record = &KeyRecord{ - KeyID: keyID, - Status: status, - } - p.KeyStore[keyID] = record - } - - record.Status = status -} - -func (p *KeystoreOperator) SetKeyVersionInfo(keyID, versionID, rotationTime string) { - if p.KeyStore == nil { - p.KeyStore = make(map[string]*KeyRecord) - } - - record, exists := p.KeyStore[keyID] - if !exists { - record = &KeyRecord{ - KeyID: keyID, - Status: EnabledKeyStatus, - } - p.KeyStore[keyID] = record - } - - record.VersionID = versionID - record.RotationTime = rotationTime -} diff --git a/internal/testutils/testplugins/keystore_operator_test.go b/internal/testutils/testplugins/keystore_operator_test.go deleted file mode 100644 index a3f1577b..00000000 --- a/internal/testutils/testplugins/keystore_operator_test.go +++ /dev/null @@ -1,284 +0,0 @@ -package testplugins_test - -import ( - "encoding/json" - "log/slog" - "testing" - - "github.com/magodo/slog2hclog" - "github.com/stretchr/testify/assert" - - keyopv1 "github.com/openkcm/plugin-sdk/proto/plugin/keystore/operations/v1" - - "github.com/openkcm/cmk/internal/testutils/testplugins" - "github.com/openkcm/cmk/utils/ptr" -) - -func setupTest() *testplugins.KeystoreOperator { - p := &testplugins.KeystoreOperator{ - KeyStore: make(map[string]*testplugins.KeyRecord), - } - - for keyID, record := range testplugins.InitialKeys { - p.HandleKeyRecord(keyID, record.Status) - } - - logLevelPlugin := new(slog.LevelVar) - p.SetLogger(slog2hclog.New(slog.Default(), logLevelPlugin)) - - return p -} - -func TestGetKey(t *testing.T) { - // Arrange - p := setupTest() - - // Act - _, err := p.GetKey(t.Context(), &keyopv1.GetKeyRequest{ - Parameters: &keyopv1.RequestParameters{KeyId: "mock-key/11111111"}, - }) - // Assert - if err != nil { - t.Errorf("Expected no error, got %v", err) - } -} - -func TestGetKeyUpdateState(t *testing.T) { - // Arrange - p := setupTest() - - // Act - _, err := p.GetKey(t.Context(), &keyopv1.GetKeyRequest{ - Parameters: &keyopv1.RequestParameters{KeyId: "mock-key/22222222"}, - }) - // Assert - if err != nil { - t.Errorf("Expected no error, got %v", err) - } - - // Act 2 - _, _ = p.DisableKey(t.Context(), &keyopv1.DisableKeyRequest{ - Parameters: &keyopv1.RequestParameters{KeyId: "test-key-id"}, - }) - - resp, err := p.GetKey(t.Context(), &keyopv1.GetKeyRequest{ - Parameters: &keyopv1.RequestParameters{KeyId: "test-key-id"}, - }) - if err != nil { - t.Errorf("Expected no error, got %v", err) - } - - assert.Equal(t, "DISABLED", resp.GetStatus(), "Expected key status to be DISABLED") -} - -func TestCreateKeyVersion(t *testing.T) { - // Arrange - p := setupTest() - - // Act - resp, err := p.CreateKey(t.Context(), &keyopv1.CreateKeyRequest{ - Algorithm: keyopv1.KeyAlgorithm_KEY_ALGORITHM_AES256, - }) - // Assert - if err != nil { - t.Errorf("Expected no error, got %v", err) - } - - assert.NotEmpty(t, resp.GetKeyId()) -} - -func TestDeleteKeyVersion(t *testing.T) { - // Arrange - p := setupTest() - - // Act - _, err := p.DeleteKey(t.Context(), &keyopv1.DeleteKeyRequest{ - Parameters: &keyopv1.RequestParameters{KeyId: "test-key-id"}, - Window: ptr.PointTo(int32(7)), - }) - // Assert - if err != nil { - t.Errorf("Expected no error, got %v", err) - } -} - -func TestEnableKeyVersion(t *testing.T) { - // Arrange - p := setupTest() - - // Act - response, err := p.EnableKey(t.Context(), &keyopv1.EnableKeyRequest{ - Parameters: &keyopv1.RequestParameters{KeyId: "test-key-id"}, - }) - // Assert - if err != nil { - t.Errorf("Expected no error, got %v", err) - } - - assert.NotNil(t, response) -} - -func TestEnableKeyVersion_Failed_EmptyRequest(t *testing.T) { - // Arrange - p := setupTest() - - // Act - response, err := p.EnableKey(t.Context(), nil) - - // Assert - assert.Error(t, err) - assert.Nil(t, response) -} - -func TestEnableKeyVersion_Failed_WrongParameter(t *testing.T) { - // Arrange - p := setupTest() - - // Act - response, err := p.EnableKey(t.Context(), &keyopv1.EnableKeyRequest{ - Parameters: nil, - }) - - // Assert - assert.Error(t, err) - assert.Nil(t, response) - - // Act - response, err = p.EnableKey(t.Context(), &keyopv1.EnableKeyRequest{ - Parameters: &keyopv1.RequestParameters{KeyId: ""}, - }) - - // Assert - assert.Error(t, err) - assert.Nil(t, response) -} - -func TestDisableKeyVersion(t *testing.T) { - // Arrange - p := setupTest() - - // Act - response, err := p.DisableKey(t.Context(), &keyopv1.DisableKeyRequest{ - Parameters: &keyopv1.RequestParameters{KeyId: "test-key-id"}, - }) - // Assert - if err != nil { - t.Errorf("Expected no error, got %v", err) - } - - assert.NotNil(t, response) -} - -func TestDisableKeyVersion_Failed_EmptyRequest(t *testing.T) { - // Arrange - p := setupTest() - - // Act - response, err := p.DisableKey(t.Context(), nil) - - // Assert - assert.Error(t, err) - assert.Nil(t, response) -} - -func TestDisableKeyVersion_Failed_WrongParameter(t *testing.T) { - // Arrange - p := setupTest() - - // Act - response, err := p.DisableKey(t.Context(), &keyopv1.DisableKeyRequest{ - Parameters: nil, - }) - - // Assert - assert.Error(t, err) - assert.Nil(t, response) - - // Act - response, err = p.DisableKey(t.Context(), &keyopv1.DisableKeyRequest{ - Parameters: &keyopv1.RequestParameters{KeyId: ""}, - }) - - // Assert - assert.Error(t, err) - assert.Nil(t, response) -} - -func TestGetImportParameters(t *testing.T) { - // Arrange - p := setupTest() - - // Act - resp, err := p.GetImportParameters(t.Context(), &keyopv1.GetImportParametersRequest{ - Parameters: &keyopv1.RequestParameters{KeyId: "test-key-id"}, - Algorithm: keyopv1.KeyAlgorithm_KEY_ALGORITHM_AES256, - }) - - // Assert - assert.NoError(t, err) - assert.Equal(t, "CKM_RSA_AES_KEY_WRAP", resp.GetImportParameters().GetFields()["wrappingAlgorithm"].GetStringValue()) - assert.Equal(t, "SHA256", resp.GetImportParameters().GetFields()["hashFunction"].GetStringValue()) - assert.Equal(t, "mock-public-key-from-provider", - resp.GetImportParameters().GetFields()["publicKey"].GetStringValue()) - assert.Equal(t, "mock-provider-params-from-provider", - resp.GetImportParameters().GetFields()["providerParams"].GetStringValue()) -} - -func TestImportKeyMaterial(t *testing.T) { - // Arrange - p := setupTest() - - // Act - _, err := p.ImportKeyMaterial(t.Context(), &keyopv1.ImportKeyMaterialRequest{ - Parameters: &keyopv1.RequestParameters{KeyId: "test-key-id"}, - EncryptedKeyMaterial: "abcdefghijklmnopqrstuvwxyz", - }) - - // Assert - assert.NoError(t, err) -} - -func TestTransformCryptoAccessData(t *testing.T) { - p := setupTest() - - input := func() []byte { - data := map[string]map[string]any{ - "instance-1": { - "field1": "value1", - "field2": "value2", - }, - "instance-2": { - "field1": "value2", - "field2": "value2", - }, - } - bytes, err := json.Marshal(data) - assert.NoError(t, err) - - return bytes - }() - - resp, err := p.TransformCryptoAccessData(t.Context(), &keyopv1.TransformCryptoAccessDataRequest{ - NativeKeyId: "test-key-id", - AccessData: input, - }) - - assert.NoError(t, err) - assert.NotNil(t, resp) -} - -func TestConfigure(t *testing.T) { - // Arrange - p := setupTest() - - // Act - res, err := p.Configure(t.Context(), nil) - // Assert - if err != nil { - t.Errorf("Configure() error = %v, want nil", err) - } - - if res == nil { - t.Errorf("Configure() = nil, want non-nil") - } -} diff --git a/internal/testutils/testplugins/notication.go b/internal/testutils/testplugins/notication.go index 5b58894d..4c86d739 100644 --- a/internal/testutils/testplugins/notication.go +++ b/internal/testutils/testplugins/notication.go @@ -2,36 +2,30 @@ package testplugins import ( "context" - "log/slog" - "github.com/openkcm/plugin-sdk/pkg/catalog" + "github.com/openkcm/plugin-sdk/api" - notificationv1 "github.com/openkcm/plugin-sdk/proto/plugin/notification/v1" - configv1 "github.com/openkcm/plugin-sdk/proto/service/common/config/v1" + "github.com/openkcm/cmk/internal/pluginregistry/service/api/notification" + servicewrapper "github.com/openkcm/cmk/internal/pluginregistry/service/wrapper" ) -type Notification struct { - notificationv1.UnimplementedNotificationServiceServer - configv1.UnsafeConfigServer -} +type TestNotification struct{} -func NewNotification() catalog.BuiltInPlugin { - p := &Notification{} - return catalog.MakeBuiltIn( - Name, - notificationv1.NotificationServicePluginServer(p), - configv1.ConfigServiceServer(p), - ) -} +var _ notification.Notification = (*TestNotification)(nil) -func (p *Notification) Configure(_ context.Context, _ *configv1.ConfigureRequest) (*configv1.ConfigureResponse, error) { - slog.Info("Configuring plugin") +func NewTestNotification() *TestNotification { + return &TestNotification{} +} - return &configv1.ConfigureResponse{}, nil +func (s *TestNotification) ServiceInfo() api.Info { + return testInfo{ + configuredType: servicewrapper.NotificationServiceType, + } } -func (p *Notification) SendNotification(_ context.Context, _ *notificationv1.SendNotificationRequest) ( - *notificationv1.SendNotificationResponse, error, -) { - return ¬ificationv1.SendNotificationResponse{}, nil +func (s *TestNotification) Send( + _ context.Context, + _ *notification.SendNotificationRequest, +) (*notification.SendNotificationResponse, error) { + return ¬ification.SendNotificationResponse{}, nil } diff --git a/internal/testutils/testplugins/registry.go b/internal/testutils/testplugins/registry.go new file mode 100644 index 00000000..82ffe880 --- /dev/null +++ b/internal/testutils/testplugins/registry.go @@ -0,0 +1,137 @@ +package testplugins + +import ( + serviceapi "github.com/openkcm/cmk/internal/pluginregistry/service/api" + "github.com/openkcm/cmk/internal/pluginregistry/service/api/certificateissuer" + "github.com/openkcm/cmk/internal/pluginregistry/service/api/identitymanagement" + "github.com/openkcm/cmk/internal/pluginregistry/service/api/keymanagement" + "github.com/openkcm/cmk/internal/pluginregistry/service/api/keystoremanagement" + "github.com/openkcm/cmk/internal/pluginregistry/service/api/notification" + "github.com/openkcm/cmk/internal/pluginregistry/service/api/systeminformation" + "github.com/openkcm/cmk/internal/pluginregistry/service/wrapper/system_information" +) + +// Registry is a test implementation of serviceapi.Registry that holds native +// Go service implementations, bypassing the plugin-sdk catalog and gRPC layer. +type Registry struct { + certificateIssuer certificateissuer.CertificateIssuer + identityManagement identitymanagement.IdentityManagement + keystoreManagements map[string]keystoremanagement.KeystoreManagement + keyManagements map[string]keymanagement.KeyManagement + notificationSvc notification.Notification + systemInformation systeminformation.SystemInformation +} + +// Compile-time assertion that Registry implements serviceapi.Registry. +var _ serviceapi.Registry = (*Registry)(nil) + +// RegistryOption configures a Registry. +type RegistryOption func(*Registry) + +// WithCertificateIssuer sets the CertificateIssuer service. +func WithCertificateIssuer(svc certificateissuer.CertificateIssuer) RegistryOption { + return func(r *Registry) { r.certificateIssuer = svc } +} + +// WithIdentityManagement sets the IdentityManagement service. +func WithIdentityManagement(svc identitymanagement.IdentityManagement) RegistryOption { + return func(r *Registry) { r.identityManagement = svc } +} + +// WithKeystoreManagement adds a KeystoreManagement service under the given key. +func WithKeystoreManagement(key string, svc keystoremanagement.KeystoreManagement) RegistryOption { + return func(r *Registry) { + if r.keystoreManagements == nil { + r.keystoreManagements = make(map[string]keystoremanagement.KeystoreManagement) + } + r.keystoreManagements[key] = svc + } +} + +// WithKeyManagement adds a KeyManagement service under the given key. +func WithKeyManagement(key string, svc keymanagement.KeyManagement) RegistryOption { + return func(r *Registry) { + if r.keyManagements == nil { + r.keyManagements = make(map[string]keymanagement.KeyManagement) + } + r.keyManagements[key] = svc + } +} + +// WithNotification sets the Notification service. +func WithNotification(svc notification.Notification) RegistryOption { + return func(r *Registry) { r.notificationSvc = svc } +} + +// WithSystemInformation sets the SystemInformation service. +func WithSystemInformation(svc systeminformation.SystemInformation) RegistryOption { + return func(r *Registry) { r.systemInformation = svc } +} + +// WithNoSystemInformation clears the SystemInformation service so that +// SystemInformation() returns system_information.ErrNotConfigured. +func WithNoSystemInformation() RegistryOption { + return func(r *Registry) { r.systemInformation = nil } +} + +// NewRegistry creates a Registry prepopulated with default test service implementations. +// Individual services can be overridden via RegistryOption. +func NewRegistry(opts ...RegistryOption) *Registry { + r := &Registry{ + certificateIssuer: NewTestCertificateIssuer(), + identityManagement: NewTestIdentityManagement(), + notificationSvc: NewTestNotification(), + systemInformation: NewTestSystemInformation(), + keystoreManagements: map[string]keystoremanagement.KeystoreManagement{Name: NewTestKeystoreManagement()}, + keyManagements: map[string]keymanagement.KeyManagement{Name: NewTestKeyManagement(true, true)}, + } + for _, o := range opts { + o(r) + } + return r +} + +func (r *Registry) Close() error { return nil } + +func (r *Registry) CertificateIssuer() (certificateissuer.CertificateIssuer, error) { + return r.certificateIssuer, nil +} + +func (r *Registry) Notification() (notification.Notification, error) { + return r.notificationSvc, nil +} + +func (r *Registry) SystemInformation() (systeminformation.SystemInformation, error) { + if r.systemInformation == nil { + return nil, system_information.ErrNotConfigured + } + return r.systemInformation, nil +} + +func (r *Registry) IdentityManagement() (identitymanagement.IdentityManagement, error) { + return r.identityManagement, nil +} + +func (r *Registry) KeystoreManagements() (map[string]keystoremanagement.KeystoreManagement, error) { + return r.keystoreManagements, nil +} + +func (r *Registry) KeystoreManagementList() ([]keystoremanagement.KeystoreManagement, error) { + list := make([]keystoremanagement.KeystoreManagement, 0, len(r.keystoreManagements)) + for _, svc := range r.keystoreManagements { + list = append(list, svc) + } + return list, nil +} + +func (r *Registry) KeyManagements() (map[string]keymanagement.KeyManagement, error) { + return r.keyManagements, nil +} + +func (r *Registry) KeyManagementList() ([]keymanagement.KeyManagement, error) { + list := make([]keymanagement.KeyManagement, 0, len(r.keyManagements)) + for _, svc := range r.keyManagements { + list = append(list, svc) + } + return list, nil +} diff --git a/internal/testutils/testplugins/system_information.go b/internal/testutils/testplugins/system_information.go index ef5cd2d4..ebf9f615 100644 --- a/internal/testutils/testplugins/system_information.go +++ b/internal/testutils/testplugins/system_information.go @@ -2,42 +2,30 @@ package testplugins import ( "context" - "log/slog" - "github.com/openkcm/plugin-sdk/pkg/catalog" + "github.com/openkcm/plugin-sdk/api" - systeminformationv1 "github.com/openkcm/plugin-sdk/proto/plugin/systeminformation/v1" - configv1 "github.com/openkcm/plugin-sdk/proto/service/common/config/v1" + "github.com/openkcm/cmk/internal/pluginregistry/service/api/systeminformation" + servicewrapper "github.com/openkcm/cmk/internal/pluginregistry/service/wrapper" ) -type SystemInformation struct { - systeminformationv1.UnsafeSystemInformationServiceServer - configv1.UnsafeConfigServer -} +type TestSystemInformation struct{} -func NewSystemInformation() catalog.BuiltInPlugin { - p := &SystemInformation{} - return catalog.MakeBuiltIn( - Name, - systeminformationv1.SystemInformationServicePluginServer(p), - configv1.ConfigServiceServer(p), - ) -} +var _ systeminformation.SystemInformation = (*TestSystemInformation)(nil) -func (p *SystemInformation) Configure( - _ context.Context, - req *configv1.ConfigureRequest, -) (*configv1.ConfigureResponse, error) { - slog.Info("Configuring plugin") +func NewTestSystemInformation() *TestSystemInformation { + return &TestSystemInformation{} +} - return &configv1.ConfigureResponse{}, nil +func (s *TestSystemInformation) ServiceInfo() api.Info { + return testInfo{ + configuredType: servicewrapper.SystemInformationServiceType, + } } -func (p *SystemInformation) Get( +func (s *TestSystemInformation) GetSystemInfo( _ context.Context, - _ *systeminformationv1.GetRequest, -) ( - *systeminformationv1.GetResponse, error, -) { - return &systeminformationv1.GetResponse{}, nil + _ *systeminformation.GetSystemInfoRequest, +) (*systeminformation.GetSystemInfoResponse, error) { + return &systeminformation.GetSystemInfoResponse{}, nil } diff --git a/internal/workflow/workflow_test.go b/internal/workflow/workflow_test.go index b0dcd058..cc6a50d8 100644 --- a/internal/workflow/workflow_test.go +++ b/internal/workflow/workflow_test.go @@ -19,11 +19,9 @@ import ( eventprocessor "github.com/openkcm/cmk/internal/event-processor" "github.com/openkcm/cmk/internal/manager" "github.com/openkcm/cmk/internal/model" - cmkpluginregistry "github.com/openkcm/cmk/internal/pluginregistry" "github.com/openkcm/cmk/internal/repo" sqlRepo "github.com/openkcm/cmk/internal/repo/sql" "github.com/openkcm/cmk/internal/testutils" - "github.com/openkcm/cmk/internal/testutils/testplugins" "github.com/openkcm/cmk/internal/workflow" ) @@ -42,21 +40,16 @@ var ( func SetupWorkflowManager(t *testing.T) (*manager.Manager, *multitenancy.DB, string) { t.Helper() - ps, psCfg := testutils.NewTestPlugins(testplugins.NewKeystoreOperator()) - dbCon, tenants, dbConf := testutils.NewTestDB(t, testutils.TestDBConfig{CreateDatabase: true}) cfg := config.Config{ - Plugins: psCfg, Database: dbConf, } tenant := tenants[0] ctx := testutils.CreateCtxWithTenant(tenant) - svcRegistry, err := cmkpluginregistry.New(ctx, &cfg, cmkpluginregistry.WithBuiltInPlugins(ps)) - assert.NoError(t, err) + svcRegistry := testutils.NewTestPlugins() logger := testutils.SetupLoggerWithBuffer() - systemService := systems.NewFakeService(logger) _, grpcClient := testutils.NewGRPCSuite(t, func(s *grpc.Server) { diff --git a/test/integration/event-processor/reconciliation_test.go b/test/integration/event-processor/reconciliation_test.go index 57cc29a5..5823456c 100644 --- a/test/integration/event-processor/reconciliation_test.go +++ b/test/integration/event-processor/reconciliation_test.go @@ -25,11 +25,9 @@ import ( eventprocessor "github.com/openkcm/cmk/internal/event-processor" eventProto "github.com/openkcm/cmk/internal/event-processor/proto" "github.com/openkcm/cmk/internal/model" - cmkpluginregistry "github.com/openkcm/cmk/internal/pluginregistry" "github.com/openkcm/cmk/internal/repo" sqlPkg "github.com/openkcm/cmk/internal/repo/sql" "github.com/openkcm/cmk/internal/testutils" - "github.com/openkcm/cmk/internal/testutils/testplugins" cmkcontext "github.com/openkcm/cmk/utils/context" "github.com/openkcm/cmk/utils/ptr" ) @@ -55,7 +53,7 @@ func setupTest(t *testing.T) tester { }, ) - ps, psCfg := testutils.NewTestPlugins(testplugins.NewKeystoreOperator()) + svcRegistry := testutils.NewTestPlugins() cfg := config.Config{ EventProcessor: config.EventProcessor{ @@ -81,13 +79,9 @@ func setupTest(t *testing.T) tester { }, }, }, - Plugins: psCfg, Database: dbConf, } - svcRegistry, err := cmkpluginregistry.New(t.Context(), &cfg, cmkpluginregistry.WithBuiltInPlugins(ps)) - require.NoError(t, err) - r := sqlPkg.NewRepository(db) reconcilerCtx, cancelFunc := context.WithCancel(t.Context()) diff --git a/test/integration/tenant-manager/provisioning_test.go b/test/integration/tenant-manager/provisioning_test.go index 9b5f9561..53d35eec 100644 --- a/test/integration/tenant-manager/provisioning_test.go +++ b/test/integration/tenant-manager/provisioning_test.go @@ -22,10 +22,8 @@ import ( eventprocessor "github.com/openkcm/cmk/internal/event-processor" "github.com/openkcm/cmk/internal/manager" "github.com/openkcm/cmk/internal/model" - cmkpluginregistry "github.com/openkcm/cmk/internal/pluginregistry" "github.com/openkcm/cmk/internal/repo/sql" "github.com/openkcm/cmk/internal/testutils" - "github.com/openkcm/cmk/internal/testutils/testplugins" integrationutils "github.com/openkcm/cmk/test/integration/integration_utils" "github.com/openkcm/cmk/utils/base62" cmkcontext "github.com/openkcm/cmk/utils/context" @@ -51,12 +49,8 @@ func (s *DBSuite) SetupSuite() { ctx := s.T().Context() - ps, psCfg := testutils.NewTestPlugins(testplugins.NewIdentityManagement()) - cfg := &config.Config{ - Plugins: psCfg, - } - svcRegistry, err := cmkpluginregistry.New(ctx, cfg, cmkpluginregistry.WithBuiltInPlugins(ps)) - s.NoError(err) + svcRegistry := testutils.NewTestPlugins() + cfg := &config.Config{} f, err := clients.NewFactory(config.Services{}) s.NoError(err) diff --git a/test/security/xss/key_controller_test.go b/test/security/xss/key_controller_test.go index af6fff77..a7ae93fc 100644 --- a/test/security/xss/key_controller_test.go +++ b/test/security/xss/key_controller_test.go @@ -6,7 +6,6 @@ import ( "net/http" "testing" - "github.com/openkcm/plugin-sdk/pkg/catalog" "github.com/stretchr/testify/assert" multitenancy "github.com/bartventer/gorm-multitenancy/v8" @@ -16,7 +15,6 @@ import ( "github.com/openkcm/cmk/internal/model" "github.com/openkcm/cmk/internal/repo/sql" "github.com/openkcm/cmk/internal/testutils" - "github.com/openkcm/cmk/internal/testutils/testplugins" cmkcontext "github.com/openkcm/cmk/utils/context" "github.com/openkcm/cmk/utils/ptr" ) @@ -41,8 +39,7 @@ func startAPIAndDBForKey(t *testing.T) (*multitenancy.DB, cmkapi.ServeMux, strin dbConfig := testutils.TestDBConfig{} db, tenants, _ := testutils.NewTestDB(t, dbConfig) - sv := testutils.NewAPIServer(t, db, - testutils.TestAPIServerConfig{Plugins: []catalog.BuiltInPlugin{testplugins.NewKeystoreOperator()}}) + sv := testutils.NewAPIServer(t, db, testutils.TestAPIServerConfig{}) return db, sv, tenants[0] }