mirror of
https://github.com/grafana/grafana.git
synced 2024-11-27 11:20:27 -06:00
d623285fcc
* Rename fixed roles * Update descriptions * Update docs for fixed roles and permissions Co-authored-by: Ieva <ieva.vasiljeva@grafana.com> Co-authored-by: Ursula Kallio <73951760+osg-grafana@users.noreply.github.com>
75 lines
1.3 KiB
Go
75 lines
1.3 KiB
Go
package accesscontrol
|
|
|
|
import (
|
|
"sort"
|
|
"strings"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestFixedRoles(t *testing.T) {
|
|
for name, role := range FixedRoles {
|
|
assert.Truef(t,
|
|
strings.HasPrefix(name, "fixed:"),
|
|
"expected all fixed roles to be prefixed by 'fixed:', found role '%s'", name,
|
|
)
|
|
assert.Equal(t, name, role.Name)
|
|
assert.NotZero(t, role.Version)
|
|
}
|
|
}
|
|
|
|
func TestFixedRoleGrants(t *testing.T) {
|
|
for _, grants := range FixedRoleGrants {
|
|
// Check grants list is sorted
|
|
assert.True(t,
|
|
sort.SliceIsSorted(grants, func(i, j int) bool {
|
|
return grants[i] < grants[j]
|
|
}),
|
|
"require role grant lists to be sorted",
|
|
)
|
|
|
|
// Check all granted roles have been registered
|
|
for _, r := range grants {
|
|
assert.Contains(t, FixedRoles, r)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestConcatPermissions(t *testing.T) {
|
|
perms1 := []Permission{
|
|
{
|
|
Action: "test",
|
|
Scope: "test:*",
|
|
},
|
|
{
|
|
Action: "test1",
|
|
Scope: "test1:*",
|
|
},
|
|
}
|
|
perms2 := []Permission{
|
|
{
|
|
Action: "test1",
|
|
Scope: "*",
|
|
},
|
|
}
|
|
|
|
expected := []Permission{
|
|
{
|
|
Action: "test",
|
|
Scope: "test:*",
|
|
},
|
|
{
|
|
Action: "test1",
|
|
Scope: "test1:*",
|
|
},
|
|
{
|
|
Action: "test1",
|
|
Scope: "*",
|
|
},
|
|
}
|
|
|
|
perms := ConcatPermissions(perms1, perms2)
|
|
assert.ElementsMatch(t, perms, expected)
|
|
}
|