mirror of
https://github.com/absmach/supermq.git
synced 2026-06-23 07:30:25 +00:00
NOISSUE - Fix Failing Users Property Based Tests (#2134)
Signed-off-by: Rodney Osodo <28790446+rodneyosodo@users.noreply.github.com>
This commit is contained in:
+17
-18
@@ -20,10 +20,9 @@ import (
|
||||
)
|
||||
|
||||
var (
|
||||
errParentUnAuthz = errors.New("failed to authorize parent group")
|
||||
errMemberKind = errors.New("invalid member kind")
|
||||
errRetrieveGroups = errors.New("failed to retrieve groups")
|
||||
errGroupIDs = errors.New("invalid group ids")
|
||||
errParentUnAuthz = errors.New("failed to authorize parent group")
|
||||
errMemberKind = errors.New("invalid member kind")
|
||||
errGroupIDs = errors.New("invalid group ids")
|
||||
)
|
||||
|
||||
type service struct {
|
||||
@@ -70,7 +69,7 @@ func (svc service) CreateGroup(ctx context.Context, token, kind string, g groups
|
||||
|
||||
g, err = svc.groups.Save(ctx, g)
|
||||
if err != nil {
|
||||
return groups.Group{}, err
|
||||
return groups.Group{}, errors.Wrap(svcerr.ErrCreateEntity, err)
|
||||
}
|
||||
// IMPROVEMENT NOTE: Add defer function , if return err is not nil, then delete group
|
||||
|
||||
@@ -104,7 +103,7 @@ func (svc service) CreateGroup(ctx context.Context, token, kind string, g groups
|
||||
})
|
||||
}
|
||||
if _, err := svc.auth.AddPolicies(ctx, &policies); err != nil {
|
||||
return g, err
|
||||
return g, errors.Wrap(svcerr.ErrAddPolicies, err)
|
||||
}
|
||||
|
||||
return g, nil
|
||||
@@ -228,7 +227,7 @@ func (svc service) ListGroups(ctx context.Context, token, memberKind, memberID s
|
||||
|
||||
gp, err := svc.groups.RetrieveByIDs(ctx, gm, ids...)
|
||||
if err != nil {
|
||||
return groups.Page{}, err
|
||||
return groups.Page{}, errors.Wrap(svcerr.ErrViewEntity, err)
|
||||
}
|
||||
|
||||
if gm.ListPerms && len(gp.Groups) > 0 {
|
||||
@@ -454,7 +453,7 @@ func (svc service) Assign(ctx context.Context, token, groupID, relation, memberK
|
||||
func (svc service) assignParentGroup(ctx context.Context, domain, parentGroupID string, groupIDs []string) (err error) {
|
||||
groupsPage, err := svc.groups.RetrieveByIDs(ctx, groups.Page{PageMeta: groups.PageMeta{Limit: 1<<63 - 1}}, groupIDs...)
|
||||
if err != nil {
|
||||
return errors.Wrap(errRetrieveGroups, err)
|
||||
return errors.Wrap(svcerr.ErrViewEntity, err)
|
||||
}
|
||||
if len(groupsPage.Groups) == 0 {
|
||||
return errGroupIDs
|
||||
@@ -484,7 +483,7 @@ func (svc service) assignParentGroup(ctx context.Context, domain, parentGroupID
|
||||
}
|
||||
|
||||
if _, err := svc.auth.AddPolicies(ctx, &addPolicies); err != nil {
|
||||
return err
|
||||
return errors.Wrap(svcerr.ErrAddPolicies, err)
|
||||
}
|
||||
defer func() {
|
||||
if err != nil {
|
||||
@@ -500,7 +499,7 @@ func (svc service) assignParentGroup(ctx context.Context, domain, parentGroupID
|
||||
func (svc service) unassignParentGroup(ctx context.Context, domain, parentGroupID string, groupIDs []string) (err error) {
|
||||
groupsPage, err := svc.groups.RetrieveByIDs(ctx, groups.Page{PageMeta: groups.PageMeta{Limit: 1<<63 - 1}}, groupIDs...)
|
||||
if err != nil {
|
||||
return errors.Wrap(errRetrieveGroups, err)
|
||||
return errors.Wrap(svcerr.ErrViewEntity, err)
|
||||
}
|
||||
if len(groupsPage.Groups) == 0 {
|
||||
return errGroupIDs
|
||||
@@ -530,7 +529,7 @@ func (svc service) unassignParentGroup(ctx context.Context, domain, parentGroupI
|
||||
}
|
||||
|
||||
if _, err := svc.auth.DeletePolicies(ctx, &deletePolicies); err != nil {
|
||||
return err
|
||||
return errors.Wrap(svcerr.ErrDeletePolicies, err)
|
||||
}
|
||||
defer func() {
|
||||
if err != nil {
|
||||
@@ -616,7 +615,7 @@ func (svc service) DeleteGroup(ctx context.Context, token, groupID string) error
|
||||
Subject: groupID,
|
||||
ObjectType: auth.GroupType,
|
||||
}); err != nil {
|
||||
return err
|
||||
return errors.Wrap(svcerr.ErrDeletePolicies, err)
|
||||
}
|
||||
|
||||
// Remove policy of things
|
||||
@@ -625,7 +624,7 @@ func (svc service) DeleteGroup(ctx context.Context, token, groupID string) error
|
||||
Subject: groupID,
|
||||
ObjectType: auth.ThingType,
|
||||
}); err != nil {
|
||||
return err
|
||||
return errors.Wrap(svcerr.ErrDeletePolicies, err)
|
||||
}
|
||||
|
||||
// Remove policy from domain
|
||||
@@ -634,12 +633,12 @@ func (svc service) DeleteGroup(ctx context.Context, token, groupID string) error
|
||||
Object: groupID,
|
||||
ObjectType: auth.GroupType,
|
||||
}); err != nil {
|
||||
return err
|
||||
return errors.Wrap(svcerr.ErrDeletePolicies, err)
|
||||
}
|
||||
|
||||
// Remove group from database
|
||||
if err := svc.groups.Delete(ctx, groupID); err != nil {
|
||||
return err
|
||||
return errors.Wrap(svcerr.ErrRemoveEntity, err)
|
||||
}
|
||||
|
||||
// Remove policy of users
|
||||
@@ -648,7 +647,7 @@ func (svc service) DeleteGroup(ctx context.Context, token, groupID string) error
|
||||
Object: groupID,
|
||||
ObjectType: auth.GroupType,
|
||||
}); err != nil {
|
||||
return err
|
||||
return errors.Wrap(svcerr.ErrDeletePolicies, err)
|
||||
}
|
||||
|
||||
return nil
|
||||
@@ -691,7 +690,7 @@ func (svc service) changeGroupStatus(ctx context.Context, token string, group gr
|
||||
}
|
||||
dbGroup, err := svc.groups.RetrieveByID(ctx, group.ID)
|
||||
if err != nil {
|
||||
return groups.Group{}, err
|
||||
return groups.Group{}, errors.Wrap(svcerr.ErrViewEntity, err)
|
||||
}
|
||||
if dbGroup.Status == group.Status {
|
||||
return groups.Group{}, errors.ErrStatusAlreadyAssigned
|
||||
@@ -704,7 +703,7 @@ func (svc service) changeGroupStatus(ctx context.Context, token string, group gr
|
||||
func (svc service) identify(ctx context.Context, token string) (*magistrala.IdentityRes, error) {
|
||||
res, err := svc.auth.Identify(ctx, &magistrala.IdentityReq{Token: token})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, errors.Wrap(svcerr.ErrAuthentication, err)
|
||||
}
|
||||
if res.GetId() == "" || res.GetDomainId() == "" {
|
||||
return nil, svcerr.ErrDomainAuthorization
|
||||
|
||||
Reference in New Issue
Block a user