-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f1d025d
commit b8e884e
Showing
29 changed files
with
682 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,11 @@ import ( | |
"strings" | ||
"testing" | ||
|
||
"github.com/esnet/gdg/internal/tools" | ||
"github.com/esnet/gdg/internal/types" | ||
"github.com/esnet/gdg/pkg/test_tooling/containers" | ||
"github.com/samber/lo" | ||
|
||
"github.com/testcontainers/testcontainers-go" | ||
|
||
"github.com/esnet/gdg/internal/config" | ||
|
@@ -237,6 +242,74 @@ func TestDashboardTagsFilter(t *testing.T) { | |
assert.Equal(t, len(boards), 0) | ||
} | ||
|
||
func TestDashboardPermissionsCrud(t *testing.T) { | ||
//if os.Getenv(test_tooling.EnableTokenTestsEnv) == "1" { | ||
// t.Skip("Skipping Token configuration, Team and User CRUD requires Basic SecureData") | ||
//} | ||
props := containers.DefaultGrafanaEnv() | ||
err := containers.SetupGrafanaLicense(&props) | ||
if err != nil { | ||
slog.Error("no valid grafana license found, skipping enterprise tests") | ||
t.Skip() | ||
} | ||
apiClient, _, _, cleanup := test_tooling.InitTest(t, nil, props) | ||
defer cleanup() | ||
// Upload all dashboards | ||
apiClient.UploadDashboards(nil) | ||
// Upload all users | ||
newUsers := apiClient.UploadUsers(service.NewUserFilter("")) | ||
assert.Equal(t, len(newUsers), 2) | ||
// Upload all teams | ||
filter := service.NewTeamFilter("") | ||
teams := apiClient.UploadTeams(filter) | ||
assert.Equal(t, len(teams), 2) | ||
// Get current Permissions | ||
currentPerms, err := apiClient.ListDashboardPermissions(nil) | ||
assert.Equal(t, len(currentPerms), 16) | ||
entry := tools.PtrOf(lo.FirstOrEmpty(lo.Filter(currentPerms, func(item types.DashboardAndPermissions, index int) bool { | ||
return item.Dashboard.Title == "Bandwidth Dashboard" | ||
}))) | ||
assert.NotNil(t, entry) | ||
assert.Equal(t, len(entry.Permissions), 3) | ||
|
||
assert.NoError(t, apiClient.ClearDashboardPermissions(nil)) | ||
currentPerms, err = apiClient.ListDashboardPermissions(nil) | ||
assert.NoError(t, err) | ||
assert.Equal(t, len(currentPerms), 16) | ||
assert.Equal(t, len(currentPerms[0].Permissions), 0) | ||
addPerms, err := apiClient.UploadDashboardPermissions(nil) | ||
assert.NoError(t, err) | ||
assert.Equal(t, len(addPerms), 16) | ||
currentPerms, err = apiClient.ListDashboardPermissions(nil) | ||
entry = nil | ||
entry = tools.PtrOf(lo.FirstOrEmpty(lo.Filter(currentPerms, func(item types.DashboardAndPermissions, index int) bool { | ||
return item.Dashboard.Title == "Bandwidth Dashboard" | ||
}))) | ||
assert.NotNil(t, entry) | ||
assert.Equal(t, 5, len(entry.Permissions)) | ||
var bobPerm *models.DashboardACLInfoDTO | ||
var teamMusic *models.DashboardACLInfoDTO | ||
for ndx, entryPerm := range entry.Permissions { | ||
if entryPerm.Team == "musicians" { | ||
teamMusic = entry.Permissions[ndx] | ||
} | ||
if entryPerm.UserLogin == "bob" { | ||
bobPerm = entry.Permissions[ndx] | ||
} | ||
} | ||
assert.NotNil(t, bobPerm) | ||
assert.NotNil(t, teamMusic) | ||
// validate bob | ||
assert.Equal(t, bobPerm.PermissionName, "Edit") | ||
assert.Equal(t, bobPerm.UserEmail, "[email protected]") | ||
assert.Equal(t, bobPerm.UserID, int64(2)) | ||
assert.Equal(t, bobPerm.Permission, models.PermissionType(2)) | ||
// validate team permission | ||
assert.Equal(t, teamMusic.PermissionName, "Admin") | ||
assert.Equal(t, teamMusic.TeamID, int64(2)) | ||
assert.Equal(t, teamMusic.Permission, models.PermissionType(4)) | ||
} | ||
|
||
func TestWildcardFilter(t *testing.T) { | ||
if testing.Short() { | ||
t.Skip("skipping integration test") | ||
|
70 changes: 70 additions & 0 deletions
70
test/data/org_main-org/dashboards-permissions/General/bandwidth-dashboard.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
[ | ||
{ | ||
"created": "2024-09-15T16:38:16.000Z", | ||
"dashboardId": 1, | ||
"permission": 2, | ||
"permissionName": "Edit", | ||
"slug": "bandwidth-dashboard", | ||
"title": "Bandwidth Dashboard", | ||
"uid": "000000003", | ||
"updated": "2024-09-15T16:38:16.000Z", | ||
"url": "/d/000000003/bandwidth-dashboard", | ||
"userAvatarUrl": "/avatar/64029c12d260bd5e3cb2504f4155998f", | ||
"userEmail": "[email protected]", | ||
"userId": 2, | ||
"userLogin": "bob" | ||
}, | ||
{ | ||
"created": "2024-09-14T20:51:23.000Z", | ||
"dashboardId": 1, | ||
"permission": 4, | ||
"permissionName": "Admin", | ||
"slug": "bandwidth-dashboard", | ||
"title": "Bandwidth Dashboard", | ||
"uid": "000000003", | ||
"updated": "2024-09-14T20:51:23.000Z", | ||
"url": "/d/000000003/bandwidth-dashboard", | ||
"userAvatarUrl": "/avatar/46d229b033af06a191ff2267bca9ae56", | ||
"userEmail": "admin@localhost", | ||
"userId": 1, | ||
"userLogin": "admin" | ||
}, | ||
{ | ||
"created": "2024-09-15T16:38:26.000Z", | ||
"dashboardId": 1, | ||
"permission": 4, | ||
"permissionName": "Admin", | ||
"slug": "bandwidth-dashboard", | ||
"team": "musicians", | ||
"teamAvatarUrl": "/avatar/80ca0095115d85b522e59fa72b51a213", | ||
"teamId": 2, | ||
"title": "Bandwidth Dashboard", | ||
"uid": "000000003", | ||
"updated": "2024-09-15T16:38:26.000Z", | ||
"url": "/d/000000003/bandwidth-dashboard" | ||
}, | ||
{ | ||
"created": "2024-09-14T20:51:23.000Z", | ||
"dashboardId": 1, | ||
"permission": 1, | ||
"permissionName": "View", | ||
"role": "Viewer", | ||
"slug": "bandwidth-dashboard", | ||
"title": "Bandwidth Dashboard", | ||
"uid": "000000003", | ||
"updated": "2024-09-14T20:51:23.000Z", | ||
"url": "/d/000000003/bandwidth-dashboard" | ||
}, | ||
{ | ||
"created": "2024-09-14T20:51:23.000Z", | ||
"dashboardId": 1, | ||
"permission": 2, | ||
"permissionName": "Edit", | ||
"role": "Editor", | ||
"slug": "bandwidth-dashboard", | ||
"title": "Bandwidth Dashboard", | ||
"uid": "000000003", | ||
"updated": "2024-09-14T20:51:23.000Z", | ||
"url": "/d/000000003/bandwidth-dashboard" | ||
} | ||
] |
41 changes: 41 additions & 0 deletions
41
test/data/org_main-org/dashboards-permissions/General/bandwidth-patterns.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
[ | ||
{ | ||
"created": "2024-09-14T20:51:23.000Z", | ||
"dashboardId": 2, | ||
"permission": 4, | ||
"permissionName": "Admin", | ||
"slug": "bandwidth-patterns", | ||
"title": "Bandwidth Patterns", | ||
"uid": "000000004", | ||
"updated": "2024-09-14T20:51:23.000Z", | ||
"url": "/d/000000004/bandwidth-patterns", | ||
"userAvatarUrl": "/avatar/46d229b033af06a191ff2267bca9ae56", | ||
"userEmail": "admin@localhost", | ||
"userId": 1, | ||
"userLogin": "admin" | ||
}, | ||
{ | ||
"created": "2024-09-14T20:51:23.000Z", | ||
"dashboardId": 2, | ||
"permission": 2, | ||
"permissionName": "Edit", | ||
"role": "Editor", | ||
"slug": "bandwidth-patterns", | ||
"title": "Bandwidth Patterns", | ||
"uid": "000000004", | ||
"updated": "2024-09-14T20:51:23.000Z", | ||
"url": "/d/000000004/bandwidth-patterns" | ||
}, | ||
{ | ||
"created": "2024-09-14T20:51:23.000Z", | ||
"dashboardId": 2, | ||
"permission": 1, | ||
"permissionName": "View", | ||
"role": "Viewer", | ||
"slug": "bandwidth-patterns", | ||
"title": "Bandwidth Patterns", | ||
"uid": "000000004", | ||
"updated": "2024-09-14T20:51:23.000Z", | ||
"url": "/d/000000004/bandwidth-patterns" | ||
} | ||
] |
Oops, something went wrong.