From 41056a1db0d580797fcbe224931002ccced5d1da Mon Sep 17 00:00:00 2001 From: Denis Arh Date: Tue, 11 Oct 2022 19:34:15 +0200 Subject: [PATCH] Moving DAL related REST tests to test/system --- tests/dal/dal_crud_connection_test.go | 283 ------------------ tests/dal/dal_crud_sensitivity_level_test.go | 229 -------------- tests/system/dal_connection_crud_test.go | 17 ++ tests/{dal => system}/dal_crud_driver_test.go | 6 +- 4 files changed, 20 insertions(+), 515 deletions(-) delete mode 100644 tests/dal/dal_crud_connection_test.go delete mode 100644 tests/dal/dal_crud_sensitivity_level_test.go rename tests/{dal => system}/dal_crud_driver_test.go (86%) diff --git a/tests/dal/dal_crud_connection_test.go b/tests/dal/dal_crud_connection_test.go deleted file mode 100644 index 5008598c1..000000000 --- a/tests/dal/dal_crud_connection_test.go +++ /dev/null @@ -1,283 +0,0 @@ -package dal - -import ( - "fmt" - "net/http" - "testing" - - "github.com/cortezaproject/corteza-server/system/types" - "github.com/cortezaproject/corteza-server/tests/helpers" - jsonpath "github.com/steinfletcher/apitest-jsonpath" -) - -func Test_dal_crud_connection_list(t *testing.T) { - h := newHelperT(t) - defer h.cleanupDal() - - helpers.AllowMeDalConnectionSearch(h) - - h.apiInit(). - Get("/system/dal/connections/"). - Header("Accept", "application/json"). - Expect(t). - Status(http.StatusOK). - Assert(helpers.AssertNoErrors). - // This will be the primary one - Assert(jsonpath.Len("$.response.set", 1)). - End() -} - -func Test_dal_crud_connection_list_forbidden(t *testing.T) { - h := newHelperT(t) - defer h.cleanupDal() - - h.apiInit(). - Get("/system/dal/connections/"). - Header("Accept", "application/json"). - Expect(t). - Status(http.StatusOK). - Assert(helpers.AssertError("dalConnection.errors.notAllowedToSearch")). - End() -} - -func Test_dal_crud_connection_list_forbidden_read(t *testing.T) { - h := newHelperT(t) - defer h.cleanupDal() - - helpers.AllowMe(h, types.ComponentRbacResource(), "dal-connections.search") - - h.apiInit(). - Get("/system/dal/connections/"). - Header("Accept", "application/json"). - Expect(t). - Status(http.StatusOK). - Assert(jsonpath.Len("$.response.set", 0)). - End() -} - -func Test_dal_crud_connection_create(t *testing.T) { - h := newHelperT(t) - defer h.cleanupDal() - - helpers.AllowMe(h, types.ComponentRbacResource(), "dal-connection.create") - - h.apiInit(). - Post("/system/dal/connections/"). - Body(loadRequestFromGenerics(t, "ok_connection.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_crud_connection_create_invalid_type(t *testing.T) { - h := newHelperT(t) - defer h.cleanupDal() - - helpers.AllowMe(h, types.ComponentRbacResource(), "dal-connection.create") - - h.apiInit(). - Post("/system/dal/connections/"). - Body(loadRequestFromGenerics(t, "nok_connection_invalid_type.json")). - Header("Accept", "application/json"). - Header("Content-Type", "application/json"). - Expect(t). - Status(http.StatusOK). - Assert(helpers.AssertErrorP("corteza::system:primary-dal-connection")). - End() -} - -func Test_dal_crud_connection_create_forbidden(t *testing.T) { - h := newHelperT(t) - defer h.cleanupDal() - - h.apiInit(). - Post("/system/dal/connections/"). - Body(loadRequestFromGenerics(t, "ok_connection.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_crud_connection_update(t *testing.T) { - h := newHelperT(t) - defer h.cleanupDal() - - sl := h.createDalConnection(&types.DalConnection{ - Handle: "test_connection", - }) - - helpers.AllowMe(h, types.DalConnectionRbacResource(0), "update") - helpers.AllowMe(h, types.DalConnectionRbacResource(0), "dal-config.manage") - - h.apiInit(). - Put(fmt.Sprintf("/system/dal/connections/%d", sl.ID)). - Header("Accept", "application/json"). - Header("Content-Type", "application/json"). - Body(loadRequestFromGenerics(t, "ok_connection_update.json")). - Expect(t). - Status(http.StatusOK). - Assert(helpers.AssertNoErrors). - Assert(jsonpath.Equal("$.response.handle", "test_connection_edited")). - End() -} - -func Test_dal_crud_connection_update_primary(t *testing.T) { - h := newHelperT(t) - defer h.cleanupDal() - - sl := h.getPrimaryConnection() - - helpers.AllowMe(h, types.DalConnectionRbacResource(0), "update") - - h.apiInit(). - Put(fmt.Sprintf("/system/dal/connections/%d", sl.ID)). - Header("Accept", "application/json"). - Header("Content-Type", "application/json"). - Body(loadRequestFromScenario(t, "connection.json")). - Expect(t). - Status(http.StatusOK). - Assert(helpers.AssertNoErrors). - Assert(jsonpath.Equal("$.response.meta.name", "Primary Connection EDITED")). - End() -} - -func Test_dal_crud_connection_update_forbidden(t *testing.T) { - h := newHelperT(t) - defer h.cleanupDal() - - sl := h.createDalConnection(&types.DalConnection{ - Handle: "test_connection", - }) - - h.apiInit(). - Put(fmt.Sprintf("/system/dal/connections/%d", sl.ID)). - Header("Accept", "application/json"). - Header("Content-Type", "application/json"). - Body(loadRequestFromGenerics(t, "ok_connection_update.json")). - Expect(t). - Status(http.StatusOK). - Assert(helpers.AssertError("dalConnection.errors.notAllowedToUpdate")). - End() -} - -func Test_dal_crud_connection_read(t *testing.T) { - h := newHelperT(t) - defer h.cleanupDal() - - sl := h.createDalConnection(&types.DalConnection{ - Handle: "test_connection", - }) - - helpers.AllowMe(h, types.DalConnectionRbacResource(0), "read") - - h.apiInit(). - Get(fmt.Sprintf("/system/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_crud_connection_read_forbidden(t *testing.T) { - h := newHelperT(t) - defer h.cleanupDal() - - sl := h.createDalConnection(&types.DalConnection{ - Handle: "test_connection", - }) - - h.apiInit(). - Get(fmt.Sprintf("/system/dal/connections/%d", sl.ID)). - Header("Accept", "application/json"). - Expect(t). - Status(http.StatusOK). - Assert(helpers.AssertError("dalConnection.errors.notAllowedToRead")). - End() -} - -func Test_dal_crud_connection_delete(t *testing.T) { - h := newHelperT(t) - defer h.cleanupDal() - - sl := h.createDalConnection(&types.DalConnection{ - Handle: "test_connection", - }) - - helpers.AllowMe(h, types.DalConnectionRbacResource(0), "delete") - - h.apiInit(). - Delete(fmt.Sprintf("/system/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_crud_connection_delete_forbidden(t *testing.T) { - h := newHelperT(t) - defer h.cleanupDal() - - sl := h.createDalConnection(&types.DalConnection{ - Handle: "test_connection", - }) - - h.apiInit(). - Delete(fmt.Sprintf("/system/dal/connections/%d", sl.ID)). - Header("Accept", "application/json"). - Expect(t). - Status(http.StatusOK). - Assert(helpers.AssertError("dalConnection.errors.notAllowedToDelete")). - End() -} - -func Test_dal_crud_connection_undelete(t *testing.T) { - h := newHelperT(t) - defer h.cleanupDal() - - 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("/system/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_crud_connection_undelete_forbidden(t *testing.T) { - h := newHelperT(t) - defer h.cleanupDal() - - sl := h.createDalConnection(&types.DalConnection{ - Handle: "test_connection", - DeletedAt: &h.cUser.CreatedAt, - DeletedBy: h.cUser.ID, - }) - - h.apiInit(). - Post(fmt.Sprintf("/system/dal/connections/%d/undelete", sl.ID)). - Header("Accept", "application/json"). - Expect(t). - Status(http.StatusOK). - Assert(helpers.AssertError("dalConnection.errors.notAllowedToUndelete")). - End() -} diff --git a/tests/dal/dal_crud_sensitivity_level_test.go b/tests/dal/dal_crud_sensitivity_level_test.go deleted file mode 100644 index 9d887fd34..000000000 --- a/tests/dal/dal_crud_sensitivity_level_test.go +++ /dev/null @@ -1,229 +0,0 @@ -package dal - -import ( - "fmt" - "net/http" - "testing" - - "github.com/cortezaproject/corteza-server/system/types" - "github.com/cortezaproject/corteza-server/tests/helpers" - jsonpath "github.com/steinfletcher/apitest-jsonpath" -) - -func Test_dal_crud_sensitivity_level_list(t *testing.T) { - h := newHelperT(t) - defer h.cleanupDal() - - helpers.AllowMe(h, types.ComponentRbacResource(), "dal-sensitivity-level.manage") - - h.apiInit(). - Get("/system/dal/sensitivity-levels/"). - Header("Accept", "application/json"). - Expect(t). - Status(http.StatusOK). - Assert(helpers.AssertNoErrors). - End() -} - -func Test_dal_crud_sensitivity_level_list_forbidden(t *testing.T) { - h := newHelperT(t) - defer h.cleanupDal() - - h.apiInit(). - Get("/system/dal/sensitivity-levels/"). - Header("Accept", "application/json"). - Expect(t). - Status(http.StatusOK). - Assert(helpers.AssertError("dalSensitivityLevel.errors.notAllowedToManage")). - End() -} - -func Test_dal_crud_sensitivity_level_create(t *testing.T) { - h := newHelperT(t) - defer h.cleanupDal() - - helpers.AllowMe(h, types.ComponentRbacResource(), "dal-sensitivity-level.manage") - - h.apiInit(). - Post("/system/dal/sensitivity-levels/"). - Body(loadRequestFromGenerics(t, "ok_sensitivity_level.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_crud_sensitivity_level_create_forbidden(t *testing.T) { - h := newHelperT(t) - defer h.cleanupDal() - - h.apiInit(). - Post("/system/dal/sensitivity-levels/"). - Body(loadRequestFromGenerics(t, "ok_sensitivity_level.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_crud_sensitivity_level_update(t *testing.T) { - h := newHelperT(t) - defer h.cleanupDal() - - sl := h.createSensitivityLevel(&types.DalSensitivityLevel{ - Handle: "test_sl", - }) - - helpers.AllowMe(h, types.ComponentRbacResource(), "dal-sensitivity-level.manage") - - h.apiInit(). - Put(fmt.Sprintf("/system/dal/sensitivity-levels/%d", sl.ID)). - Header("Accept", "application/json"). - Header("Content-Type", "application/json"). - Body(loadRequestFromGenerics(t, "ok_sensitivity_level_update.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_crud_sensitivity_level_update_forbidden(t *testing.T) { - h := newHelperT(t) - defer h.cleanupDal() - - sl := h.createSensitivityLevel(&types.DalSensitivityLevel{ - Handle: "test_sl", - }) - - h.apiInit(). - Put(fmt.Sprintf("/system/dal/sensitivity-levels/%d", sl.ID)). - Header("Accept", "application/json"). - Header("Content-Type", "application/json"). - Body(loadRequestFromGenerics(t, "ok_sensitivity_level_update.json")). - Expect(t). - Status(http.StatusOK). - Assert(helpers.AssertError("dalSensitivityLevel.errors.notAllowedToManage")). - End() -} - -func Test_dal_crud_sensitivity_level_read(t *testing.T) { - h := newHelperT(t) - defer h.cleanupDal() - - sl := h.createSensitivityLevel(&types.DalSensitivityLevel{ - Handle: "test_sl", - }) - - helpers.AllowMe(h, types.ComponentRbacResource(), "dal-sensitivity-level.manage") - - h.apiInit(). - Get(fmt.Sprintf("/system/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_crud_sensitivity_level_read_forbidden(t *testing.T) { - h := newHelperT(t) - defer h.cleanupDal() - - sl := h.createSensitivityLevel(&types.DalSensitivityLevel{ - Handle: "test_sl", - }) - - h.apiInit(). - Get(fmt.Sprintf("/system/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_crud_sensitivity_level_delete(t *testing.T) { - h := newHelperT(t) - defer h.cleanupDal() - - sl := h.createSensitivityLevel(&types.DalSensitivityLevel{ - Handle: "test_sl", - }) - - helpers.AllowMe(h, types.ComponentRbacResource(), "dal-sensitivity-level.manage") - - h.apiInit(). - Delete(fmt.Sprintf("/system/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_crud_sensitivity_level_delete_forbidden(t *testing.T) { - h := newHelperT(t) - defer h.cleanupDal() - - sl := h.createSensitivityLevel(&types.DalSensitivityLevel{ - Handle: "test_sl", - }) - - h.apiInit(). - Delete(fmt.Sprintf("/system/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_crud_sensitivity_level_undelete(t *testing.T) { - h := newHelperT(t) - defer h.cleanupDal() - - 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("/system/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_crud_sensitivity_level_undelete_forbidden(t *testing.T) { - h := newHelperT(t) - defer h.cleanupDal() - - sl := h.createSensitivityLevel(&types.DalSensitivityLevel{ - Handle: "test_sl", - DeletedAt: &h.cUser.CreatedAt, - DeletedBy: h.cUser.ID, - }) - - h.apiInit(). - Post(fmt.Sprintf("/system/dal/sensitivity-levels/%d/undelete", sl.ID)). - Header("Accept", "application/json"). - Expect(t). - Status(http.StatusOK). - Assert(helpers.AssertError("dalSensitivityLevel.errors.notAllowedToManage")). - End() -} diff --git a/tests/system/dal_connection_crud_test.go b/tests/system/dal_connection_crud_test.go index 8736f5d0a..bf9f3c039 100644 --- a/tests/system/dal_connection_crud_test.go +++ b/tests/system/dal_connection_crud_test.go @@ -144,6 +144,23 @@ func Test_dal_connection_create(t *testing.T) { End() } +func Test_dal_connection_create_invalid_type(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.AssertErrorP("corteza::system:primary-dal-connection")). + End() +} + func Test_dal_connection_create_forbidden(t *testing.T) { h := newHelper(t) defer h.clearDalConnections() diff --git a/tests/dal/dal_crud_driver_test.go b/tests/system/dal_crud_driver_test.go similarity index 86% rename from tests/dal/dal_crud_driver_test.go rename to tests/system/dal_crud_driver_test.go index 75b3afb6b..bf2ced603 100644 --- a/tests/dal/dal_crud_driver_test.go +++ b/tests/system/dal_crud_driver_test.go @@ -1,4 +1,4 @@ -package dal +package system import ( "net/http" @@ -9,10 +9,10 @@ import ( ) func Test_dal_crud_driver_list(t *testing.T) { - h := newHelperT(t) + h := newHelper(t) h.apiInit(). - Get("/system/dal/drivers/"). + Get("/dal/drivers/"). Expect(t). Status(http.StatusOK). Assert(helpers.AssertNoErrors).