SMQ-3224 - Add consistent error for assigning channel and client with parent group to parent group (#3225)

Signed-off-by: Felix Gateru <felix.gateru@gmail.com>
This commit is contained in:
Felix Gateru
2025-12-01 18:32:58 +03:00
committed by GitHub
parent f7dcaa949b
commit 9d13d5b528
3 changed files with 12 additions and 5 deletions
+7 -1
View File
@@ -26,6 +26,7 @@ var (
errAddConnectionsClients = errors.New("failed to add connections in clients service")
errRemoveConnectionsClients = errors.New("failed to remove connections from clients service")
errSetParentGroup = errors.New("channel already have parent")
errSetSameParentGroup = errors.New("channel already assigned to the parent group")
)
type service struct {
@@ -421,7 +422,12 @@ func (svc service) SetParentGroup(ctx context.Context, session authn.Session, pa
}
var pols []policies.Policy
if ch.ParentGroup != "" {
switch ch.ParentGroup {
case parentGroupID:
return errors.Wrap(svcerr.ErrConflict, errSetSameParentGroup)
case "":
// No action needed, proceed to next code after switch
default:
return errors.Wrap(svcerr.ErrConflict, errSetParentGroup)
}
pols = append(pols, policies.Policy{
+4 -3
View File
@@ -20,8 +20,9 @@ import (
)
var (
errRollbackRepo = errors.New("failed to rollback repo")
errSetParentGroup = errors.New("client already have parent")
errRollbackRepo = errors.New("failed to rollback repo")
errSetParentGroup = errors.New("client already have parent")
errSetSameParentGroup = errors.New("client already assigned to the parent group")
)
var _ Service = (*service)(nil)
@@ -247,7 +248,7 @@ func (svc service) SetParentGroup(ctx context.Context, session authn.Session, pa
}
switch cli.ParentGroup {
case parentGroupID:
return nil
return errors.Wrap(svcerr.ErrConflict, errSetSameParentGroup)
case "":
// No action needed, proceed to next code after switch
default:
+1 -1
View File
@@ -1029,7 +1029,7 @@ func TestSetParentGroup(t *testing.T) {
parentGroupID: validID,
session: smqauthn.Session{UserID: validID, DomainID: validID, DomainUserID: validID + "_" + validID},
retrieveByIDResp: parentedClient,
err: nil,
err: svcerr.ErrConflict,
},
{
desc: "set parent group of client with existing parent group",