Add endpoint for listing permissions for a resource

This commit is contained in:
Benedikt Kulmann
2020-08-24 16:50:28 +02:00
parent e016ebdec8
commit 5fb1a8a2bb
14 changed files with 1060 additions and 452 deletions
+15
View File
@@ -0,0 +1,15 @@
package util
import "github.com/owncloud/ocis-settings/pkg/proto/v0"
const (
ResourceIdAll = "all"
)
// IsResourceMatched checks if the `example` resource is an exact match or a subset of `definition`
func IsResourceMatched(definition, example *proto.Resource) bool {
if definition.Type != example.Type {
return false
}
return definition.Id == ResourceIdAll || definition.Id == example.Id
}
+90
View File
@@ -0,0 +1,90 @@
package util
import (
"github.com/owncloud/ocis-settings/pkg/proto/v0"
"gotest.tools/assert"
"testing"
)
func TestIsResourceMatched(t *testing.T) {
scenarios := []struct {
name string
definition *proto.Resource
example *proto.Resource
matched bool
}{
{
"same resource types without ids match",
&proto.Resource{
Type: proto.Resource_TYPE_SYSTEM,
},
&proto.Resource{
Type: proto.Resource_TYPE_SYSTEM,
},
true,
},
{
"different resource types without ids don't match",
&proto.Resource{
Type: proto.Resource_TYPE_SYSTEM,
},
&proto.Resource{
Type: proto.Resource_TYPE_USER,
},
false,
},
{
"same resource types with different ids don't match",
&proto.Resource{
Type: proto.Resource_TYPE_USER,
Id: "einstein",
},
&proto.Resource{
Type: proto.Resource_TYPE_USER,
Id: "marie",
},
false,
},
{
"same resource types with same ids match",
&proto.Resource{
Type: proto.Resource_TYPE_USER,
Id: "einstein",
},
&proto.Resource{
Type: proto.Resource_TYPE_USER,
Id: "einstein",
},
true,
},
{
"same resource types with definition = ALL and without id in example is a match",
&proto.Resource{
Type: proto.Resource_TYPE_USER,
Id: ResourceIdAll,
},
&proto.Resource{
Type: proto.Resource_TYPE_USER,
},
true,
},
{
"same resource types with definition.id = ALL and with some id in example is a match",
&proto.Resource{
Type: proto.Resource_TYPE_USER,
Id: ResourceIdAll,
},
&proto.Resource{
Type: proto.Resource_TYPE_USER,
Id: "einstein",
},
true,
},
}
for _, scenario := range scenarios {
t.Run(scenario.name, func(t *testing.T) {
assert.Equal(t, scenario.matched, IsResourceMatched(scenario.definition, scenario.example))
})
}
}