Moving DAL related REST tests to test/system
This commit is contained in:
@@ -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()
|
||||
}
|
||||
@@ -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()
|
||||
}
|
||||
@@ -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()
|
||||
|
||||
@@ -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).
|
||||
Reference in New Issue
Block a user