Chore: remove tests for legacy AC, update other tests to work with RBAC (#68895)

* remove tests for legacy AC, update other tests to work with RBAC

* update usage stat tests to use RBAC
This commit is contained in:
Ieva
2023-05-23 15:29:20 +01:00
committed by GitHub
parent 4629c79c7a
commit 900348f3d9
11 changed files with 85 additions and 867 deletions

View File

@@ -304,27 +304,15 @@ func TestAPIGetPublicDashboard(t *testing.T) {
PublicDashboardResult *PublicDashboard
PublicDashboardErr error
User *user.SignedInUser
AccessControlEnabled bool
ShouldCallService bool
}{
{
Name: "retrieves public dashboard when dashboard is found",
DashboardUid: "1",
ExpectedHttpResponse: http.StatusOK,
PublicDashboardResult: pubdash,
PublicDashboardErr: nil,
User: userViewer,
AccessControlEnabled: false,
ShouldCallService: true,
},
{
Name: "returns 404 when dashboard not found",
DashboardUid: "77777",
ExpectedHttpResponse: http.StatusNotFound,
PublicDashboardResult: nil,
PublicDashboardErr: ErrDashboardNotFound.Errorf(""),
User: userViewer,
AccessControlEnabled: false,
User: userViewerRBAC,
ShouldCallService: true,
},
{
@@ -333,8 +321,7 @@ func TestAPIGetPublicDashboard(t *testing.T) {
ExpectedHttpResponse: http.StatusInternalServerError,
PublicDashboardResult: nil,
PublicDashboardErr: errors.New("database broken"),
User: userViewer,
AccessControlEnabled: false,
User: userViewerRBAC,
ShouldCallService: true,
},
{
@@ -344,7 +331,6 @@ func TestAPIGetPublicDashboard(t *testing.T) {
PublicDashboardResult: pubdash,
PublicDashboardErr: nil,
User: userViewerRBAC,
AccessControlEnabled: true,
ShouldCallService: true,
},
{
@@ -353,7 +339,6 @@ func TestAPIGetPublicDashboard(t *testing.T) {
PublicDashboardResult: pubdash,
PublicDashboardErr: nil,
User: userViewer,
AccessControlEnabled: true,
ShouldCallService: false,
},
}
@@ -368,7 +353,6 @@ func TestAPIGetPublicDashboard(t *testing.T) {
}
cfg := setting.NewCfg()
cfg.RBACEnabled = test.AccessControlEnabled
testServer := setupTestServer(
t,
@@ -407,26 +391,14 @@ func TestApiCreatePublicDashboard(t *testing.T) {
ExpectedHttpResponse int
SaveDashboardErr error
User *user.SignedInUser
AccessControlEnabled bool
ShouldCallService bool
}{
{
Name: "returns 200 when update persists",
DashboardUid: "1",
publicDashboard: &PublicDashboard{IsEnabled: true},
ExpectedHttpResponse: http.StatusOK,
SaveDashboardErr: nil,
User: userAdmin,
AccessControlEnabled: false,
ShouldCallService: true,
},
{
Name: "returns 500 when not persisted",
ExpectedHttpResponse: http.StatusInternalServerError,
publicDashboard: &PublicDashboard{},
SaveDashboardErr: ErrInternalServerError.Errorf(""),
User: userAdmin,
AccessControlEnabled: false,
User: userAdminRBAC,
ShouldCallService: true,
},
{
@@ -434,8 +406,7 @@ func TestApiCreatePublicDashboard(t *testing.T) {
ExpectedHttpResponse: http.StatusNotFound,
publicDashboard: &PublicDashboard{},
SaveDashboardErr: ErrDashboardNotFound.Errorf(""),
User: userAdmin,
AccessControlEnabled: false,
User: userAdminRBAC,
ShouldCallService: true,
},
{
@@ -445,25 +416,14 @@ func TestApiCreatePublicDashboard(t *testing.T) {
ExpectedHttpResponse: http.StatusOK,
SaveDashboardErr: nil,
User: userAdminRBAC,
AccessControlEnabled: true,
ShouldCallService: true,
},
{
Name: "returns 403 when no permissions",
ExpectedHttpResponse: http.StatusForbidden,
publicDashboard: &PublicDashboard{IsEnabled: true},
SaveDashboardErr: ErrInternalServerError.Errorf("default error"),
User: userViewer,
AccessControlEnabled: false,
ShouldCallService: false,
},
{
Name: "returns 403 when no permissions RBAC on",
ExpectedHttpResponse: http.StatusForbidden,
publicDashboard: &PublicDashboard{IsEnabled: true},
SaveDashboardErr: nil,
User: userAdmin,
AccessControlEnabled: true,
ShouldCallService: false,
},
}
@@ -479,7 +439,6 @@ func TestApiCreatePublicDashboard(t *testing.T) {
}
cfg := setting.NewCfg()
cfg.RBACEnabled = test.AccessControlEnabled
testServer := setupTestServer(
t,