Skip to content

Commit

Permalink
test: add cases for checking subject sets
Browse files Browse the repository at this point in the history
inspired by and closes #985
  • Loading branch information
zepatrik committed Sep 2, 2022
1 parent 32a2ada commit 93aee83
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 1 deletion.
26 changes: 26 additions & 0 deletions cmd/check/root_test.go
Expand Up @@ -3,6 +3,10 @@ package check
import (
"testing"

"github.com/stretchr/testify/require"

rts "github.com/ory/keto/proto/ory/keto/relation_tuples/v1alpha2"

"github.com/stretchr/testify/assert"

"github.com/ory/keto/cmd/client"
Expand All @@ -19,3 +23,25 @@ func TestCheckCommand(t *testing.T) {
)
assert.Equal(t, "Denied\n", stdOut)
}

func TestParseSubject(t *testing.T) {
for _, tc := range []struct {
input string
expected *rts.Subject
}{
{
input: "nspace:obj#rel",
expected: rts.NewSubjectSet("nspace", "obj", "rel"),
},
{
input: "someid",
expected: rts.NewSubjectID("someid"),
},
} {
t.Run("subject="+tc.input, func(t *testing.T) {
actual, err := parseSubject(tc.input)
require.NoError(t, err)
assert.Equal(t, tc.expected, actual)
})
}
}
3 changes: 2 additions & 1 deletion go.mod
Expand Up @@ -47,6 +47,7 @@ require (
go.opentelemetry.io/otel v1.9.0
go.uber.org/goleak v1.1.12
golang.org/x/exp v0.0.0-20220518171630-0b5c67f07fdf
golang.org/x/oauth2 v0.0.0-20220608161450-d0670ef3b1eb
golang.org/x/sync v0.0.0-20220601150217-0de741cfad7f
google.golang.org/grpc v1.48.0
google.golang.org/protobuf v1.28.1
Expand Down Expand Up @@ -195,11 +196,11 @@ require (
golang.org/x/crypto v0.0.0-20220622213112-05595931fe9d // indirect
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4 // indirect
golang.org/x/net v0.0.0-20220708220712-1185a9018129 // indirect
golang.org/x/oauth2 v0.0.0-20220608161450-d0670ef3b1eb // indirect
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8 // indirect
golang.org/x/text v0.3.7 // indirect
golang.org/x/tools v0.1.11 // indirect
golang.org/x/xerrors v0.0.0-20220609144429-65e65417b02f // indirect
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/genproto v0.0.0-20220622171453-ea41d75dfa0f // indirect
gopkg.in/ini.v1 v1.66.6 // indirect
gopkg.in/op/go-logging.v1 v1.0.0-20160211212156-b2cb9fa56473 // indirect
Expand Down
22 changes: 22 additions & 0 deletions internal/e2e/cases_test.go
Expand Up @@ -49,6 +49,28 @@ func runCases(c client, m *namespaceTestManager) func(*testing.T) {
assert.True(t, c.check(t, tuple))
})

t.Run("case=check subjectSet relations", func(t *testing.T) {
n := &namespace.Namespace{Name: t.Name()}
m.add(t, n)

obj := fmt.Sprintf("obj for client %T", c)
rel := "check"

rt := &ketoapi.RelationTuple{
Namespace: n.Name,
Object: obj,
Relation: rel,
SubjectSet: &ketoapi.SubjectSet{
Namespace: n.Name,
Object: obj,
Relation: rel,
},
}
c.createTuple(t, rt)

assert.True(t, c.check(t, rt))
})

t.Run("case=expand API", func(t *testing.T) {
n := &namespace.Namespace{Name: t.Name()}
m.add(t, n)
Expand Down

0 comments on commit 93aee83

Please sign in to comment.