Skip to content

Commit

Permalink
Merge pull request #1645 from josephschorr/combined-dispatch-recursiv…
Browse files Browse the repository at this point in the history
…e-test

Add missing combined recursive test case
  • Loading branch information
vroldanbet authored Nov 15, 2023
2 parents 54345a4 + c8ddcd5 commit 774d638
Showing 1 changed file with 60 additions and 0 deletions.
60 changes: 60 additions & 0 deletions internal/dispatch/combined/combined_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package combined

import (
"context"
"testing"

"github.com/stretchr/testify/require"

"github.com/authzed/spicedb/internal/datastore/memdb"
datastoremw "github.com/authzed/spicedb/internal/middleware/datastore"
"github.com/authzed/spicedb/internal/testfixtures"
core "github.com/authzed/spicedb/pkg/proto/core/v1"
dispatchv1 "github.com/authzed/spicedb/pkg/proto/dispatch/v1"
"github.com/authzed/spicedb/pkg/tuple"
)

func TestCombinedRecursiveCall(t *testing.T) {
dispatcher, err := NewDispatcher()
require.NoError(t, err)

t.Cleanup(func() { dispatcher.Close() })

ctx := datastoremw.ContextWithHandle(context.Background())

rawDS, err := memdb.NewMemdbDatastore(0, 0, memdb.DisableGC)
require.NoError(t, err)

ds, revision := testfixtures.DatastoreFromSchemaAndTestRelationships(rawDS, `
definition user {}
definition resource {
relation viewer: resource#viewer | user
permission view = viewer
}
`, []*core.RelationTuple{
tuple.MustParse("resource:someresource#viewer@resource:someresource#viewer"),
}, require.New(t))

require.NoError(t, datastoremw.SetInContext(ctx, ds))

_, err = dispatcher.DispatchCheck(ctx, &dispatchv1.DispatchCheckRequest{
ResourceRelation: &core.RelationReference{
Namespace: "resource",
Relation: "view",
},
ResourceIds: []string{"someresource"},
Subject: &core.ObjectAndRelation{
Namespace: "user",
ObjectId: "fred",
Relation: tuple.Ellipsis,
},
ResultsSetting: dispatchv1.DispatchCheckRequest_REQUIRE_ALL_RESULTS,
Metadata: &dispatchv1.ResolverMeta{
AtRevision: revision.String(),
DepthRemaining: 50,
},
})
require.Error(t, err)
require.ErrorContains(t, err, "max depth exceeded")
}

0 comments on commit 774d638

Please sign in to comment.