diff --git a/system/service/dal_connection.go b/system/service/dal_connection.go index 05dd5fa88..aca8c9cf7 100644 --- a/system/service/dal_connection.go +++ b/system/service/dal_connection.go @@ -145,22 +145,6 @@ func (svc *dalConnection) Update(ctx context.Context, upd *types.DalConnection) return fmt.Errorf("can not update connection parameters for primary connection") } - if old.Handle != upd.Handle { - return fmt.Errorf("can not update handle for primary connection") - } - - if old.Config.DefaultModelIdent != upd.Config.DefaultModelIdent { - return fmt.Errorf("can not update defaultModelIdent for primary connection") - } - - if old.Config.DefaultAttributeIdent != upd.Config.DefaultAttributeIdent { - return fmt.Errorf("can not update defaultAttributeIdent for primary connection") - } - - if old.Handle != upd.Handle { - return fmt.Errorf("can not update handle for primary connection") - } - if old.Type != upd.Type { return fmt.Errorf("can not update type for primary connection") } @@ -245,7 +229,8 @@ func (svc *dalConnection) UndeleteByID(ctx context.Context, ID uint64) (err erro } // We're creating it here since it was removed on delete - return dalConnectionRemove(ctx, svc.dal, c) + // primary connection can't be deleted we're just using nil here. + return dalConnectionReplace(ctx, nil, svc.dal, c) }() return svc.recordAction(ctx, cProps, DalConnectionActionDelete, err) diff --git a/tests/dal/dal_codec_alias_test.go b/tests/dal/dal_codec_alias_test.go index 86d30d59b..7fbdf4e49 100644 --- a/tests/dal/dal_codec_alias_test.go +++ b/tests/dal/dal_codec_alias_test.go @@ -44,8 +44,8 @@ func Test_dal_codec_alias(t *testing.T) { rIn.Values = rIn.Values.Set(&types.RecordValue{Name: "intr_vDate", Value: "2022-01-01"}) rIn.Values = rIn.Values.Set(&types.RecordValue{Name: "intr_vNumber", Value: "2423423"}) rIn.Values = rIn.Values.Set(&types.RecordValue{Name: "intr_vText", Value: "lorm ipsum "}) - rIn.Values = rIn.Values.Set(&types.RecordValue{Name: "intr_vBoolean_T", Value: "true"}) - rIn.Values = rIn.Values.Set(&types.RecordValue{Name: "intr_vBoolean_F", Value: "false"}) + rIn.Values = rIn.Values.Set(&types.RecordValue{Name: "intr_vBoolean_T", Value: "1"}) + rIn.Values = rIn.Values.Set(&types.RecordValue{Name: "intr_vBoolean_F", Value: ""}) rIn.Values = rIn.Values.Set(&types.RecordValue{Name: "intr_vEnum", Value: "abc"}) rIn.Values = rIn.Values.Set(&types.RecordValue{Name: "intr_vGeometry", Value: `{"lat":1,"lng":1}`}) rIn.Values = rIn.Values.Set(&types.RecordValue{Name: "intr_vJSON", Value: `[{"bool":true"}]`}) @@ -53,7 +53,7 @@ func Test_dal_codec_alias(t *testing.T) { rIn.Values = rIn.Values.Set(&types.RecordValue{Name: "intr_vUUID", Value: "ba485865-54f9-44de-bde8-6965556c022a"}) bootstrap(t, func(ctx context.Context, t *testing.T, h helper, svc dalService) { - h.a.NoError(svc.CreateModel(ctx, model)) + h.a.NoError(svc.ReplaceModel(ctx, model)) h.a.NoError(svc.Create(ctx, model.ToFilter(), capabilities.CreateCapabilities(model.Capabilities...), &rIn)) h.a.NoError(svc.Lookup(ctx, model.ToFilter(), capabilities.LookupCapabilities(model.Capabilities...), dal.PKValues{"id": rIn.ID}, &rOut)) diff --git a/tests/dal/dal_codec_json_test.go b/tests/dal/dal_codec_json_test.go index c1955a41e..f52a4b712 100644 --- a/tests/dal/dal_codec_json_test.go +++ b/tests/dal/dal_codec_json_test.go @@ -44,8 +44,8 @@ func Test_dal_codec_json(t *testing.T) { rIn.Values = rIn.Values.Set(&types.RecordValue{Name: "vDate", Value: "2022-01-01"}) rIn.Values = rIn.Values.Set(&types.RecordValue{Name: "vNumber", Value: "2423423"}) rIn.Values = rIn.Values.Set(&types.RecordValue{Name: "vText", Value: "lorm ipsum "}) - rIn.Values = rIn.Values.Set(&types.RecordValue{Name: "vBoolean_T", Value: "true"}) - rIn.Values = rIn.Values.Set(&types.RecordValue{Name: "vBoolean_F", Value: "false"}) + rIn.Values = rIn.Values.Set(&types.RecordValue{Name: "vBoolean_T", Value: "1"}) + rIn.Values = rIn.Values.Set(&types.RecordValue{Name: "vBoolean_F", Value: ""}) rIn.Values = rIn.Values.Set(&types.RecordValue{Name: "vEnum", Value: "abc"}) rIn.Values = rIn.Values.Set(&types.RecordValue{Name: "vGeometry", Value: `{"lat":1,"lng":1}`}) rIn.Values = rIn.Values.Set(&types.RecordValue{Name: "vJSON", Value: `[{"bool":true"}]`}) @@ -53,7 +53,7 @@ func Test_dal_codec_json(t *testing.T) { rIn.Values = rIn.Values.Set(&types.RecordValue{Name: "vUUID", Value: "ba485865-54f9-44de-bde8-6965556c022a"}) bootstrap(t, func(ctx context.Context, t *testing.T, h helper, svc dalService) { - h.a.NoError(svc.CreateModel(ctx, model)) + h.a.NoError(svc.ReplaceModel(ctx, model)) h.a.NoError(svc.Create(ctx, model.ToFilter(), capabilities.CreateCapabilities(model.Capabilities...), &rIn)) h.a.NoError(svc.Lookup(ctx, model.ToFilter(), capabilities.LookupCapabilities(model.Capabilities...), dal.PKValues{"id": rIn.ID}, &rOut)) diff --git a/tests/dal/dal_codec_plain_test.go b/tests/dal/dal_codec_plain_test.go index 3cfa1487c..236e83b4e 100644 --- a/tests/dal/dal_codec_plain_test.go +++ b/tests/dal/dal_codec_plain_test.go @@ -44,8 +44,8 @@ func Test_dal_codec_plain(t *testing.T) { rIn.Values = rIn.Values.Set(&types.RecordValue{Name: "vDate", Value: "2022-01-01"}) rIn.Values = rIn.Values.Set(&types.RecordValue{Name: "vNumber", Value: "2423423"}) rIn.Values = rIn.Values.Set(&types.RecordValue{Name: "vText", Value: "lorm ipsum "}) - rIn.Values = rIn.Values.Set(&types.RecordValue{Name: "vBoolean_T", Value: "true"}) - rIn.Values = rIn.Values.Set(&types.RecordValue{Name: "vBoolean_F", Value: "false"}) + rIn.Values = rIn.Values.Set(&types.RecordValue{Name: "vBoolean_T", Value: "1"}) + rIn.Values = rIn.Values.Set(&types.RecordValue{Name: "vBoolean_F", Value: ""}) rIn.Values = rIn.Values.Set(&types.RecordValue{Name: "vEnum", Value: "abc"}) rIn.Values = rIn.Values.Set(&types.RecordValue{Name: "vGeometry", Value: `{"lat":1,"lng":1}`}) rIn.Values = rIn.Values.Set(&types.RecordValue{Name: "vJSON", Value: `[{"bool":true"}]`}) @@ -53,7 +53,7 @@ func Test_dal_codec_plain(t *testing.T) { rIn.Values = rIn.Values.Set(&types.RecordValue{Name: "vUUID", Value: "ba485865-54f9-44de-bde8-6965556c022a"}) bootstrap(t, func(ctx context.Context, t *testing.T, h helper, svc dalService) { - h.a.NoError(svc.CreateModel(ctx, model)) + h.a.NoError(svc.ReplaceModel(ctx, model)) h.a.NoError(svc.Create(ctx, model.ToFilter(), capabilities.CreateCapabilities(model.Capabilities...), &rIn)) h.a.NoError(svc.Lookup(ctx, model.ToFilter(), capabilities.LookupCapabilities(model.Capabilities...), dal.PKValues{"id": rIn.ID}, &rOut)) @@ -108,7 +108,7 @@ func benchmark_dal_codec_plain(b *testing.B, count int) { rIn.Values = rIn.Values.Set(&types.RecordValue{Name: "vUUID", Value: "ba485865-54f9-44de-bde8-6965556c022a"}) bootstrapBenchmark(b, func(ctx context.Context, b *testing.B, h helper, svc dalService) { - h.a.NoError(svc.CreateModel(ctx, model)) + h.a.NoError(svc.ReplaceModel(ctx, model)) ctr := uint64(1) for rep := 0; rep < b.N; rep++ { diff --git a/tests/dal/dal_crud_compose_record_test.go b/tests/dal/dal_crud_compose_record_test.go index 6209deb26..3d26b958d 100644 --- a/tests/dal/dal_crud_compose_record_test.go +++ b/tests/dal/dal_crud_compose_record_test.go @@ -18,15 +18,8 @@ func Test_dal_crud_compose_record_create(t *testing.T) { ctx := h.secCtx() - helpers.AllowMe(h, types.NamespaceRbacResource(0), "module.create") - helpers.AllowMe(h, types.NamespaceRbacResource(0), "modules.search") - helpers.AllowMe(h, types.ModuleRbacResource(0, 0), "read") - helpers.AllowMe(h, types.ModuleRbacResource(0, 0), "update") - helpers.AllowMe(h, types.ModuleRbacResource(0, 0), "delete") - helpers.AllowMe(h, types.ModuleRbacResource(0, 0), "record.create") - helpers.AllowMe(h, types.ModuleRbacResource(0, 0), "records.search") - helpers.AllowMe(h, types.ModuleFieldRbacResource(0, 0, 0), "record.value.update") - helpers.AllowMe(h, types.ModuleFieldRbacResource(0, 0, 0), "record.value.read") + helpers.AllowMeModuleCRUD(h) + helpers.AllowMeRecordCRUD(h) ns := h.createNamespace("test") module := createModuleFromGenerics(ctx, t, "ok_module.json", ns.ID, &types.ModelConfig{ @@ -84,16 +77,8 @@ func Test_dal_crud_compose_record_update(t *testing.T) { ctx := h.secCtx() - helpers.AllowMe(h, types.NamespaceRbacResource(0), "module.create") - helpers.AllowMe(h, types.NamespaceRbacResource(0), "modules.search") - helpers.AllowMe(h, types.ModuleRbacResource(0, 0), "read") - helpers.AllowMe(h, types.ModuleRbacResource(0, 0), "update") - helpers.AllowMe(h, types.ModuleRbacResource(0, 0), "delete") - helpers.AllowMe(h, types.ModuleRbacResource(0, 0), "record.create") - helpers.AllowMe(h, types.ModuleRbacResource(0, 0), "records.search") - helpers.AllowMe(h, types.ModuleFieldRbacResource(0, 0, 0), "record.value.update") - helpers.AllowMe(h, types.ModuleFieldRbacResource(0, 0, 0), "record.value.read") - helpers.AllowMe(h, types.RecordRbacResource(0, 0, 0), "update") + helpers.AllowMeModuleCRUD(h) + helpers.AllowMeRecordCRUD(h) ns := h.createNamespace("test") module := createModuleFromGenerics(ctx, t, "ok_module.json", ns.ID, &types.ModelConfig{ @@ -151,17 +136,8 @@ func Test_dal_crud_compose_record_delete(t *testing.T) { ctx := h.secCtx() - helpers.AllowMe(h, types.NamespaceRbacResource(0), "module.create") - helpers.AllowMe(h, types.NamespaceRbacResource(0), "modules.search") - helpers.AllowMe(h, types.ModuleRbacResource(0, 0), "read") - helpers.AllowMe(h, types.ModuleRbacResource(0, 0), "update") - helpers.AllowMe(h, types.ModuleRbacResource(0, 0), "delete") - helpers.AllowMe(h, types.ModuleRbacResource(0, 0), "record.create") - helpers.AllowMe(h, types.ModuleRbacResource(0, 0), "records.search") - helpers.AllowMe(h, types.ModuleFieldRbacResource(0, 0, 0), "record.value.update") - helpers.AllowMe(h, types.ModuleFieldRbacResource(0, 0, 0), "record.value.read") - helpers.AllowMe(h, types.RecordRbacResource(0, 0, 0), "delete") - helpers.AllowMe(h, types.RecordRbacResource(0, 0, 0), "read") + helpers.AllowMeModuleCRUD(h) + helpers.AllowMeRecordCRUD(h) ns := h.createNamespace("test") module := createModuleFromGenerics(ctx, t, "ok_module.json", ns.ID, &types.ModelConfig{ diff --git a/tests/dal/dal_crud_connection_test.go b/tests/dal/dal_crud_connection_test.go index 2b9e2fd2b..e83897f5d 100644 --- a/tests/dal/dal_crud_connection_test.go +++ b/tests/dal/dal_crud_connection_test.go @@ -14,8 +14,7 @@ func Test_dal_crud_connection_list(t *testing.T) { h := newHelperT(t) defer h.cleanupDal() - helpers.AllowMe(h, types.ComponentRbacResource(), "dal-connections.search") - helpers.AllowMe(h, types.DalConnectionRbacResource(0), "read") + helpers.AllowMeDalConnectionSearch(h) h.apiInit(). Get("/system/dal/connections/"). @@ -87,7 +86,7 @@ func Test_dal_crud_connection_create_invalid_type(t *testing.T) { Header("Content-Type", "application/json"). Expect(t). Status(http.StatusOK). - Assert(helpers.AssertErrorP("corteza::system:primary_dal_connection")). + Assert(helpers.AssertErrorP("corteza::system:primary-dal-connection")). End() } diff --git a/tests/dal/dal_crud_issues_compose_module_test.go b/tests/dal/dal_crud_issues_compose_module_test.go index 655ab7a98..5dbc91057 100644 --- a/tests/dal/dal_crud_issues_compose_module_test.go +++ b/tests/dal/dal_crud_issues_compose_module_test.go @@ -6,8 +6,6 @@ import ( "net/http" "testing" - "github.com/cortezaproject/corteza-server/compose/types" - systemTypes "github.com/cortezaproject/corteza-server/system/types" "github.com/cortezaproject/corteza-server/tests/helpers" jsonpath "github.com/steinfletcher/apitest-jsonpath" ) @@ -16,14 +14,8 @@ func Test_dal_crud_issues_compose_module_missing_sensitivity(t *testing.T) { h := newHelperT(t) defer h.cleanupDal() - helpers.AllowMe(h, types.NamespaceRbacResource(0), "module.create") - helpers.AllowMe(h, types.NamespaceRbacResource(0), "modules.search") - helpers.AllowMe(h, types.ModuleRbacResource(0, 0), "read") - helpers.AllowMe(h, types.ModuleRbacResource(0, 0), "update") - helpers.AllowMe(h, types.ModuleRbacResource(0, 0), "delete") - + helpers.AllowMeModuleCRUD(h) ns := h.createNamespace("test") - aux := &composeModuleRestRsp{} rsp := h.apiInit(). @@ -79,14 +71,8 @@ func Test_dal_crud_issues_compose_module_field_missing_sensitivity(t *testing.T) h := newHelperT(t) defer h.cleanupDal() - helpers.AllowMe(h, types.NamespaceRbacResource(0), "module.create") - helpers.AllowMe(h, types.NamespaceRbacResource(0), "modules.search") - helpers.AllowMe(h, types.ModuleRbacResource(0, 0), "read") - helpers.AllowMe(h, types.ModuleRbacResource(0, 0), "update") - helpers.AllowMe(h, types.ModuleRbacResource(0, 0), "delete") - + helpers.AllowMeModuleCRUD(h) ns := h.createNamespace("test") - aux := &composeModuleRestRsp{} rsp := h.apiInit(). @@ -141,17 +127,8 @@ func Test_dal_crud_issues_compose_module_nok_connection(t *testing.T) { h := newHelperT(t) defer h.cleanupDal() - helpers.AllowMe(h, types.NamespaceRbacResource(0), "module.create") - helpers.AllowMe(h, types.NamespaceRbacResource(0), "modules.search") - helpers.AllowMe(h, types.ModuleRbacResource(0, 0), "read") - helpers.AllowMe(h, types.ModuleRbacResource(0, 0), "update") - helpers.AllowMe(h, types.ModuleRbacResource(0, 0), "delete") - - helpers.AllowMe(h, systemTypes.ComponentRbacResource(), "dal-connection.create") - helpers.AllowMe(h, systemTypes.ComponentRbacResource(), "dal-connections.search") - helpers.AllowMe(h, systemTypes.DalConnectionRbacResource(0), "read") - helpers.AllowMe(h, systemTypes.DalConnectionRbacResource(0), "update") - helpers.AllowMe(h, systemTypes.DalConnectionRbacResource(0), "delete") + helpers.AllowMeModuleCRUD(h) + helpers.AllowMeDalConnectionCRUD(h) ns := h.createNamespace("test") conn := createConnectionFromGenerics(h.secCtx(), t, "nok_connection_connectivity.json") diff --git a/tests/dal/dal_crud_issues_compose_record_test.go b/tests/dal/dal_crud_issues_compose_record_test.go index a1b73830b..3806089fb 100644 --- a/tests/dal/dal_crud_issues_compose_record_test.go +++ b/tests/dal/dal_crud_issues_compose_record_test.go @@ -7,7 +7,6 @@ import ( "github.com/cortezaproject/corteza-server/compose/types" "github.com/cortezaproject/corteza-server/pkg/dal/capabilities" - systemTypes "github.com/cortezaproject/corteza-server/system/types" "github.com/cortezaproject/corteza-server/tests/helpers" ) @@ -15,20 +14,9 @@ func Test_dal_crud_issues_compose_record_nok_connection(t *testing.T) { h := newHelperT(t) defer h.cleanupDal() - helpers.AllowMe(h, systemTypes.ComponentRbacResource(), "dal-connection.create") - helpers.AllowMe(h, systemTypes.ComponentRbacResource(), "dal-connections.search") - helpers.AllowMe(h, systemTypes.DalConnectionRbacResource(0), "read") - helpers.AllowMe(h, systemTypes.DalConnectionRbacResource(0), "update") - helpers.AllowMe(h, systemTypes.DalConnectionRbacResource(0), "delete") - helpers.AllowMe(h, types.NamespaceRbacResource(0), "module.create") - helpers.AllowMe(h, types.NamespaceRbacResource(0), "modules.search") - helpers.AllowMe(h, types.ModuleRbacResource(0, 0), "read") - helpers.AllowMe(h, types.ModuleRbacResource(0, 0), "update") - helpers.AllowMe(h, types.ModuleRbacResource(0, 0), "delete") - helpers.AllowMe(h, types.ModuleRbacResource(0, 0), "record.create") - helpers.AllowMe(h, types.ModuleRbacResource(0, 0), "records.search") - helpers.AllowMe(h, types.ModuleFieldRbacResource(0, 0, 0), "record.value.update") - helpers.AllowMe(h, types.ModuleFieldRbacResource(0, 0, 0), "record.value.read") + helpers.AllowMeDalConnectionCRUD(h) + helpers.AllowMeModuleCRUD(h) + helpers.AllowMeRecordCRUD(h) ns := h.createNamespace("test") @@ -53,20 +41,9 @@ func Test_dal_crud_issues_compose_record_nok_model(t *testing.T) { h := newHelperT(t) defer h.cleanupDal() - helpers.AllowMe(h, systemTypes.ComponentRbacResource(), "dal-connection.create") - helpers.AllowMe(h, systemTypes.ComponentRbacResource(), "dal-connections.search") - helpers.AllowMe(h, systemTypes.DalConnectionRbacResource(0), "read") - helpers.AllowMe(h, systemTypes.DalConnectionRbacResource(0), "update") - helpers.AllowMe(h, systemTypes.DalConnectionRbacResource(0), "delete") - helpers.AllowMe(h, types.NamespaceRbacResource(0), "module.create") - helpers.AllowMe(h, types.NamespaceRbacResource(0), "modules.search") - helpers.AllowMe(h, types.ModuleRbacResource(0, 0), "read") - helpers.AllowMe(h, types.ModuleRbacResource(0, 0), "update") - helpers.AllowMe(h, types.ModuleRbacResource(0, 0), "delete") - helpers.AllowMe(h, types.ModuleRbacResource(0, 0), "record.create") - helpers.AllowMe(h, types.ModuleRbacResource(0, 0), "records.search") - helpers.AllowMe(h, types.ModuleFieldRbacResource(0, 0, 0), "record.value.update") - helpers.AllowMe(h, types.ModuleFieldRbacResource(0, 0, 0), "record.value.read") + helpers.AllowMeDalConnectionCRUD(h) + helpers.AllowMeModuleCRUD(h) + helpers.AllowMeRecordCRUD(h) ns := h.createNamespace("test") @@ -91,20 +68,9 @@ func Test_dal_crud_issues_compose_record_ok(t *testing.T) { h := newHelperT(t) defer h.cleanupDal() - helpers.AllowMe(h, systemTypes.ComponentRbacResource(), "dal-connection.create") - helpers.AllowMe(h, systemTypes.ComponentRbacResource(), "dal-connections.search") - helpers.AllowMe(h, systemTypes.DalConnectionRbacResource(0), "read") - helpers.AllowMe(h, systemTypes.DalConnectionRbacResource(0), "update") - helpers.AllowMe(h, systemTypes.DalConnectionRbacResource(0), "delete") - helpers.AllowMe(h, types.NamespaceRbacResource(0), "module.create") - helpers.AllowMe(h, types.NamespaceRbacResource(0), "modules.search") - helpers.AllowMe(h, types.ModuleRbacResource(0, 0), "read") - helpers.AllowMe(h, types.ModuleRbacResource(0, 0), "update") - helpers.AllowMe(h, types.ModuleRbacResource(0, 0), "delete") - helpers.AllowMe(h, types.ModuleRbacResource(0, 0), "record.create") - helpers.AllowMe(h, types.ModuleRbacResource(0, 0), "records.search") - helpers.AllowMe(h, types.ModuleFieldRbacResource(0, 0, 0), "record.value.update") - helpers.AllowMe(h, types.ModuleFieldRbacResource(0, 0, 0), "record.value.read") + helpers.AllowMeDalConnectionCRUD(h) + helpers.AllowMeModuleCRUD(h) + helpers.AllowMeRecordCRUD(h) ns := h.createNamespace("test") diff --git a/tests/dal/dal_crud_issues_connection_test.go b/tests/dal/dal_crud_issues_connection_test.go index b02b4f6d4..bab428998 100644 --- a/tests/dal/dal_crud_issues_connection_test.go +++ b/tests/dal/dal_crud_issues_connection_test.go @@ -6,7 +6,6 @@ import ( "net/http" "testing" - "github.com/cortezaproject/corteza-server/system/types" "github.com/cortezaproject/corteza-server/tests/helpers" jsonpath "github.com/steinfletcher/apitest-jsonpath" ) @@ -15,11 +14,7 @@ func Test_dal_crud_issues_connection_connectivity(t *testing.T) { h := newHelperT(t) defer h.cleanupDal() - helpers.AllowMe(h, types.ComponentRbacResource(), "dal-connection.create") - helpers.AllowMe(h, types.ComponentRbacResource(), "dal-connections.search") - helpers.AllowMe(h, types.DalConnectionRbacResource(0), "read") - helpers.AllowMe(h, types.DalConnectionRbacResource(0), "update") - helpers.AllowMe(h, types.DalConnectionRbacResource(0), "delete") + helpers.AllowMeDalConnectionCRUD(h) aux := &dalConnectionRestRsp{} @@ -76,11 +71,7 @@ func Test_dal_crud_issues_connection_sensitivity(t *testing.T) { h := newHelperT(t) defer h.cleanupDal() - helpers.AllowMe(h, types.ComponentRbacResource(), "dal-connection.create") - helpers.AllowMe(h, types.ComponentRbacResource(), "dal-connections.search") - helpers.AllowMe(h, types.DalConnectionRbacResource(0), "read") - helpers.AllowMe(h, types.DalConnectionRbacResource(0), "update") - helpers.AllowMe(h, types.DalConnectionRbacResource(0), "delete") + helpers.AllowMeDalConnectionCRUD(h) aux := &dalConnectionRestRsp{} diff --git a/tests/dal/dal_record_create_test.go b/tests/dal/dal_record_create_test.go deleted file mode 100644 index 34f524732..000000000 --- a/tests/dal/dal_record_create_test.go +++ /dev/null @@ -1 +0,0 @@ -package dal diff --git a/tests/dal/dal_utils.go b/tests/dal/dal_utils.go index 73526a6db..6a44b4f1e 100644 --- a/tests/dal/dal_utils.go +++ b/tests/dal/dal_utils.go @@ -30,29 +30,27 @@ type ( dalService interface { Drivers() (drivers []dal.Driver) - ReloadSensitivityLevels(levels ...dal.SensitivityLevel) (err error) - CreateSensitivityLevel(levels ...dal.SensitivityLevel) (err error) - UpdateSensitivityLevel(levels ...dal.SensitivityLevel) (err error) - DeleteSensitivityLevel(levels ...dal.SensitivityLevel) (err error) - CreateConnection(ctx context.Context, connectionID uint64, cp dal.ConnectionParams, cm dal.ConnectionMeta, capabilities ...capabilities.Capability) (err error) - DeleteConnection(ctx context.Context, connectionID uint64) (err error) - UpdateConnection(ctx context.Context, connectionID uint64, cp dal.ConnectionParams, cm dal.ConnectionMeta, capabilities ...capabilities.Capability) (err error) + + ReplaceSensitivityLevel(levels ...dal.SensitivityLevel) (err error) + RemoveSensitivityLevel(levelIDs ...uint64) (err error) + + ReplaceConnection(ctx context.Context, cw *dal.ConnectionWrap, isDefault bool) (err error) + RemoveConnection(ctx context.Context, ID uint64) (err error) + + SearchModels(ctx context.Context) (out dal.ModelSet, err error) + ReplaceModel(ctx context.Context, model *dal.Model) (err error) + RemoveModel(ctx context.Context, connectionID, ID uint64) (err error) + ReplaceModelAttribute(ctx context.Context, model *dal.Model, old, new *dal.Attribute, trans ...dal.TransformationFunction) (err error) + FindModelByResourceID(connectionID uint64, resourceID uint64) *dal.Model + FindModelByResourceIdent(connectionID uint64, resourceType, resourceIdent string) *dal.Model + FindModelByIdent(connectionID uint64, ident string) *dal.Model + Create(ctx context.Context, mf dal.ModelFilter, capabilities capabilities.Set, rr ...dal.ValueGetter) (err error) Update(ctx context.Context, mf dal.ModelFilter, capabilities capabilities.Set, rr ...dal.ValueGetter) (err error) Search(ctx context.Context, mf dal.ModelFilter, capabilities capabilities.Set, f filter.Filter) (iter dal.Iterator, err error) Lookup(ctx context.Context, mf dal.ModelFilter, capabilities capabilities.Set, lookup dal.ValueGetter, dst dal.ValueSetter) (err error) Delete(ctx context.Context, mf dal.ModelFilter, capabilities capabilities.Set, vv ...dal.ValueGetter) (err error) Truncate(ctx context.Context, mf dal.ModelFilter, capabilities capabilities.Set) (err error) - ReloadModel(ctx context.Context, models ...*dal.Model) (err error) - SearchModels(ctx context.Context) (out dal.ModelSet, err error) - CreateModel(ctx context.Context, models ...*dal.Model) (err error) - DeleteModel(ctx context.Context, models ...*dal.Model) (err error) - UpdateModel(ctx context.Context, old, new *dal.Model) (err error) - UpdateModelAttribute(ctx context.Context, model *dal.Model, old, new *dal.Attribute, trans ...dal.TransformationFunction) (err error) - ModelIdentFormatter(connectionID uint64) (f *dal.IdentFormatter, err error) - FindModelByResourceID(connectionID uint64, resourceID uint64) *dal.Model - FindModelByResourceIdent(connectionID uint64, resourceType, resourceIdent string) *dal.Model - FindModelByIdent(connectionID uint64, ident string) *dal.Model SearchConnectionIssues(connectionID uint64) (out []error) SearchModelIssues(connectionID, resourceID uint64) (out []error) @@ -131,6 +129,7 @@ func (h helper) cleanupDal() { } h.a.NoError(store.DeleteDalConnectionByID(ctx, ds, c.ID)) } + dd.Purge(ctx) h.a.NoError(service.DefaultDalConnection.ReloadConnections(ctx)) h.a.NoError(composeService.DefaultModule.ReloadDALModels(ctx)) @@ -147,15 +146,15 @@ func initSvc(ctx context.Context, d driver) (dalService, error) { Label: c.Handle, } - svc, err := dal.New( - ctx, - zap.NewNop(), - false, - c.ID, - c.Config.Connection, - cm, - capabilities.FullCapabilities()..., - ) + svc, err := dal.New(zap.NewNop(), false) + if err != nil { + return nil, err + } + + err = svc.ReplaceConnection(ctx, dal.MakeConnection(c.ID, nil, c.Config.Connection, cm, capabilities.FullCapabilities()...), true) + if err != nil { + return nil, err + } return svc, err } @@ -233,7 +232,7 @@ func bootstrapWithModel(rootTest *testing.T, ident string, run func(context.Cont driver.setup(ctx, rootTest, driver.dsn) - require.NoError(t, svc.CreateModel(ctx, model)) + require.NoError(t, svc.ReplaceModel(ctx, model)) run(ctx, t, h, svc, model) }) diff --git a/tests/dal/helper.go b/tests/dal/helper.go index 09e019178..08cfff0a2 100644 --- a/tests/dal/helper.go +++ b/tests/dal/helper.go @@ -138,6 +138,7 @@ func (h helper) createSensitivityLevel(res *types.DalSensitivityLevel) *types.Da } h.a.NoError(service.DefaultStore.CreateDalSensitivityLevel(context.Background(), res)) + h.a.NoError(service.DefaultDalSensitivityLevel.ReloadSensitivityLevels(context.Background(), service.DefaultStore)) return res } diff --git a/tests/dal/main_test.go b/tests/dal/main_test.go index 85c135f1f..ec9d0afc2 100644 --- a/tests/dal/main_test.go +++ b/tests/dal/main_test.go @@ -75,6 +75,10 @@ func InitTestApp() { return nil }) + + if err := testApp.Activate(ctx); err != nil { + panic(fmt.Errorf("could not activate corteza: %v", err)) + } } hh = &handlers.AuthHandlers{ diff --git a/tests/dal/testdata/dal_crud_connection_update_primary/connection.json b/tests/dal/testdata/dal_crud_connection_update_primary/connection.json index 7de858cf6..83a97550e 100644 --- a/tests/dal/testdata/dal_crud_connection_update_primary/connection.json +++ b/tests/dal/testdata/dal_crud_connection_update_primary/connection.json @@ -1,7 +1,7 @@ { "name": "Primary Connection EDITED", "handle": "primary_connection", - "type": "corteza::system:primary_dal_connection", + "type": "corteza::system:primary-dal-connection", "location": { "geometry": { "type": "", diff --git a/tests/dal/testdata/generic/nok_connection_connectivity.json b/tests/dal/testdata/generic/nok_connection_connectivity.json index 6f30b8ad0..db818f7f3 100644 --- a/tests/dal/testdata/generic/nok_connection_connectivity.json +++ b/tests/dal/testdata/generic/nok_connection_connectivity.json @@ -1,7 +1,7 @@ { "name": "Test Connection", "handle": "test_connection", - "type": "corteza::system:dal_connection", + "type": "corteza::system:dal-connection", "location": { "geometry": { "type": "", diff --git a/tests/dal/testdata/generic/nok_connection_invalid_type.json b/tests/dal/testdata/generic/nok_connection_invalid_type.json index 774b6c291..708c1ba48 100644 --- a/tests/dal/testdata/generic/nok_connection_invalid_type.json +++ b/tests/dal/testdata/generic/nok_connection_invalid_type.json @@ -1,7 +1,7 @@ { "name": "Test Connection", "handle": "test_connection", - "type": "corteza::system:primary_dal_connection", + "type": "corteza::system:primary-dal-connection", "location": { "geometry": { "type": "", diff --git a/tests/dal/testdata/generic/nok_connection_sensitivity.json b/tests/dal/testdata/generic/nok_connection_sensitivity.json index 372e9c5d6..1c39e2cf9 100644 --- a/tests/dal/testdata/generic/nok_connection_sensitivity.json +++ b/tests/dal/testdata/generic/nok_connection_sensitivity.json @@ -1,7 +1,7 @@ { "name": "Test Connection", "handle": "test_connection", - "type": "corteza::system:dal_connection", + "type": "corteza::system:dal-connection", "location": { "geometry": { "type": "", diff --git a/tests/dal/testdata/generic/ok_connection.json b/tests/dal/testdata/generic/ok_connection.json index 9ca7ad91f..187696e8b 100644 --- a/tests/dal/testdata/generic/ok_connection.json +++ b/tests/dal/testdata/generic/ok_connection.json @@ -1,7 +1,7 @@ { "name": "Test Connection", "handle": "test_connection", - "type": "corteza::system:dal_connection", + "type": "corteza::system:dal-connection", "location": { "geometry": { "type": "", diff --git a/tests/dal/testdata/generic/ok_connection_update.json b/tests/dal/testdata/generic/ok_connection_update.json index a02bc6c76..4364d9f60 100644 --- a/tests/dal/testdata/generic/ok_connection_update.json +++ b/tests/dal/testdata/generic/ok_connection_update.json @@ -1,7 +1,7 @@ { "name": "Test Connection EDITED", "handle": "test_connection_edited", - "type": "corteza::system:dal_connection", + "type": "corteza::system:dal-connection", "location": { "geometry": { "type": "", diff --git a/tests/helpers/rbac.go b/tests/helpers/rbac.go index f7739ab80..0d004ba86 100644 --- a/tests/helpers/rbac.go +++ b/tests/helpers/rbac.go @@ -3,6 +3,7 @@ package helpers import ( "context" + composeTypes "github.com/cortezaproject/corteza-server/compose/types" "github.com/cortezaproject/corteza-server/pkg/auth" "github.com/cortezaproject/corteza-server/pkg/cli" "github.com/cortezaproject/corteza-server/pkg/eventbus" @@ -63,3 +64,45 @@ func Deny(role *types.Role, r string, oo ...string) { func Grant(rr ...*rbac.Rule) { cli.HandleError(rbac.Global().Grant(context.Background(), rr...)) } + +// Common RBAC presets + +func AllowMeModuleCreate(mrg myRoleGetter) { + AllowMe(mrg, composeTypes.NamespaceRbacResource(0), "module.create") +} + +func AllowMeModuleSearch(mrg myRoleGetter) { + AllowMe(mrg, composeTypes.NamespaceRbacResource(0), "modules.search") + AllowMe(mrg, composeTypes.ModuleRbacResource(0, 0), "read") +} + +func AllowMeModuleCRUD(mrg myRoleGetter) { + AllowMe(mrg, composeTypes.NamespaceRbacResource(0), "module.create") + AllowMe(mrg, composeTypes.NamespaceRbacResource(0), "modules.search") + AllowMe(mrg, composeTypes.ModuleRbacResource(0, 0), "read") + AllowMe(mrg, composeTypes.ModuleRbacResource(0, 0), "update") + AllowMe(mrg, composeTypes.ModuleRbacResource(0, 0), "delete") +} + +func AllowMeRecordCRUD(mrg myRoleGetter) { + AllowMe(mrg, composeTypes.ModuleRbacResource(0, 0), "record.create") + AllowMe(mrg, composeTypes.ModuleRbacResource(0, 0), "records.search") + AllowMe(mrg, composeTypes.RecordRbacResource(0, 0, 0), "read") + AllowMe(mrg, composeTypes.RecordRbacResource(0, 0, 0), "update") + AllowMe(mrg, composeTypes.RecordRbacResource(0, 0, 0), "delete") + AllowMe(mrg, composeTypes.ModuleFieldRbacResource(0, 0, 0), "record.value.update") + AllowMe(mrg, composeTypes.ModuleFieldRbacResource(0, 0, 0), "record.value.read") +} + +func AllowMeDalConnectionSearch(mrg myRoleGetter) { + AllowMe(mrg, types.ComponentRbacResource(), "dal-connections.search") + AllowMe(mrg, types.DalConnectionRbacResource(0), "read") +} + +func AllowMeDalConnectionCRUD(mrg myRoleGetter) { + AllowMe(mrg, types.ComponentRbacResource(), "dal-connection.create") + AllowMe(mrg, types.ComponentRbacResource(), "dal-connections.search") + AllowMe(mrg, types.DalConnectionRbacResource(0), "read") + AllowMe(mrg, types.DalConnectionRbacResource(0), "update") + AllowMe(mrg, types.DalConnectionRbacResource(0), "delete") +} diff --git a/tests/system/testdata/dal_connection_create/generic.json b/tests/system/testdata/dal_connection_create/generic.json index 613253294..54e430d77 100644 --- a/tests/system/testdata/dal_connection_create/generic.json +++ b/tests/system/testdata/dal_connection_create/generic.json @@ -1,7 +1,7 @@ { "name": "Test Connection", "handle": "test_connection", - "type": "corteza::system:dal_connection", + "type": "corteza::system:dal-connection", "location": { "geometry": { "type": "", diff --git a/tests/system/testdata/dal_connection_create_forbidden/generic.json b/tests/system/testdata/dal_connection_create_forbidden/generic.json index 613253294..54e430d77 100644 --- a/tests/system/testdata/dal_connection_create_forbidden/generic.json +++ b/tests/system/testdata/dal_connection_create_forbidden/generic.json @@ -1,7 +1,7 @@ { "name": "Test Connection", "handle": "test_connection", - "type": "corteza::system:dal_connection", + "type": "corteza::system:dal-connection", "location": { "geometry": { "type": "", diff --git a/tests/system/testdata/dal_connection_create_invalid_type/generic.json b/tests/system/testdata/dal_connection_create_invalid_type/generic.json index 0598fc0c4..648dfa9e4 100644 --- a/tests/system/testdata/dal_connection_create_invalid_type/generic.json +++ b/tests/system/testdata/dal_connection_create_invalid_type/generic.json @@ -1,7 +1,7 @@ { "name": "Test Connection", "handle": "test_connection", - "type": "corteza::system:primary_dal_connection", + "type": "corteza::system:primary-dal-connection", "location": { "geometry": { "type": "", diff --git a/tests/system/testdata/dal_connection_update/generic.json b/tests/system/testdata/dal_connection_update/generic.json index 5a809465e..226591943 100644 --- a/tests/system/testdata/dal_connection_update/generic.json +++ b/tests/system/testdata/dal_connection_update/generic.json @@ -1,7 +1,7 @@ { "name": "Test Connection EDITED", "handle": "test_connection_edited", - "type": "corteza::system:dal_connection", + "type": "corteza::system:dal-connection", "location": { "geometry": { "type": "", diff --git a/tests/system/testdata/dal_connection_update_forbidden/generic.json b/tests/system/testdata/dal_connection_update_forbidden/generic.json index 5a809465e..226591943 100644 --- a/tests/system/testdata/dal_connection_update_forbidden/generic.json +++ b/tests/system/testdata/dal_connection_update_forbidden/generic.json @@ -1,7 +1,7 @@ { "name": "Test Connection EDITED", "handle": "test_connection_edited", - "type": "corteza::system:dal_connection", + "type": "corteza::system:dal-connection", "location": { "geometry": { "type": "", diff --git a/tests/system/testdata/dal_connection_update_primary/generic.json b/tests/system/testdata/dal_connection_update_primary/generic.json index 7de858cf6..83a97550e 100644 --- a/tests/system/testdata/dal_connection_update_primary/generic.json +++ b/tests/system/testdata/dal_connection_update_primary/generic.json @@ -1,7 +1,7 @@ { "name": "Primary Connection EDITED", "handle": "primary_connection", - "type": "corteza::system:primary_dal_connection", + "type": "corteza::system:primary-dal-connection", "location": { "geometry": { "type": "",