mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
handle case when scope is wildcard (#44654)
This commit is contained in:
parent
333de57999
commit
16e62965f5
@ -30,8 +30,8 @@ func Filter(ctx context.Context, sqlID, prefix, action string, user *models.Sign
|
|||||||
var hasWildcard bool
|
var hasWildcard bool
|
||||||
var ids []interface{}
|
var ids []interface{}
|
||||||
for _, scope := range user.Permissions[user.OrgId][action] {
|
for _, scope := range user.Permissions[user.OrgId][action] {
|
||||||
if strings.HasPrefix(scope, prefix) {
|
if strings.HasPrefix(scope, prefix) || scope == "*" {
|
||||||
if id := strings.TrimPrefix(scope, prefix); id == ":*" || id == ":id:*" {
|
if id := strings.TrimPrefix(scope, prefix); id == "*" || id == ":*" || id == ":id:*" {
|
||||||
hasWildcard = true
|
hasWildcard = true
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
@ -31,6 +31,22 @@ func TestFilter_Datasources(t *testing.T) {
|
|||||||
},
|
},
|
||||||
expectedDataSources: []string{"ds:1", "ds:2", "ds:3", "ds:4", "ds:5", "ds:6", "ds:7", "ds:8", "ds:9", "ds:10"},
|
expectedDataSources: []string{"ds:1", "ds:2", "ds:3", "ds:4", "ds:5", "ds:6", "ds:7", "ds:8", "ds:9", "ds:10"},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
desc: "expect all data sources for wildcard id scope to be returned",
|
||||||
|
sqlID: "data_source.id",
|
||||||
|
permissions: []*accesscontrol.Permission{
|
||||||
|
{Action: "datasources:read", Scope: "datasources:id:*"},
|
||||||
|
},
|
||||||
|
expectedDataSources: []string{"ds:1", "ds:2", "ds:3", "ds:4", "ds:5", "ds:6", "ds:7", "ds:8", "ds:9", "ds:10"},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
desc: "expect all data sources for wildcard scope to be returned",
|
||||||
|
sqlID: "data_source.id",
|
||||||
|
permissions: []*accesscontrol.Permission{
|
||||||
|
{Action: "datasources:read", Scope: "*"},
|
||||||
|
},
|
||||||
|
expectedDataSources: []string{"ds:1", "ds:2", "ds:3", "ds:4", "ds:5", "ds:6", "ds:7", "ds:8", "ds:9", "ds:10"},
|
||||||
|
},
|
||||||
{
|
{
|
||||||
desc: "expect no data sources to be returned",
|
desc: "expect no data sources to be returned",
|
||||||
sqlID: "data_source.id",
|
sqlID: "data_source.id",
|
||||||
@ -47,6 +63,14 @@ func TestFilter_Datasources(t *testing.T) {
|
|||||||
},
|
},
|
||||||
expectedDataSources: []string{"ds:3", "ds:7", "ds:8"},
|
expectedDataSources: []string{"ds:3", "ds:7", "ds:8"},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
desc: "expect no data sources to be returned for malformed scope",
|
||||||
|
sqlID: "data_source.id",
|
||||||
|
permissions: []*accesscontrol.Permission{
|
||||||
|
{Action: "datasources:read", Scope: "datasources:id:1*"},
|
||||||
|
},
|
||||||
|
expectedDataSources: []string{},
|
||||||
|
},
|
||||||
{
|
{
|
||||||
desc: "expect error if sqlID is not in the accept list",
|
desc: "expect error if sqlID is not in the accept list",
|
||||||
sqlID: "other.id",
|
sqlID: "other.id",
|
||||||
|
Loading…
Reference in New Issue
Block a user