Skip to content

Commit

Permalink
Removing excluded users from ListUsers response (#347)
Browse files Browse the repository at this point in the history
  • Loading branch information
ewanharris authored Jun 17, 2024
2 parents b8938e0 + c1c3455 commit c8e464f
Show file tree
Hide file tree
Showing 10 changed files with 7 additions and 67 deletions.
8 changes: 0 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1100,14 +1100,6 @@ fga query **list-users** --object <object> --relation <relation> --user-filter <
```json5
{
{
"excluded_users": [
{
"object": {
"type": "user",
"id": "beth"
}
}
],
"users": [
{
"object": {
Expand Down
2 changes: 0 additions & 2 deletions example/model.fga.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,6 @@ tests:
users:
- user:anne
- user:beth
excluded_users: []
can_write:
users:
- user:anne
excluded_users: []
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ require (
github.com/nwidger/jsoncolor v0.3.2
github.com/oklog/ulid/v2 v2.1.0
github.com/openfga/api/proto v0.0.0-20240529190005-394820dfc109
github.com/openfga/go-sdk v0.4.0
github.com/openfga/go-sdk v0.5.0
github.com/openfga/language/pkg/go v0.0.0-20240530090832-1ae482acc202
github.com/openfga/openfga v1.5.4
github.com/spf13/cobra v1.8.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -185,8 +185,8 @@ github.com/opencontainers/image-spec v1.1.0 h1:8SG7/vwALn54lVB/0yZ/MMwhFrPYtpEHQ
github.com/opencontainers/image-spec v1.1.0/go.mod h1:W4s4sFTMaBeK1BQLXbG4AdM2szdn85PY75RI83NrTrM=
github.com/openfga/api/proto v0.0.0-20240529190005-394820dfc109 h1:V92DXyx43GBjLCv4Ky/u2jT8Lr1Hc3g8wNbnDHBfdBM=
github.com/openfga/api/proto v0.0.0-20240529190005-394820dfc109/go.mod h1:gil5LBD8tSdFQbUkCQdnXsoeU9kDJdJgbGdHkgJfcd0=
github.com/openfga/go-sdk v0.4.0 h1:C7h/x7Yq3NjxThHE4YGz+rwfawmyo8d9SVScer8fB9w=
github.com/openfga/go-sdk v0.4.0/go.mod h1:AoMnFlPw65sU/7O4xOPpCb2vXA8ZD9K9xp2hZjcvt4g=
github.com/openfga/go-sdk v0.5.0 h1:1IuAu6Xf4eBxgc2AyMfosK7QzApxuZ5yi7jmFaftnl0=
github.com/openfga/go-sdk v0.5.0/go.mod h1:AoMnFlPw65sU/7O4xOPpCb2vXA8ZD9K9xp2hZjcvt4g=
github.com/openfga/language/pkg/go v0.0.0-20240530090832-1ae482acc202 h1:DkW3VX6wOMckk2VIeaafdKW1WOt5Se6d/7L9239tt6I=
github.com/openfga/language/pkg/go v0.0.0-20240530090832-1ae482acc202/go.mod h1:mCwEY2IQvyNgfEwbfH0C0ERUwtL8z6UjSAF8zgn5Xbg=
github.com/openfga/openfga v1.5.4 h1:mVrp0uB9jNWX/5+OtZLM6YOx5Y9Y4r/D/O+LNBF/FGQ=
Expand Down
15 changes: 0 additions & 15 deletions internal/storetest/conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,18 +106,3 @@ func convertOpenfgaUsers(users []openfga.User) []string {

return simpleUsers
}

func convertOpenfgaObjectOrUserset(users []openfga.ObjectOrUserset) []string {
simpleUsers := []string{}

for _, user := range users {
switch {
case user.Object != nil:
simpleUsers = append(simpleUsers, user.Object.Type+":"+user.Object.Id)
case user.Userset != nil:
simpleUsers = append(simpleUsers, user.Userset.Type+":"+user.Userset.Id+"#"+user.Userset.Relation)
}
}

return simpleUsers
}
28 changes: 0 additions & 28 deletions internal/storetest/conversion_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,31 +172,3 @@ func TestConvertPbObjectOrUsersetToStrings(t *testing.T) {
})
}
}

func TestConvertObjectOrUsersetToStrings(t *testing.T) {
t.Parallel()

tests := map[string]struct {
input openfga.ObjectOrUserset
expected string
}{
"User_Object": {
input: openfga.ObjectOrUserset{Object: &openfga.FgaObject{Type: "user", Id: "anne"}},
expected: "user:anne",
},
"User_Userset": {
input: openfga.ObjectOrUserset{Userset: &openfga.UsersetUser{Type: "group", Id: "fga", Relation: "member"}},
expected: "group:fga#member",
},
}

for name, testcase := range tests {
t.Run(name, func(t *testing.T) {
t.Parallel()

got := convertOpenfgaObjectOrUserset([]openfga.ObjectOrUserset{testcase.input})

assert.Equal(t, []string{testcase.expected}, got)
})
}
}
3 changes: 1 addition & 2 deletions internal/storetest/localtest.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,8 +205,7 @@ func RunLocalListUsersTest(

if response != nil {
result.Got = ModelTestListUsersAssertion{
Users: convertPbUsersToStrings(response.GetUsers()),
ExcludedUsers: convertPbObjectOrUsersetToStrings(response.GetExcludedUsers()),
Users: convertPbUsersToStrings(response.GetUsers()),
}
result.TestResult = result.IsPassing()
}
Expand Down
3 changes: 1 addition & 2 deletions internal/storetest/remotetest.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,7 @@ func RunSingleRemoteListUsersTest(

if response != nil {
result.Got = ModelTestListUsersAssertion{
Users: convertOpenfgaUsers(response.GetUsers()),
ExcludedUsers: convertOpenfgaObjectOrUserset(response.GetExcludedUsers()),
Users: convertOpenfgaUsers(response.GetUsers()),
}
result.TestResult = result.IsPassing()
}
Expand Down
3 changes: 1 addition & 2 deletions internal/storetest/storedata.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,7 @@ type ModelTestListUsers struct {
}

type ModelTestListUsersAssertion struct {
Users []string `json:"users" yaml:"users"`
ExcludedUsers []string `json:"excluded_users" yaml:"excluded_users"` //nolint:tagliatelle
Users []string `json:"users" yaml:"users"`
}

type ModelTest struct {
Expand Down
6 changes: 1 addition & 5 deletions internal/storetest/testresult.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,7 @@ type ModelTestListUsersSingleResult struct {

func (result ModelTestListUsersSingleResult) IsPassing() bool {
return result.Error == nil &&
comparison.CheckStringArraysEqual(result.Got.Users, result.Expected.Users) &&
comparison.CheckStringArraysEqual(result.Got.ExcludedUsers, result.Expected.ExcludedUsers)
comparison.CheckStringArraysEqual(result.Got.Users, result.Expected.Users)
}

type TestResult struct {
Expand Down Expand Up @@ -199,9 +198,6 @@ func buildListUsersTestResults(
failedListUsersCount++

got := NoValueString
if listUsersResult.Got.Users != nil || listUsersResult.Got.ExcludedUsers != nil {
got = fmt.Sprintf("%+v", listUsersResult.Got)
}

userFilter := listUsersResult.Request.UserFilters[0]

Expand Down

0 comments on commit c8e464f

Please sign in to comment.