-
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.
change interpretation of group parameter for PatchIdentityGroups
The group parameter passed to the PatchIdentityGroups method is a group ID not a group tag (not group-ID and instead just ID). This PR fixes that misinterpretation.
- Loading branch information
Showing
4 changed files
with
29 additions
and
17 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 |
---|---|---|
|
@@ -31,11 +31,11 @@ func (s *identitiesSuite) TestIdentityPatchGroups(c *gc.C) { | |
identitySvc := rebac_admin.NewidentitiesService(s.JIMM) | ||
groupName := "group-test1" | ||
username := s.AdminUser.Name | ||
groupTag := s.AddGroup(c, groupName) | ||
group := s.AddGroup(c, groupName) | ||
|
||
// test add identity group | ||
changed, err := identitySvc.PatchIdentityGroups(ctx, username, []resources.IdentityGroupsPatchItem{{ | ||
Group: groupTag.String(), | ||
Group: group.UUID, | ||
Op: resources.IdentityGroupsPatchItemOpAdd, | ||
}}) | ||
c.Assert(err, gc.IsNil) | ||
|
@@ -47,23 +47,23 @@ func (s *identitiesSuite) TestIdentityPatchGroups(c *gc.C) { | |
tuples, _, err := s.JIMM.ListRelationshipTuples(ctx, s.AdminUser, params.RelationshipTuple{ | ||
Object: objUser.ResourceTag().String(), | ||
Relation: ofganames.MemberRelation.String(), | ||
TargetObject: groupTag.String(), | ||
TargetObject: group.ResourceTag().String(), | ||
}, 10, "") | ||
c.Assert(err, gc.IsNil) | ||
c.Assert(len(tuples), gc.Equals, 1) | ||
c.Assert(groupTag.Id(), gc.Equals, tuples[0].Target.ID) | ||
c.Assert(group.UUID, gc.Equals, tuples[0].Target.ID) | ||
|
||
// test user remove from group | ||
changed, err = identitySvc.PatchIdentityGroups(ctx, username, []resources.IdentityGroupsPatchItem{{ | ||
Group: groupTag.String(), | ||
Group: group.UUID, | ||
Op: resources.IdentityGroupsPatchItemOpRemove, | ||
}}) | ||
c.Assert(err, gc.IsNil) | ||
c.Assert(changed, gc.Equals, true) | ||
tuples, _, err = s.JIMM.ListRelationshipTuples(ctx, s.AdminUser, params.RelationshipTuple{ | ||
Object: objUser.ResourceTag().String(), | ||
Relation: ofganames.MemberRelation.String(), | ||
TargetObject: groupTag.String(), | ||
TargetObject: group.ResourceTag().String(), | ||
}, 10, "") | ||
c.Assert(err, gc.IsNil) | ||
c.Assert(len(tuples), gc.Equals, 0) | ||
|
@@ -80,10 +80,10 @@ func (s *identitiesSuite) TestIdentityGetGroups(c *gc.C) { | |
groupTags := make([]jimmnames.GroupTag, groupsSize) | ||
for i := range groupsSize { | ||
groupName := fmt.Sprintf("group-test%d", i) | ||
groupTag := s.AddGroup(c, groupName) | ||
groupTags[i] = groupTag | ||
group := s.AddGroup(c, groupName) | ||
groupTags[i] = group.ResourceTag() | ||
groupsToAdd[i] = resources.IdentityGroupsPatchItem{ | ||
Group: groupTag.String(), | ||
Group: group.UUID, | ||
Op: resources.IdentityGroupsPatchItemOpAdd, | ||
} | ||
|
||
|
@@ -118,13 +118,13 @@ func (s *identitiesSuite) TestIdentityEntitlements(c *gc.C) { | |
// initialization | ||
ctx := context.Background() | ||
identitySvc := rebac_admin.NewidentitiesService(s.JIMM) | ||
groupTag := s.AddGroup(c, "test-group") | ||
group := s.AddGroup(c, "test-group") | ||
user := names.NewUserTag("[email protected]") | ||
s.AddUser(c, user.Id()) | ||
err := s.JIMM.OpenFGAClient.AddRelation(ctx, openfga.Tuple{ | ||
Object: ofganames.ConvertTag(user), | ||
Relation: ofganames.MemberRelation, | ||
Target: ofganames.ConvertTag(groupTag), | ||
Target: ofganames.ConvertTag(group.ResourceTag()), | ||
}) | ||
c.Assert(err, gc.IsNil) | ||
tuple := openfga.Tuple{ | ||
|
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 |
---|---|---|
|
@@ -11,6 +11,7 @@ import ( | |
rebac_handlers "github.com/canonical/rebac-admin-ui-handlers/v1" | ||
"github.com/canonical/rebac-admin-ui-handlers/v1/resources" | ||
qt "github.com/frankban/quicktest" | ||
"github.com/google/uuid" | ||
|
||
"github.com/canonical/jimm/v3/internal/common/pagination" | ||
"github.com/canonical/jimm/v3/internal/common/utils" | ||
|
@@ -217,9 +218,11 @@ func TestPatchIdentityGroups(t *testing.T) { | |
c.Assert(err, qt.ErrorMatches, ".* not found") | ||
|
||
username := "[email protected]" | ||
group1ID := uuid.New() | ||
group2ID := uuid.New() | ||
operations := []resources.IdentityGroupsPatchItem{ | ||
{Group: "test-group1", Op: resources.IdentityGroupsPatchItemOpAdd}, | ||
{Group: "test-group2", Op: resources.IdentityGroupsPatchItemOpRemove}, | ||
{Group: group1ID.String(), Op: resources.IdentityGroupsPatchItemOpAdd}, | ||
{Group: group2ID.String(), Op: resources.IdentityGroupsPatchItemOpRemove}, | ||
} | ||
res, err := idSvc.PatchIdentityGroups(ctx, username, operations) | ||
c.Assert(err, qt.IsNil) | ||
|
@@ -228,4 +231,10 @@ func TestPatchIdentityGroups(t *testing.T) { | |
patchTuplesErr = errors.New("foo") | ||
_, err = idSvc.PatchIdentityGroups(ctx, username, operations) | ||
c.Assert(err, qt.ErrorMatches, ".*foo") | ||
|
||
invalidGroupName := []resources.IdentityGroupsPatchItem{ | ||
{Group: "test-group1", Op: resources.IdentityGroupsPatchItemOpAdd}, | ||
} | ||
res, err = idSvc.PatchIdentityGroups(ctx, "[email protected]", invalidGroupName) | ||
c.Assert(err, qt.ErrorMatches, "Bad Request: ID test-group1 is not a valid group ID") | ||
} |
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