Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 63 additions & 0 deletions pkg/go/graph/weighted_graph_builder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package graph
import (
"testing"

openfgav1 "github.com/openfga/api/proto/openfga/v1"
"github.com/stretchr/testify/require"

language "github.com/openfga/language/pkg/go/transformer"
Expand Down Expand Up @@ -1935,6 +1936,68 @@ func TestGraphConstructionIntersection(t *testing.T) {
_, err := wgb.Build(authorizationModel)
require.ErrorContains(t, err, "invalid model: not all paths return the same type for the node intersection:")
})
t.Run("empty_intersection", func(t *testing.T) {
t.Parallel()
authorizationModel := &openfgav1.AuthorizationModel{
SchemaVersion: "1.1",
TypeDefinitions: []*openfgav1.TypeDefinition{
{
Type: "user",
},
{
Type: "document",
Relations: map[string]*openfgav1.Userset{
"viewer": {
Userset: &openfgav1.Userset_Intersection{
Intersection: &openfgav1.Usersets{
Child: []*openfgav1.Userset{},
},
},
},
},
Metadata: &openfgav1.Metadata{
Relations: map[string]*openfgav1.RelationMetadata{
"viewer": {},
},
},
},
},
}
wgb := NewWeightedAuthorizationModelGraphBuilder()
_, err := wgb.Build(authorizationModel)
require.Error(t, err)
})
t.Run("empty_union", func(t *testing.T) {
t.Parallel()
authorizationModel := &openfgav1.AuthorizationModel{
SchemaVersion: "1.1",
TypeDefinitions: []*openfgav1.TypeDefinition{
{
Type: "user",
},
{
Type: "document",
Relations: map[string]*openfgav1.Userset{
"viewer": {
Userset: &openfgav1.Userset_Union{
Union: &openfgav1.Usersets{
Child: []*openfgav1.Userset{},
},
},
},
},
Metadata: &openfgav1.Metadata{
Relations: map[string]*openfgav1.RelationMetadata{
"viewer": {},
},
},
},
},
}
wgb := NewWeightedAuthorizationModelGraphBuilder()
_, err := wgb.Build(authorizationModel)
require.Error(t, err)
})
})

t.Run("multiple_intersections", func(t *testing.T) {
Expand Down