Add base DAL crud integration tests
This commit is contained in:
@@ -3,7 +3,6 @@ package service
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"github.com/davecgh/go-spew/spew"
|
||||
"testing"
|
||||
|
||||
"github.com/cortezaproject/corteza-server/compose/service/values"
|
||||
@@ -898,7 +897,6 @@ func TestSetRecordOwner(t *testing.T) {
|
||||
)
|
||||
|
||||
req.NoError(rbacService.Grant(ctx, rbac.AllowRule(role.ID, types.RecordRbacResource(0, 0, 0), "owner.manage")))
|
||||
spew.Dump(rbacService.Rules())
|
||||
req.NoError(store.CreateUser(ctx, s, invoker, originalOwner, alternativeOwner))
|
||||
|
||||
t.Run("invalid input", func(t *testing.T) {
|
||||
|
||||
Generated
+4
@@ -740,6 +740,10 @@ func DalConnectionFilter(f systemType.DalConnectionFilter) (ee []goqu.Expression
|
||||
ee = append(ee, goqu.C("handle").Eq(f.Handle))
|
||||
}
|
||||
|
||||
if val := strings.TrimSpace(f.Type); len(val) > 0 {
|
||||
ee = append(ee, goqu.C("type").Eq(f.Type))
|
||||
}
|
||||
|
||||
return ee, f, err
|
||||
}
|
||||
|
||||
|
||||
@@ -37,7 +37,7 @@ dal_connection: schema.#Resource & {
|
||||
deleted: {goType: "filter.State", storeIdent: "deleted_at"}
|
||||
}
|
||||
|
||||
byValue: ["connection_id", "handle"]
|
||||
byValue: ["connection_id", "handle", "type"]
|
||||
byNilState: ["deleted"]
|
||||
}
|
||||
|
||||
|
||||
@@ -146,6 +146,10 @@ func (ctrl DalConnection) Undelete(ctx context.Context, r *request.DalConnection
|
||||
}
|
||||
|
||||
func (ctrl DalConnection) makeFilterPayload(ctx context.Context, connections types.DalConnectionSet, f types.DalConnectionFilter) (out *connectionSetPayload, err error) {
|
||||
out = &connectionSetPayload{
|
||||
Filter: f,
|
||||
Set: make(types.DalConnectionSet, 0),
|
||||
}
|
||||
for _, c := range connections {
|
||||
if c.Capabilities.Enforced == nil {
|
||||
c.Capabilities.Enforced = capabilities.Set{}
|
||||
@@ -160,10 +164,7 @@ func (ctrl DalConnection) makeFilterPayload(ctx context.Context, connections typ
|
||||
c.Capabilities.Enabled = capabilities.Set{}
|
||||
}
|
||||
}
|
||||
out = &connectionSetPayload{
|
||||
Set: connections,
|
||||
Filter: f,
|
||||
}
|
||||
out.Set = append(out.Set, connections...)
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
@@ -297,7 +297,9 @@ func (svc *dalConnection) Search(ctx context.Context, filter types.DalConnection
|
||||
|
||||
func (svc *dalConnection) ReloadConnections(ctx context.Context) (err error) {
|
||||
// Get all available connections
|
||||
cc, _, err := store.SearchDalConnections(ctx, svc.store, types.DalConnectionFilter{})
|
||||
cc, _, err := store.SearchDalConnections(ctx, svc.store, types.DalConnectionFilter{
|
||||
Type: types.DalConnectionResourceType,
|
||||
})
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
@@ -277,7 +277,7 @@ func (svc *dalSensitivityLevel) prepare(ctx context.Context, s store.Storer, sl
|
||||
{
|
||||
// Assure unique level
|
||||
for _, crt := range set {
|
||||
if crt.Level == sl.Level {
|
||||
if crt.Level == sl.Level && crt.ID != sl.ID {
|
||||
return nil, fmt.Errorf("invalid sensitivity level: duplicated level value %d", sl.Level)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,349 @@
|
||||
package system
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/cortezaproject/corteza-server/pkg/dal"
|
||||
"github.com/cortezaproject/corteza-server/pkg/dal/capabilities"
|
||||
"github.com/cortezaproject/corteza-server/pkg/id"
|
||||
"github.com/cortezaproject/corteza-server/store"
|
||||
"github.com/cortezaproject/corteza-server/system/service"
|
||||
"github.com/cortezaproject/corteza-server/system/types"
|
||||
"github.com/cortezaproject/corteza-server/tests/helpers"
|
||||
jsonpath "github.com/steinfletcher/apitest-jsonpath"
|
||||
)
|
||||
|
||||
func (h helper) clearDalConnections() {
|
||||
h.noError(store.TruncateDalConnections(context.Background(), service.DefaultStore))
|
||||
}
|
||||
|
||||
func (h helper) getPrimaryConnection() *types.DalConnection {
|
||||
cc, _, err := store.SearchDalConnections(context.Background(), service.DefaultStore, types.DalConnectionFilter{Type: types.DalPrimaryConnectionResourceType})
|
||||
h.a.NoError(err)
|
||||
|
||||
if len(cc) != 1 {
|
||||
h.a.FailNow("invalid state: no or too many primary connections")
|
||||
}
|
||||
|
||||
return cc[0]
|
||||
}
|
||||
|
||||
func (h helper) createDalConnection(res *types.DalConnection) *types.DalConnection {
|
||||
if res.ID == 0 {
|
||||
res.ID = id.Next()
|
||||
}
|
||||
|
||||
if res.Name == "" {
|
||||
res.Name = "Test Connection"
|
||||
}
|
||||
if res.Handle == "" {
|
||||
res.Handle = "test_connection"
|
||||
}
|
||||
if res.Type == "" {
|
||||
res.Type = types.DalConnectionResourceType
|
||||
}
|
||||
if res.Ownership == "" {
|
||||
res.Ownership = "tester"
|
||||
}
|
||||
|
||||
if res.Config.DefaultModelIdent == "" {
|
||||
res.Config.DefaultModelIdent = "compose_records"
|
||||
}
|
||||
if res.Config.DefaultAttributeIdent == "" {
|
||||
res.Config.DefaultAttributeIdent = "values"
|
||||
}
|
||||
if res.Config.DefaultPartitionFormat == "" {
|
||||
res.Config.DefaultPartitionFormat = "compose_records_{{namespace}}_{{module}}"
|
||||
}
|
||||
if res.Config.PartitionFormatValidator == "" {
|
||||
res.Config.PartitionFormatValidator = ""
|
||||
}
|
||||
if res.Config.Connection.Params == nil {
|
||||
res.Config.Connection = dal.NewDSNConnection("sqlite3://file::memory:?cache=shared&mode=memory")
|
||||
}
|
||||
|
||||
if len(res.Capabilities.Enforced) == 0 {
|
||||
res.Capabilities.Enforced = capabilities.FullCapabilities()
|
||||
}
|
||||
|
||||
if len(res.Capabilities.Supported) == 0 {
|
||||
res.Capabilities.Supported = capabilities.Set{}
|
||||
}
|
||||
|
||||
if len(res.Capabilities.Unsupported) == 0 {
|
||||
res.Capabilities.Unsupported = capabilities.Set{}
|
||||
}
|
||||
|
||||
if len(res.Capabilities.Enabled) == 0 {
|
||||
res.Capabilities.Enabled = capabilities.Set{}
|
||||
}
|
||||
|
||||
if res.CreatedAt.IsZero() {
|
||||
res.CreatedAt = time.Now()
|
||||
}
|
||||
if res.CreatedBy == 0 {
|
||||
res.CreatedBy = h.cUser.ID
|
||||
}
|
||||
|
||||
h.a.NoError(service.DefaultStore.CreateDalConnection(context.Background(), res))
|
||||
h.a.NoError(service.DefaultDalConnection.ReloadConnections(context.Background()))
|
||||
return res
|
||||
}
|
||||
|
||||
func Test_dal_connection_list(t *testing.T) {
|
||||
h := newHelper(t)
|
||||
defer h.clearDalConnections()
|
||||
|
||||
helpers.AllowMe(h, types.ComponentRbacResource(), "dal-connections.search")
|
||||
helpers.AllowMe(h, types.DalConnectionRbacResource(0), "read")
|
||||
|
||||
h.apiInit().
|
||||
Get("/dal/connections/").
|
||||
Header("Accept", "application/json").
|
||||
Expect(t).
|
||||
Status(http.StatusOK).
|
||||
Assert(helpers.AssertNoErrors).
|
||||
Assert(jsonpath.Len("$.response.set", 1)).
|
||||
End()
|
||||
}
|
||||
|
||||
func Test_dal_connection_list_forbidden(t *testing.T) {
|
||||
h := newHelper(t)
|
||||
defer h.clearDalConnections()
|
||||
|
||||
h.apiInit().
|
||||
Get("/dal/connections/").
|
||||
Header("Accept", "application/json").
|
||||
Expect(t).
|
||||
Status(http.StatusOK).
|
||||
Assert(helpers.AssertError("dalConnection.errors.notAllowedToSearch")).
|
||||
End()
|
||||
}
|
||||
|
||||
func Test_dal_connection_list_forbidden_read(t *testing.T) {
|
||||
h := newHelper(t)
|
||||
defer h.clearDalConnections()
|
||||
|
||||
helpers.AllowMe(h, types.ComponentRbacResource(), "dal-connections.search")
|
||||
|
||||
h.apiInit().
|
||||
Get("/dal/connections/").
|
||||
Header("Accept", "application/json").
|
||||
Expect(t).
|
||||
Status(http.StatusOK).
|
||||
Assert(jsonpath.Len("$.response.set", 0)).
|
||||
End()
|
||||
}
|
||||
|
||||
func Test_dal_connection_create(t *testing.T) {
|
||||
h := newHelper(t)
|
||||
defer h.clearDalConnections()
|
||||
|
||||
helpers.AllowMe(h, types.ComponentRbacResource(), "dal-connection.create")
|
||||
|
||||
h.apiInit().
|
||||
Post("/dal/connections/").
|
||||
Body(loadScenarioRequest(t, "generic.json")).
|
||||
Header("Accept", "application/json").
|
||||
Header("Content-Type", "application/json").
|
||||
Expect(t).
|
||||
Status(http.StatusOK).
|
||||
Assert(helpers.AssertNoErrors).
|
||||
Assert(jsonpath.Present("$.response.connectionID")).
|
||||
End()
|
||||
}
|
||||
|
||||
func Test_dal_connection_create_forbidden(t *testing.T) {
|
||||
h := newHelper(t)
|
||||
defer h.clearDalConnections()
|
||||
|
||||
h.apiInit().
|
||||
Post("/dal/connections/").
|
||||
Body(loadScenarioRequest(t, "generic.json")).
|
||||
Header("Accept", "application/json").
|
||||
Header("Content-Type", "application/json").
|
||||
Expect(t).
|
||||
Status(http.StatusOK).
|
||||
Assert(helpers.AssertError("dalConnection.errors.notAllowedToCreate")).
|
||||
End()
|
||||
}
|
||||
|
||||
func Test_dal_connection_update(t *testing.T) {
|
||||
h := newHelper(t)
|
||||
defer h.clearDalConnections()
|
||||
|
||||
sl := h.createDalConnection(&types.DalConnection{
|
||||
Handle: "test_connection",
|
||||
})
|
||||
|
||||
helpers.AllowMe(h, types.DalConnectionRbacResource(0), "update")
|
||||
|
||||
h.apiInit().
|
||||
Put(fmt.Sprintf("/dal/connections/%d", sl.ID)).
|
||||
Header("Accept", "application/json").
|
||||
Header("Content-Type", "application/json").
|
||||
Body(loadScenarioRequest(t, "generic.json")).
|
||||
Expect(t).
|
||||
Status(http.StatusOK).
|
||||
Assert(helpers.AssertNoErrors).
|
||||
Assert(jsonpath.Equal("$.response.handle", "test_connection_edited")).
|
||||
End()
|
||||
}
|
||||
|
||||
func Test_dal_connection_update_primary(t *testing.T) {
|
||||
h := newHelper(t)
|
||||
defer h.clearDalConnections()
|
||||
|
||||
sl := h.getPrimaryConnection()
|
||||
|
||||
helpers.AllowMe(h, types.DalConnectionRbacResource(0), "update")
|
||||
|
||||
h.apiInit().
|
||||
Put(fmt.Sprintf("/dal/connections/%d", sl.ID)).
|
||||
Header("Accept", "application/json").
|
||||
Header("Content-Type", "application/json").
|
||||
Body(loadScenarioRequest(t, "generic.json")).
|
||||
Expect(t).
|
||||
Status(http.StatusOK).
|
||||
Assert(helpers.AssertNoErrors).
|
||||
Assert(jsonpath.Equal("$.response.name", "Primary Connection EDITED")).
|
||||
End()
|
||||
}
|
||||
|
||||
func Test_dal_connection_update_forbidden(t *testing.T) {
|
||||
h := newHelper(t)
|
||||
defer h.clearDalConnections()
|
||||
|
||||
sl := h.createDalConnection(&types.DalConnection{
|
||||
Handle: "test_connection",
|
||||
})
|
||||
|
||||
h.apiInit().
|
||||
Put(fmt.Sprintf("/dal/connections/%d", sl.ID)).
|
||||
Header("Accept", "application/json").
|
||||
Header("Content-Type", "application/json").
|
||||
Body(loadScenarioRequest(t, "generic.json")).
|
||||
Expect(t).
|
||||
Status(http.StatusOK).
|
||||
Assert(helpers.AssertError("dalConnection.errors.notAllowedToUpdate")).
|
||||
End()
|
||||
}
|
||||
|
||||
func Test_dal_connection_read(t *testing.T) {
|
||||
h := newHelper(t)
|
||||
defer h.clearDalConnections()
|
||||
|
||||
sl := h.createDalConnection(&types.DalConnection{
|
||||
Handle: "test_connection",
|
||||
})
|
||||
|
||||
helpers.AllowMe(h, types.DalConnectionRbacResource(0), "read")
|
||||
|
||||
h.apiInit().
|
||||
Get(fmt.Sprintf("/dal/connections/%d", sl.ID)).
|
||||
Header("Accept", "application/json").
|
||||
Expect(t).
|
||||
Status(http.StatusOK).
|
||||
Assert(helpers.AssertNoErrors).
|
||||
Assert(jsonpath.Present("$.response.connectionID")).
|
||||
End()
|
||||
}
|
||||
|
||||
func Test_dal_connection_read_forbiden(t *testing.T) {
|
||||
h := newHelper(t)
|
||||
defer h.clearDalConnections()
|
||||
|
||||
sl := h.createDalConnection(&types.DalConnection{
|
||||
Handle: "test_connection",
|
||||
})
|
||||
|
||||
h.apiInit().
|
||||
Get(fmt.Sprintf("/dal/connections/%d", sl.ID)).
|
||||
Header("Accept", "application/json").
|
||||
Expect(t).
|
||||
Status(http.StatusOK).
|
||||
Assert(helpers.AssertError("dalConnection.errors.notAllowedToRead")).
|
||||
End()
|
||||
}
|
||||
|
||||
func Test_dal_connection_delete(t *testing.T) {
|
||||
h := newHelper(t)
|
||||
defer h.clearDalConnections()
|
||||
|
||||
sl := h.createDalConnection(&types.DalConnection{
|
||||
Handle: "test_connection",
|
||||
})
|
||||
|
||||
helpers.AllowMe(h, types.DalConnectionRbacResource(0), "delete")
|
||||
|
||||
h.apiInit().
|
||||
Delete(fmt.Sprintf("/dal/connections/%d", sl.ID)).
|
||||
Header("Accept", "application/json").
|
||||
Expect(t).
|
||||
Status(http.StatusOK).
|
||||
Assert(helpers.AssertNoErrors).
|
||||
Assert(jsonpath.Equal("$.success.message", "OK")).
|
||||
End()
|
||||
}
|
||||
|
||||
func Test_dal_connection_delete_forbidden(t *testing.T) {
|
||||
h := newHelper(t)
|
||||
defer h.clearDalConnections()
|
||||
|
||||
sl := h.createDalConnection(&types.DalConnection{
|
||||
Handle: "test_connection",
|
||||
})
|
||||
|
||||
h.apiInit().
|
||||
Delete(fmt.Sprintf("/dal/connections/%d", sl.ID)).
|
||||
Header("Accept", "application/json").
|
||||
Expect(t).
|
||||
Status(http.StatusOK).
|
||||
Assert(helpers.AssertError("dalConnection.errors.notAllowedToDelete")).
|
||||
End()
|
||||
}
|
||||
|
||||
func Test_dal_connection_undelete(t *testing.T) {
|
||||
h := newHelper(t)
|
||||
defer h.clearDalConnections()
|
||||
|
||||
sl := h.createDalConnection(&types.DalConnection{
|
||||
Handle: "test_connection",
|
||||
DeletedAt: &h.cUser.CreatedAt,
|
||||
DeletedBy: h.cUser.ID,
|
||||
})
|
||||
|
||||
helpers.AllowMe(h, types.DalConnectionRbacResource(0), "delete")
|
||||
|
||||
h.apiInit().
|
||||
Post(fmt.Sprintf("/dal/connections/%d/undelete", sl.ID)).
|
||||
Header("Accept", "application/json").
|
||||
Expect(t).
|
||||
Status(http.StatusOK).
|
||||
Assert(helpers.AssertNoErrors).
|
||||
Assert(jsonpath.Equal("$.success.message", "OK")).
|
||||
End()
|
||||
}
|
||||
|
||||
func Test_dal_connection_undelete_forbidden(t *testing.T) {
|
||||
h := newHelper(t)
|
||||
defer h.clearDalConnections()
|
||||
|
||||
sl := h.createDalConnection(&types.DalConnection{
|
||||
Handle: "test_connection",
|
||||
DeletedAt: &h.cUser.CreatedAt,
|
||||
DeletedBy: h.cUser.ID,
|
||||
})
|
||||
|
||||
h.apiInit().
|
||||
Post(fmt.Sprintf("/dal/connections/%d/undelete", sl.ID)).
|
||||
Header("Accept", "application/json").
|
||||
Expect(t).
|
||||
Status(http.StatusOK).
|
||||
Assert(helpers.AssertError("dalConnection.errors.notAllowedToUndelete")).
|
||||
End()
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
package system
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"testing"
|
||||
|
||||
"github.com/cortezaproject/corteza-server/tests/helpers"
|
||||
jsonpath "github.com/steinfletcher/apitest-jsonpath"
|
||||
)
|
||||
|
||||
func Test_dal_driver_list(t *testing.T) {
|
||||
h := newHelper(t)
|
||||
|
||||
h.apiInit().
|
||||
Get("/dal/drivers/").
|
||||
Expect(t).
|
||||
Status(http.StatusOK).
|
||||
Assert(helpers.AssertNoErrors).
|
||||
Assert(jsonpath.Len("$.response.set", 1)).
|
||||
Assert(jsonpath.Present("$.response.set[0].capabilities")).
|
||||
End()
|
||||
}
|
||||
@@ -0,0 +1,251 @@
|
||||
package system
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/cortezaproject/corteza-server/pkg/id"
|
||||
"github.com/cortezaproject/corteza-server/store"
|
||||
"github.com/cortezaproject/corteza-server/system/service"
|
||||
"github.com/cortezaproject/corteza-server/system/types"
|
||||
"github.com/cortezaproject/corteza-server/tests/helpers"
|
||||
jsonpath "github.com/steinfletcher/apitest-jsonpath"
|
||||
)
|
||||
|
||||
func (h helper) clearSensitivityLevels() {
|
||||
h.noError(store.TruncateDalSensitivityLevels(context.Background(), service.DefaultStore))
|
||||
}
|
||||
|
||||
func (h helper) createSensitivityLevel(res *types.DalSensitivityLevel) *types.DalSensitivityLevel {
|
||||
if res.ID == 0 {
|
||||
res.ID = id.Next()
|
||||
}
|
||||
|
||||
if res.CreatedAt.IsZero() {
|
||||
res.CreatedAt = time.Now()
|
||||
}
|
||||
|
||||
h.a.NoError(service.DefaultStore.CreateDalSensitivityLevel(context.Background(), res))
|
||||
return res
|
||||
}
|
||||
|
||||
func Test_dal_sensitivity_level_list(t *testing.T) {
|
||||
h := newHelper(t)
|
||||
defer h.clearSensitivityLevels()
|
||||
|
||||
helpers.AllowMe(h, types.ComponentRbacResource(), "dal-sensitivity-level.manage")
|
||||
|
||||
h.apiInit().
|
||||
Get("/dal/sensitivity-levels/").
|
||||
Header("Accept", "application/json").
|
||||
Expect(t).
|
||||
Status(http.StatusOK).
|
||||
Assert(helpers.AssertNoErrors).
|
||||
End()
|
||||
}
|
||||
|
||||
func Test_dal_sensitivity_level_list_forbidden(t *testing.T) {
|
||||
h := newHelper(t)
|
||||
defer h.clearSensitivityLevels()
|
||||
|
||||
h.apiInit().
|
||||
Get("/dal/sensitivity-levels/").
|
||||
Header("Accept", "application/json").
|
||||
Expect(t).
|
||||
Status(http.StatusOK).
|
||||
Assert(helpers.AssertError("dalSensitivityLevel.errors.notAllowedToManage")).
|
||||
End()
|
||||
}
|
||||
|
||||
func Test_dal_sensitivity_level_create(t *testing.T) {
|
||||
h := newHelper(t)
|
||||
defer h.clearSensitivityLevels()
|
||||
|
||||
helpers.AllowMe(h, types.ComponentRbacResource(), "dal-sensitivity-level.manage")
|
||||
|
||||
h.apiInit().
|
||||
Post("/dal/sensitivity-levels/").
|
||||
Body(loadScenarioRequest(t, "generic.json")).
|
||||
Header("Accept", "application/json").
|
||||
Header("Content-Type", "application/json").
|
||||
Expect(t).
|
||||
Status(http.StatusOK).
|
||||
Assert(helpers.AssertNoErrors).
|
||||
Assert(jsonpath.Present("$.response.sensitivityLevelID")).
|
||||
End()
|
||||
}
|
||||
|
||||
func Test_dal_sensitivity_level_create_forbidden(t *testing.T) {
|
||||
h := newHelper(t)
|
||||
defer h.clearSensitivityLevels()
|
||||
|
||||
h.apiInit().
|
||||
Post("/dal/sensitivity-levels/").
|
||||
Body(loadScenarioRequest(t, "generic.json")).
|
||||
Header("Accept", "application/json").
|
||||
Header("Content-Type", "application/json").
|
||||
Expect(t).
|
||||
Status(http.StatusOK).
|
||||
Assert(helpers.AssertError("dalSensitivityLevel.errors.notAllowedToManage")).
|
||||
End()
|
||||
}
|
||||
|
||||
func Test_dal_sensitivity_level_update(t *testing.T) {
|
||||
h := newHelper(t)
|
||||
defer h.clearSensitivityLevels()
|
||||
|
||||
sl := h.createSensitivityLevel(&types.DalSensitivityLevel{
|
||||
Handle: "test_sl",
|
||||
})
|
||||
|
||||
helpers.AllowMe(h, types.ComponentRbacResource(), "dal-sensitivity-level.manage")
|
||||
|
||||
h.apiInit().
|
||||
Put(fmt.Sprintf("/dal/sensitivity-levels/%d", sl.ID)).
|
||||
Header("Accept", "application/json").
|
||||
Header("Content-Type", "application/json").
|
||||
Body(loadScenarioRequest(t, "generic.json")).
|
||||
Expect(t).
|
||||
Status(http.StatusOK).
|
||||
Assert(helpers.AssertNoErrors).
|
||||
Assert(jsonpath.Present("$.response.sensitivityLevelID")).
|
||||
Assert(jsonpath.Equal("$.response.handle", "private_edited")).
|
||||
End()
|
||||
}
|
||||
|
||||
func Test_dal_sensitivity_level_update_forbidden(t *testing.T) {
|
||||
h := newHelper(t)
|
||||
defer h.clearSensitivityLevels()
|
||||
|
||||
sl := h.createSensitivityLevel(&types.DalSensitivityLevel{
|
||||
Handle: "test_sl",
|
||||
})
|
||||
|
||||
h.apiInit().
|
||||
Put(fmt.Sprintf("/dal/sensitivity-levels/%d", sl.ID)).
|
||||
Header("Accept", "application/json").
|
||||
Header("Content-Type", "application/json").
|
||||
Body(loadScenarioRequest(t, "generic.json")).
|
||||
Expect(t).
|
||||
Status(http.StatusOK).
|
||||
Assert(helpers.AssertError("dalSensitivityLevel.errors.notAllowedToManage")).
|
||||
End()
|
||||
}
|
||||
|
||||
func Test_dal_sensitivity_level_read(t *testing.T) {
|
||||
h := newHelper(t)
|
||||
defer h.clearSensitivityLevels()
|
||||
|
||||
sl := h.createSensitivityLevel(&types.DalSensitivityLevel{
|
||||
Handle: "test_sl",
|
||||
})
|
||||
|
||||
helpers.AllowMe(h, types.ComponentRbacResource(), "dal-sensitivity-level.manage")
|
||||
|
||||
h.apiInit().
|
||||
Get(fmt.Sprintf("/dal/sensitivity-levels/%d", sl.ID)).
|
||||
Header("Accept", "application/json").
|
||||
Expect(t).
|
||||
Status(http.StatusOK).
|
||||
Assert(helpers.AssertNoErrors).
|
||||
Assert(jsonpath.Present("$.response.sensitivityLevelID")).
|
||||
End()
|
||||
}
|
||||
|
||||
func Test_dal_sensitivity_level_read_forbiden(t *testing.T) {
|
||||
h := newHelper(t)
|
||||
defer h.clearSensitivityLevels()
|
||||
|
||||
sl := h.createSensitivityLevel(&types.DalSensitivityLevel{
|
||||
Handle: "test_sl",
|
||||
})
|
||||
|
||||
h.apiInit().
|
||||
Get(fmt.Sprintf("/dal/sensitivity-levels/%d", sl.ID)).
|
||||
Header("Accept", "application/json").
|
||||
Expect(t).
|
||||
Status(http.StatusOK).
|
||||
Assert(helpers.AssertError("dalSensitivityLevel.errors.notAllowedToManage")).
|
||||
End()
|
||||
}
|
||||
|
||||
func Test_dal_sensitivity_level_delete(t *testing.T) {
|
||||
h := newHelper(t)
|
||||
defer h.clearSensitivityLevels()
|
||||
|
||||
sl := h.createSensitivityLevel(&types.DalSensitivityLevel{
|
||||
Handle: "test_sl",
|
||||
})
|
||||
|
||||
helpers.AllowMe(h, types.ComponentRbacResource(), "dal-sensitivity-level.manage")
|
||||
|
||||
h.apiInit().
|
||||
Delete(fmt.Sprintf("/dal/sensitivity-levels/%d", sl.ID)).
|
||||
Header("Accept", "application/json").
|
||||
Expect(t).
|
||||
Status(http.StatusOK).
|
||||
Assert(helpers.AssertNoErrors).
|
||||
Assert(jsonpath.Equal("$.success.message", "OK")).
|
||||
End()
|
||||
}
|
||||
|
||||
func Test_dal_sensitivity_level_delete_forbidden(t *testing.T) {
|
||||
h := newHelper(t)
|
||||
defer h.clearSensitivityLevels()
|
||||
|
||||
sl := h.createSensitivityLevel(&types.DalSensitivityLevel{
|
||||
Handle: "test_sl",
|
||||
})
|
||||
|
||||
h.apiInit().
|
||||
Delete(fmt.Sprintf("/dal/sensitivity-levels/%d", sl.ID)).
|
||||
Header("Accept", "application/json").
|
||||
Expect(t).
|
||||
Status(http.StatusOK).
|
||||
Assert(helpers.AssertError("dalSensitivityLevel.errors.notAllowedToManage")).
|
||||
End()
|
||||
}
|
||||
|
||||
func Test_dal_sensitivity_level_undelete(t *testing.T) {
|
||||
h := newHelper(t)
|
||||
defer h.clearSensitivityLevels()
|
||||
|
||||
sl := h.createSensitivityLevel(&types.DalSensitivityLevel{
|
||||
Handle: "test_sl",
|
||||
DeletedAt: &h.cUser.CreatedAt,
|
||||
DeletedBy: h.cUser.ID,
|
||||
})
|
||||
|
||||
helpers.AllowMe(h, types.ComponentRbacResource(), "dal-sensitivity-level.manage")
|
||||
|
||||
h.apiInit().
|
||||
Post(fmt.Sprintf("/dal/sensitivity-levels/%d/undelete", sl.ID)).
|
||||
Header("Accept", "application/json").
|
||||
Expect(t).
|
||||
Status(http.StatusOK).
|
||||
Assert(helpers.AssertNoErrors).
|
||||
Assert(jsonpath.Equal("$.success.message", "OK")).
|
||||
End()
|
||||
}
|
||||
|
||||
func Test_dal_sensitivity_level_undelete_forbidden(t *testing.T) {
|
||||
h := newHelper(t)
|
||||
defer h.clearSensitivityLevels()
|
||||
|
||||
sl := h.createSensitivityLevel(&types.DalSensitivityLevel{
|
||||
Handle: "test_sl",
|
||||
DeletedAt: &h.cUser.CreatedAt,
|
||||
DeletedBy: h.cUser.ID,
|
||||
})
|
||||
|
||||
h.apiInit().
|
||||
Post(fmt.Sprintf("/dal/sensitivity-levels/%d/undelete", sl.ID)).
|
||||
Header("Accept", "application/json").
|
||||
Expect(t).
|
||||
Status(http.StatusOK).
|
||||
Assert(helpers.AssertError("dalSensitivityLevel.errors.notAllowedToManage")).
|
||||
End()
|
||||
}
|
||||
@@ -5,7 +5,9 @@ import (
|
||||
"embed"
|
||||
"errors"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path"
|
||||
"testing"
|
||||
|
||||
"github.com/cortezaproject/corteza-server/app"
|
||||
@@ -24,6 +26,7 @@ import (
|
||||
"github.com/cortezaproject/corteza-server/pkg/rand"
|
||||
"github.com/cortezaproject/corteza-server/pkg/rbac"
|
||||
"github.com/cortezaproject/corteza-server/store"
|
||||
"github.com/cortezaproject/corteza-server/store/adapters/rdbms/drivers/sqlite"
|
||||
"github.com/cortezaproject/corteza-server/system/rest"
|
||||
"github.com/cortezaproject/corteza-server/system/service"
|
||||
"github.com/cortezaproject/corteza-server/system/types"
|
||||
@@ -214,3 +217,14 @@ func readStaticFile(f string) []byte {
|
||||
c, _ := mockData.ReadFile(f)
|
||||
return c
|
||||
}
|
||||
|
||||
func loadScenarioRequest(t *testing.T, req string) string {
|
||||
f, err := os.Open(path.Join("testdata", t.Name()[5:], req))
|
||||
require.NoError(t, err)
|
||||
defer f.Close()
|
||||
|
||||
bb, err := ioutil.ReadAll(f)
|
||||
require.NoError(t, err)
|
||||
|
||||
return string(bb)
|
||||
}
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
{
|
||||
"name": "Test Connection",
|
||||
"handle": "test_connection",
|
||||
"type": "corteza::system:dal_connection",
|
||||
"location": {
|
||||
"geometry": {
|
||||
"type": "",
|
||||
"coordinates": null
|
||||
},
|
||||
"properties": {
|
||||
"name": ""
|
||||
}
|
||||
},
|
||||
"ownership": "",
|
||||
"sensitivityLevel": "0",
|
||||
"config": {
|
||||
"defaultModelIdent": "compose_record",
|
||||
"defaultAttributeIdent": "values",
|
||||
"defaultPartitionFormat": "compose_record_{{namespace}}_{{module}}",
|
||||
"partitionFormatValidator": "",
|
||||
"connection": {
|
||||
"type": "corteza::dal:connection:dsn",
|
||||
"params": {
|
||||
"dsn": "mysql://user:pass@tcp(localhost:3308)/corteza?collation=utf8mb4_general_ci"
|
||||
}
|
||||
}
|
||||
},
|
||||
"capabilities": {
|
||||
"enforced": [],
|
||||
"supported": [
|
||||
"corteza::dal:capability:create",
|
||||
"corteza::dal:capability:update",
|
||||
"corteza::dal:capability:search",
|
||||
"corteza::dal:capability:lookup",
|
||||
"corteza::dal:capability:paging",
|
||||
"corteza::dal:capability:stats",
|
||||
"corteza::dal:capability:sorting",
|
||||
"corteza::dal:capability:RBAC"
|
||||
],
|
||||
"unsupported": [],
|
||||
"enabled": []
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
{
|
||||
"name": "Test Connection",
|
||||
"handle": "test_connection",
|
||||
"type": "corteza::system:dal_connection",
|
||||
"location": {
|
||||
"geometry": {
|
||||
"type": "",
|
||||
"coordinates": null
|
||||
},
|
||||
"properties": {
|
||||
"name": ""
|
||||
}
|
||||
},
|
||||
"ownership": "",
|
||||
"sensitivityLevel": "0",
|
||||
"config": {
|
||||
"defaultModelIdent": "compose_record",
|
||||
"defaultAttributeIdent": "values",
|
||||
"defaultPartitionFormat": "compose_record_{{namespace}}_{{module}}",
|
||||
"partitionFormatValidator": "",
|
||||
"connection": {
|
||||
"type": "corteza::dal:connection:dsn",
|
||||
"params": {
|
||||
"dsn": "mysql://user:pass@tcp(localhost:3308)/corteza?collation=utf8mb4_general_ci"
|
||||
}
|
||||
}
|
||||
},
|
||||
"capabilities": {
|
||||
"enforced": [],
|
||||
"supported": [
|
||||
"corteza::dal:capability:create",
|
||||
"corteza::dal:capability:update",
|
||||
"corteza::dal:capability:search",
|
||||
"corteza::dal:capability:lookup",
|
||||
"corteza::dal:capability:paging",
|
||||
"corteza::dal:capability:stats",
|
||||
"corteza::dal:capability:sorting",
|
||||
"corteza::dal:capability:RBAC"
|
||||
],
|
||||
"unsupported": [],
|
||||
"enabled": []
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
{
|
||||
"name": "Test Connection",
|
||||
"handle": "test_connection",
|
||||
"type": "corteza::system:primary_dal_connection",
|
||||
"location": {
|
||||
"geometry": {
|
||||
"type": "",
|
||||
"coordinates": null
|
||||
},
|
||||
"properties": {
|
||||
"name": ""
|
||||
}
|
||||
},
|
||||
"ownership": "",
|
||||
"sensitivityLevel": "0",
|
||||
"config": {
|
||||
"defaultModelIdent": "compose_record",
|
||||
"defaultAttributeIdent": "values",
|
||||
"defaultPartitionFormat": "compose_record_{{namespace}}_{{module}}",
|
||||
"partitionFormatValidator": "",
|
||||
"connection": {
|
||||
"type": "corteza::dal:connection:dsn",
|
||||
"params": {
|
||||
"dsn": "mysql://user:pass@tcp(localhost:3308)/corteza?collation=utf8mb4_general_ci"
|
||||
}
|
||||
}
|
||||
},
|
||||
"capabilities": {
|
||||
"enforced": [],
|
||||
"supported": [
|
||||
"corteza::dal:capability:create",
|
||||
"corteza::dal:capability:update",
|
||||
"corteza::dal:capability:search",
|
||||
"corteza::dal:capability:lookup",
|
||||
"corteza::dal:capability:paging",
|
||||
"corteza::dal:capability:stats",
|
||||
"corteza::dal:capability:sorting",
|
||||
"corteza::dal:capability:RBAC"
|
||||
],
|
||||
"unsupported": [],
|
||||
"enabled": []
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
{
|
||||
"name": "Test Connection EDITED",
|
||||
"handle": "test_connection_edited",
|
||||
"type": "corteza::system:dal_connection",
|
||||
"location": {
|
||||
"geometry": {
|
||||
"type": "",
|
||||
"coordinates": null
|
||||
},
|
||||
"properties": {
|
||||
"name": ""
|
||||
}
|
||||
},
|
||||
"ownership": "",
|
||||
"sensitivityLevel": "0",
|
||||
"config": {
|
||||
"defaultModelIdent": "compose_record",
|
||||
"defaultAttributeIdent": "values",
|
||||
"defaultPartitionFormat": "compose_record_{{namespace}}_{{module}}",
|
||||
"partitionFormatValidator": "",
|
||||
"connection": {
|
||||
"type": "corteza::dal:connection:dsn",
|
||||
"params": {
|
||||
"dsn": "sqlite3://file::memory:?cache=shared&mode=memory"
|
||||
}
|
||||
}
|
||||
},
|
||||
"capabilities": {
|
||||
"enforced": [],
|
||||
"supported": [
|
||||
"corteza::dal:capability:create",
|
||||
"corteza::dal:capability:update",
|
||||
"corteza::dal:capability:search",
|
||||
"corteza::dal:capability:lookup",
|
||||
"corteza::dal:capability:paging",
|
||||
"corteza::dal:capability:stats",
|
||||
"corteza::dal:capability:sorting",
|
||||
"corteza::dal:capability:RBAC"
|
||||
],
|
||||
"unsupported": [],
|
||||
"enabled": []
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
{
|
||||
"name": "Test Connection EDITED",
|
||||
"handle": "test_connection_edited",
|
||||
"type": "corteza::system:dal_connection",
|
||||
"location": {
|
||||
"geometry": {
|
||||
"type": "",
|
||||
"coordinates": null
|
||||
},
|
||||
"properties": {
|
||||
"name": ""
|
||||
}
|
||||
},
|
||||
"ownership": "",
|
||||
"sensitivityLevel": "0",
|
||||
"config": {
|
||||
"defaultModelIdent": "compose_record",
|
||||
"defaultAttributeIdent": "values",
|
||||
"defaultPartitionFormat": "compose_record_{{namespace}}_{{module}}",
|
||||
"partitionFormatValidator": "",
|
||||
"connection": {
|
||||
"type": "corteza::dal:connection:dsn",
|
||||
"params": {
|
||||
"dsn": "sqlite3://file::memory:?cache=shared&mode=memory"
|
||||
}
|
||||
}
|
||||
},
|
||||
"capabilities": {
|
||||
"enforced": [],
|
||||
"supported": [
|
||||
"corteza::dal:capability:create",
|
||||
"corteza::dal:capability:update",
|
||||
"corteza::dal:capability:search",
|
||||
"corteza::dal:capability:lookup",
|
||||
"corteza::dal:capability:paging",
|
||||
"corteza::dal:capability:stats",
|
||||
"corteza::dal:capability:sorting",
|
||||
"corteza::dal:capability:RBAC"
|
||||
],
|
||||
"unsupported": [],
|
||||
"enabled": []
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
{
|
||||
"name": "Primary Connection EDITED",
|
||||
"handle": "primary_connection",
|
||||
"type": "corteza::system:primary_dal_connection",
|
||||
"location": {
|
||||
"geometry": {
|
||||
"type": "",
|
||||
"coordinates": null
|
||||
},
|
||||
"properties": {
|
||||
"name": ""
|
||||
}
|
||||
},
|
||||
"ownership": "",
|
||||
"sensitivityLevel": "0",
|
||||
"config": {
|
||||
"defaultModelIdent": "compose_record",
|
||||
"defaultAttributeIdent": "values",
|
||||
"defaultPartitionFormat": "compose_record_{{namespace}}_{{module}}",
|
||||
"partitionFormatValidator": "",
|
||||
"connection": {
|
||||
"type": "corteza::dal:connection:dsn",
|
||||
"params": {
|
||||
"dsn": "sqlite3://file::memory:?cache=shared&mode=memory"
|
||||
}
|
||||
}
|
||||
},
|
||||
"capabilities": {
|
||||
"enforced": [],
|
||||
"supported": [
|
||||
"corteza::dal:capability:create",
|
||||
"corteza::dal:capability:update",
|
||||
"corteza::dal:capability:search",
|
||||
"corteza::dal:capability:lookup",
|
||||
"corteza::dal:capability:paging",
|
||||
"corteza::dal:capability:stats",
|
||||
"corteza::dal:capability:sorting",
|
||||
"corteza::dal:capability:RBAC"
|
||||
],
|
||||
"unsupported": [],
|
||||
"enabled": []
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"handle": "private",
|
||||
"level": 1,
|
||||
"meta": {
|
||||
"name": "private sensitivity",
|
||||
"description": "data is private to the owner"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"handle": "private",
|
||||
"level": 1,
|
||||
"meta": {
|
||||
"name": "private sensitivity",
|
||||
"description": "data is private to the owner"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"handle": "private_edited",
|
||||
"level": 1,
|
||||
"meta": {
|
||||
"name": "private sensitivity",
|
||||
"description": "data is private to the owner"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"handle": "private_edited",
|
||||
"level": 1,
|
||||
"meta": {
|
||||
"name": "private sensitivity",
|
||||
"description": "data is private to the owner"
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user