-
Notifications
You must be signed in to change notification settings - Fork 7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Juju 7074/identities filter #1434
Merged
SimoneDutto
merged 7 commits into
canonical:v3
from
SimoneDutto:JUJU-7074/identities-filter
Nov 15, 2024
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
efaf7ed
filter identities
SimoneDutto ece8e37
add tests
SimoneDutto 10cd635
update godoc
SimoneDutto 72ff456
fix test
SimoneDutto 0a145b6
rename params
SimoneDutto f4397cf
Merge branch 'v3' into JUJU-7074/identities-filter
alesstimec f127eeb
address pr comments
SimoneDutto File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -183,7 +183,7 @@ func (s *dbSuite) TestGetIdentityCloudCredentials(c *qt.C) { | |
c.Assert(credentials, qt.DeepEquals, []dbmodel.CloudCredential{cred1, cred2}) | ||
} | ||
|
||
func (s *dbSuite) TestForEachIdentity(c *qt.C) { | ||
func (s *dbSuite) TestListIdentities(c *qt.C) { | ||
err := s.Database.Migrate(context.Background(), false) | ||
c.Assert(err, qt.IsNil) | ||
|
||
|
@@ -192,41 +192,20 @@ func (s *dbSuite) TestForEachIdentity(c *qt.C) { | |
err = s.Database.GetIdentity(context.Background(), id) | ||
c.Assert(err, qt.IsNil) | ||
} | ||
firstIdentities := []*dbmodel.Identity{} | ||
ctx := context.Background() | ||
err = s.Database.ForEachIdentity(ctx, 5, 0, func(ge *dbmodel.Identity) error { | ||
firstIdentities = append(firstIdentities, ge) | ||
return nil | ||
}) | ||
firstIdentities, err := s.Database.ListIdentities(ctx, 5, 0, "") | ||
c.Assert(err, qt.IsNil) | ||
for i := 0; i < 5; i++ { | ||
c.Assert(firstIdentities[i].Name, qt.Equals, fmt.Sprintf("bob%[email protected]", i)) | ||
} | ||
secondIdentities := []*dbmodel.Identity{} | ||
err = s.Database.ForEachIdentity(ctx, 5, 5, func(ge *dbmodel.Identity) error { | ||
secondIdentities = append(secondIdentities, ge) | ||
return nil | ||
}) | ||
secondIdentities, err := s.Database.ListIdentities(ctx, 5, 5, "") | ||
c.Assert(err, qt.IsNil) | ||
for i := 0; i < 5; i++ { | ||
c.Assert(secondIdentities[i].Name, qt.Equals, fmt.Sprintf("bob%[email protected]", i+5)) | ||
} | ||
} | ||
|
||
func (s *dbSuite) TestForEachIdentityError(c *qt.C) { | ||
err := s.Database.Migrate(context.Background(), false) | ||
filteredIdentities, err := s.Database.ListIdentities(ctx, 5, 0, "bob0") | ||
c.Assert(err, qt.IsNil) | ||
ctx := context.Background() | ||
// add one identity | ||
id, _ := dbmodel.NewIdentity("[email protected]") | ||
err = s.Database.GetIdentity(context.Background(), id) | ||
c.Assert(err, qt.IsNil) | ||
|
||
// test error is returned | ||
errTest := errors.E("test-error") | ||
err = s.Database.ForEachIdentity(ctx, 5, 0, func(ge *dbmodel.Identity) error { | ||
return errTest | ||
}) | ||
c.Assert(err, qt.IsNotNil) | ||
c.Assert(err.Error(), qt.Equals, errTest.Error()) | ||
c.Assert(filteredIdentities, qt.HasLen, 1) | ||
c.Assert(filteredIdentities[0].Name, qt.Equals, "[email protected]") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -68,8 +68,8 @@ func TestListIdentities(t *testing.T) { | |
u := openfga.NewUser(&dbmodel.Identity{Name: "[email protected]"}, ofgaClient) | ||
u.JimmAdmin = true | ||
|
||
filter := pagination.NewOffsetFilter(10, 0) | ||
users, err := j.ListIdentities(ctx, u, filter) | ||
pag := pagination.NewOffsetFilter(10, 0) | ||
users, err := j.ListIdentities(ctx, u, pag, "") | ||
c.Assert(err, qt.IsNil) | ||
c.Assert(len(users), qt.Equals, 0) | ||
|
||
|
@@ -89,6 +89,7 @@ func TestListIdentities(t *testing.T) { | |
desc string | ||
limit int | ||
offset int | ||
match string | ||
identities []string | ||
}{ | ||
{ | ||
|
@@ -109,11 +110,18 @@ func TestListIdentities(t *testing.T) { | |
offset: 6, | ||
identities: []string{}, | ||
}, | ||
{ | ||
desc: "test with match", | ||
limit: 5, | ||
offset: 0, | ||
identities: []string{userNames[0]}, | ||
match: "bob1", | ||
}, | ||
} | ||
for _, t := range testCases { | ||
c.Run(t.desc, func(c *qt.C) { | ||
filter = pagination.NewOffsetFilter(t.limit, t.offset) | ||
identities, err := j.ListIdentities(ctx, u, filter) | ||
pag = pagination.NewOffsetFilter(t.limit, t.offset) | ||
identities, err := j.ListIdentities(ctx, u, pag, t.match) | ||
c.Assert(err, qt.IsNil) | ||
c.Assert(identities, qt.HasLen, len(t.identities)) | ||
for i := range len(t.identities) { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,6 +25,37 @@ type identitiesSuite struct { | |
|
||
var _ = gc.Suite(&identitiesSuite{}) | ||
|
||
func (s *identitiesSuite) TestIdentitiesList(c *gc.C) { | ||
ctx := context.Background() | ||
ctx = rebac_handlers.ContextWithIdentity(ctx, s.AdminUser) | ||
identitySvc := rebac_admin.NewidentitiesService(s.JIMM) | ||
for i := range 5 { | ||
user := names.NewUserTag(fmt.Sprintf("test-user-match-%[email protected]", i)) | ||
s.AddUser(c, user.Id()) | ||
} | ||
pageSize := 5 | ||
page := 0 | ||
params := &resources.GetIdentitiesParams{Size: &pageSize, Page: &page} | ||
res, err := identitySvc.ListIdentities(ctx, params) | ||
c.Assert(err, gc.IsNil) | ||
c.Assert(res, gc.Not(gc.IsNil)) | ||
c.Assert(res.Meta.Size, gc.Equals, 5) | ||
|
||
match := "test-user-match-1" | ||
params.Filter = &match | ||
res, err = identitySvc.ListIdentities(ctx, params) | ||
c.Assert(err, gc.IsNil) | ||
c.Assert(res, gc.Not(gc.IsNil)) | ||
c.Assert(len(res.Data), gc.Equals, 1) | ||
|
||
match = "test-user" | ||
params.Filter = &match | ||
res, err = identitySvc.ListIdentities(ctx, params) | ||
c.Assert(err, gc.IsNil) | ||
c.Assert(res, gc.Not(gc.IsNil)) | ||
c.Assert(len(res.Data), gc.Equals, pageSize) | ||
} | ||
|
||
func (s *identitiesSuite) TestIdentityPatchGroups(c *gc.C) { | ||
// initialization | ||
ctx := context.Background() | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Feel like I'm reading that book aha. Love it.