-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* filter identities * add tests * update godoc * fix test * rename params * address pr comments --------- Co-authored-by: Ales Stimec <[email protected]>
- Loading branch information
1 parent
8001a25
commit a2562bc
Showing
9 changed files
with
83 additions
and
75 deletions.
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