Skip to content

Commit

Permalink
Fix generated membership for the development package when using indir…
Browse files Browse the repository at this point in the history
…ect caveats

Also adds a consistency test case for this scenario
  • Loading branch information
josephschorr committed Jun 16, 2023
1 parent 5d33a67 commit 5760751
Show file tree
Hide file tree
Showing 3 changed files with 131 additions and 0 deletions.
2 changes: 2 additions & 0 deletions internal/developmentmembership/membership.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,8 @@ func populateFoundSubjects(rootONR *core.ObjectAndRelation, treeNode *core.Relat

fs.relationships.Add(resource)
}

toReturn.ApplyParentCaveatExpression(treeNode.CaveatExpression)
return toReturn, nil

default:
Expand Down
89 changes: 89 additions & 0 deletions internal/dispatch/graph/expand_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -632,6 +632,95 @@ func TestCaveatedExpand(t *testing.T) {
}
`,
},
{
"recursive caveated indirect arrow",
`definition user {}
caveat somecaveat(somecondition int) {
somecondition == 42
}
definition folder {
relation container: folder with somecaveat
relation member: user
permission view = container->member
}
definition resource {
relation folder: folder
permission view = folder->view
}`,
[]*core.RelationTuple{
tuple.MustParse("resource:someresource#folder@folder:first"),
tuple.MustParse("folder:first#container@folder:second[somecaveat]"),
tuple.MustParse("folder:first#member@user:notreachable"),
tuple.MustParse("folder:second#member@user:tom"),
},
tuple.ParseONR("resource:someresource#view"),
v1.DispatchExpandRequest_RECURSIVE,
`
intermediate_node: {
operation: UNION
child_nodes: {
intermediate_node: {
operation: UNION
child_nodes: {
intermediate_node: {
operation: UNION
child_nodes: {
intermediate_node: {
operation: UNION
child_nodes: {
leaf_node: {
subjects: {
subject: {
namespace: "user"
object_id: "tom"
relation: "..."
}
}
}
expanded: {
namespace: "folder"
object_id: "second"
relation: "member"
}
caveat_expression: {
caveat: {
caveat_name: "somecaveat"
context: {}
}
}
}
}
expanded: {
namespace: "folder"
object_id: "first"
relation: "view"
}
}
}
expanded: {
namespace: "folder"
object_id: "first"
relation: "view"
}
}
}
expanded: {
namespace: "resource"
object_id: "someresource"
relation: "view"
}
}
}
expanded: {
namespace: "resource"
object_id: "someresource"
relation: "view"
}
`,
},
}

for _, tc := range testCases {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
schema: |-
definition user {}
caveat team_is_admin(admin_teams list<string>, self string) {
self in admin_teams
}
definition team {
relation admin: team with team_is_admin
relation member: user
permission view = admin->member
}
definition resource {
relation team: team
permission can_view = team->view
}
relationships: |-
// team definition
team:A#admin@team:A[team_is_admin:{"self":"A"}]
team:B#admin@team:B[team_is_admin:{"self":"B"}]
team:C#admin@team:C[team_is_admin:{"self":"C"}]
// team members
team:A#member@user:clara
// resources
resource:1#team@team:B
resource:2#team@team:C
resource:3#team@team:C
resource:4#team@team:A
resource:5#team@team:B
resource:6#team@team:B
resource:7#team@team:C
assertions:
assertTrue:
- 'resource:4#can_view@user:clara with {"admin_teams": ["A"]}'
assertCaveated:
- resource:4#can_view@user:clara
assertFalse:
- 'resource:4#can_view@user:clara with {"admin_teams": ["B"]}'
- 'resource:1#can_view@user:clara with {"admin_teams": ["B"]}'

0 comments on commit 5760751

Please sign in to comment.