Skip to content

Commit

Permalink
Merge pull request #1916 from josephschorr/validation-exclusion-sort
Browse files Browse the repository at this point in the history
Ensure stability of exclusions in validation package
  • Loading branch information
josephschorr authored May 30, 2024
2 parents c51f10a + 3b8d4fd commit e524bd2
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
4 changes: 4 additions & 0 deletions pkg/development/validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,10 @@ func validateSubjects(onrKey blocks.ObjectRelation, fs developmentmembership.Fou
if isWildcard {
expectedExcludedStrings := toExpectedRelationshipsStrings(expectedExcludedSubjects)
foundExcludedONRStrings := toFoundRelationshipsStrings(foundExcludedSubjects)

sort.Strings(expectedExcludedStrings)
sort.Strings(foundExcludedONRStrings)

if !cmp.Equal(expectedExcludedStrings, foundExcludedONRStrings) {
failures = append(failures, &devinterface.DeveloperError{
Message: fmt.Sprintf("For object and permission/relation `%s`, found different excluded subjects for subject `%s`: Specified: `%s`, Computed: `%s`",
Expand Down
28 changes: 28 additions & 0 deletions pkg/development/wasm/operations_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -962,6 +962,34 @@ assertFalse:
false,
`document:somedoc#view:
- '[user:* - {user:jimmy}] is <document:somedoc#viewer>'
`,
},
{
"wildcard multiple exclusion",
`
definition user {}
definition document {
relation banned: user
relation viewer: user | user:*
permission view = viewer - banned
}
`,
[]*core.RelationTuple{
tuple.MustParse("document:somedoc#banned@user:jimmy"),
tuple.MustParse("document:somedoc#banned@user:fred"),
tuple.MustParse("document:somedoc#viewer@user:*"),
},
`"document:somedoc#view":
- "[user:* - {user:fred, user:jimmy}] is <document:somedoc#viewer>"`,
`assertTrue:
- document:somedoc#view@user:somegal
assertFalse:
- document:somedoc#view@user:jimmy
- document:somedoc#view@user:fred`,
nil,
false,
`document:somedoc#view:
- '[user:* - {user:fred, user:jimmy}] is <document:somedoc#viewer>'
`,
},
{
Expand Down

0 comments on commit e524bd2

Please sign in to comment.