2019-11-29 12:59:40 +01:00
|
|
|
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
|
|
|
|
// See LICENSE.txt for license information.
|
2019-01-10 15:17:31 -05:00
|
|
|
|
|
|
|
|
package api4
|
|
|
|
|
|
|
|
|
|
import (
|
2021-04-21 18:01:02 +03:00
|
|
|
"context"
|
2019-01-10 15:17:31 -05:00
|
|
|
"fmt"
|
|
|
|
|
"net/http"
|
|
|
|
|
"testing"
|
2020-03-07 22:42:23 +05:30
|
|
|
"time"
|
2019-01-10 15:17:31 -05:00
|
|
|
|
2019-11-14 09:21:23 -05:00
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
|
"github.com/stretchr/testify/require"
|
2021-01-07 22:42:43 +05:30
|
|
|
|
2023-06-11 10:54:35 +05:30
|
|
|
"github.com/mattermost/mattermost/server/public/model"
|
2019-01-10 15:17:31 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func TestGetGroup(t *testing.T) {
|
2020-07-22 13:50:33 +05:30
|
|
|
th := Setup(t)
|
2019-01-10 15:17:31 -05:00
|
|
|
defer th.TearDown()
|
|
|
|
|
|
|
|
|
|
id := model.NewId()
|
2021-08-13 13:12:16 +02:00
|
|
|
g, appErr := th.App.CreateGroup(&model.Group{
|
2019-01-10 15:17:31 -05:00
|
|
|
DisplayName: "dn_" + id,
|
2020-05-26 19:21:29 -06:00
|
|
|
Name: model.NewString("name" + id),
|
2019-01-10 15:17:31 -05:00
|
|
|
Source: model.GroupSourceLdap,
|
|
|
|
|
Description: "description_" + id,
|
2022-02-17 12:34:39 -05:00
|
|
|
RemoteId: model.NewString(model.NewId()),
|
2019-01-10 15:17:31 -05:00
|
|
|
})
|
2021-08-13 13:12:16 +02:00
|
|
|
assert.Nil(t, appErr)
|
2019-01-10 15:17:31 -05:00
|
|
|
|
2023-06-06 23:29:29 +02:00
|
|
|
_, response, err := th.Client.GetGroup(context.Background(), g.Id, "")
|
2021-08-13 13:12:16 +02:00
|
|
|
require.Error(t, err)
|
2019-01-10 15:17:31 -05:00
|
|
|
CheckNotImplementedStatus(t, response)
|
|
|
|
|
|
2023-06-06 23:29:29 +02:00
|
|
|
_, response, err = th.SystemAdminClient.GetGroup(context.Background(), g.Id, "")
|
2021-08-13 13:12:16 +02:00
|
|
|
require.Error(t, err)
|
2019-01-10 15:17:31 -05:00
|
|
|
CheckNotImplementedStatus(t, response)
|
|
|
|
|
|
2020-06-12 13:43:50 +02:00
|
|
|
th.App.Srv().SetLicense(model.NewTestLicense("ldap"))
|
2019-01-10 15:17:31 -05:00
|
|
|
|
2023-06-06 23:29:29 +02:00
|
|
|
group, _, err := th.SystemAdminClient.GetGroup(context.Background(), g.Id, "")
|
2021-08-13 13:12:16 +02:00
|
|
|
require.NoError(t, err)
|
2019-01-10 15:17:31 -05:00
|
|
|
|
|
|
|
|
assert.Equal(t, g.DisplayName, group.DisplayName)
|
|
|
|
|
assert.Equal(t, g.Name, group.Name)
|
|
|
|
|
assert.Equal(t, g.Source, group.Source)
|
|
|
|
|
assert.Equal(t, g.Description, group.Description)
|
|
|
|
|
assert.Equal(t, g.RemoteId, group.RemoteId)
|
|
|
|
|
assert.Equal(t, g.CreateAt, group.CreateAt)
|
|
|
|
|
assert.Equal(t, g.UpdateAt, group.UpdateAt)
|
|
|
|
|
assert.Equal(t, g.DeleteAt, group.DeleteAt)
|
|
|
|
|
|
2023-06-06 23:29:29 +02:00
|
|
|
_, response, err = th.SystemAdminClient.GetGroup(context.Background(), model.NewId(), "")
|
2021-08-13 13:12:16 +02:00
|
|
|
require.Error(t, err)
|
2019-01-10 15:17:31 -05:00
|
|
|
CheckNotFoundStatus(t, response)
|
|
|
|
|
|
2023-06-06 23:29:29 +02:00
|
|
|
_, response, err = th.SystemAdminClient.GetGroup(context.Background(), "12345", "")
|
2021-08-13 13:12:16 +02:00
|
|
|
require.Error(t, err)
|
2019-01-10 15:17:31 -05:00
|
|
|
CheckBadRequestStatus(t, response)
|
|
|
|
|
|
2023-06-06 23:29:29 +02:00
|
|
|
th.SystemAdminClient.Logout(context.Background())
|
|
|
|
|
_, response, err = th.SystemAdminClient.GetGroup(context.Background(), group.Id, "")
|
2021-08-13 13:12:16 +02:00
|
|
|
require.Error(t, err)
|
2019-01-10 15:17:31 -05:00
|
|
|
CheckUnauthorizedStatus(t, response)
|
|
|
|
|
}
|
2022-02-17 12:34:39 -05:00
|
|
|
func TestCreateGroup(t *testing.T) {
|
|
|
|
|
th := Setup(t)
|
|
|
|
|
defer th.TearDown()
|
|
|
|
|
|
|
|
|
|
id := model.NewId()
|
|
|
|
|
g := &model.Group{
|
|
|
|
|
DisplayName: "dn_" + id,
|
|
|
|
|
Name: model.NewString("name" + id),
|
|
|
|
|
Source: model.GroupSourceCustom,
|
|
|
|
|
Description: "description_" + id,
|
|
|
|
|
AllowReference: true,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
th.App.Srv().SetLicense(model.NewTestLicenseSKU(model.LicenseShortSkuProfessional, "ldap"))
|
|
|
|
|
|
2023-10-05 14:55:59 +01:00
|
|
|
_, resp, err := th.SystemAdminClient.CreateGroup(context.Background(), nil)
|
|
|
|
|
require.Error(t, err)
|
|
|
|
|
CheckBadRequestStatus(t, resp)
|
|
|
|
|
|
2023-06-06 23:29:29 +02:00
|
|
|
group, _, err := th.SystemAdminClient.CreateGroup(context.Background(), g)
|
2022-02-17 12:34:39 -05:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
|
|
assert.Equal(t, g.DisplayName, group.DisplayName)
|
|
|
|
|
assert.Equal(t, g.Name, group.Name)
|
|
|
|
|
assert.Equal(t, g.Source, group.Source)
|
|
|
|
|
assert.Equal(t, g.Description, group.Description)
|
|
|
|
|
assert.Equal(t, g.RemoteId, group.RemoteId)
|
|
|
|
|
|
|
|
|
|
gbroken := &model.Group{
|
|
|
|
|
DisplayName: "dn_" + id,
|
|
|
|
|
Name: model.NewString("name" + id),
|
|
|
|
|
Source: "rrrr",
|
|
|
|
|
Description: "description_" + id,
|
|
|
|
|
}
|
|
|
|
|
|
2023-06-06 23:29:29 +02:00
|
|
|
_, response, err := th.SystemAdminClient.CreateGroup(context.Background(), gbroken)
|
2022-02-17 12:34:39 -05:00
|
|
|
require.Error(t, err)
|
2022-08-08 20:02:49 +05:30
|
|
|
CheckBadRequestStatus(t, response)
|
2022-02-17 12:34:39 -05:00
|
|
|
|
|
|
|
|
validGroup := &model.Group{
|
|
|
|
|
DisplayName: "dn_" + model.NewId(),
|
|
|
|
|
Name: model.NewString("name" + model.NewId()),
|
|
|
|
|
Source: model.GroupSourceCustom,
|
|
|
|
|
AllowReference: true,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
th.RemovePermissionFromRole(model.PermissionCreateCustomGroup.Id, model.SystemAdminRoleId)
|
|
|
|
|
th.RemovePermissionFromRole(model.PermissionCreateCustomGroup.Id, model.SystemUserRoleId)
|
|
|
|
|
defer th.AddPermissionToRole(model.PermissionCreateCustomGroup.Id, model.SystemUserRoleId)
|
2023-06-06 23:29:29 +02:00
|
|
|
_, response, err = th.SystemAdminClient.CreateGroup(context.Background(), validGroup)
|
2022-02-17 12:34:39 -05:00
|
|
|
require.Error(t, err)
|
|
|
|
|
CheckForbiddenStatus(t, response)
|
|
|
|
|
|
|
|
|
|
th.AddPermissionToRole(model.PermissionCreateCustomGroup.Id, model.SystemAdminRoleId)
|
2023-06-06 23:29:29 +02:00
|
|
|
_, response, err = th.SystemAdminClient.CreateGroup(context.Background(), validGroup)
|
2022-02-17 12:34:39 -05:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
CheckCreatedStatus(t, response)
|
2019-01-10 15:17:31 -05:00
|
|
|
|
2022-03-08 09:14:22 -05:00
|
|
|
usernameGroup := &model.Group{
|
|
|
|
|
DisplayName: "dn_" + model.NewId(),
|
|
|
|
|
Name: &th.BasicUser.Username,
|
|
|
|
|
Source: model.GroupSourceCustom,
|
|
|
|
|
AllowReference: true,
|
|
|
|
|
}
|
2023-06-06 23:29:29 +02:00
|
|
|
_, response, err = th.SystemAdminClient.CreateGroup(context.Background(), usernameGroup)
|
2022-03-08 09:14:22 -05:00
|
|
|
require.Error(t, err)
|
|
|
|
|
CheckBadRequestStatus(t, response)
|
|
|
|
|
|
2022-02-17 12:34:39 -05:00
|
|
|
unReferenceableCustomGroup := &model.Group{
|
|
|
|
|
DisplayName: "dn_" + model.NewId(),
|
|
|
|
|
Name: model.NewString("name" + model.NewId()),
|
|
|
|
|
Source: model.GroupSourceCustom,
|
|
|
|
|
AllowReference: false,
|
|
|
|
|
}
|
2023-06-06 23:29:29 +02:00
|
|
|
_, response, err = th.SystemAdminClient.CreateGroup(context.Background(), unReferenceableCustomGroup)
|
2022-02-17 12:34:39 -05:00
|
|
|
require.Error(t, err)
|
2022-08-08 20:02:49 +05:30
|
|
|
CheckBadRequestStatus(t, response)
|
2022-02-17 12:34:39 -05:00
|
|
|
unReferenceableCustomGroup.AllowReference = true
|
2023-06-06 23:29:29 +02:00
|
|
|
_, response, err = th.SystemAdminClient.CreateGroup(context.Background(), unReferenceableCustomGroup)
|
2022-02-17 12:34:39 -05:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
CheckCreatedStatus(t, response)
|
|
|
|
|
|
|
|
|
|
customGroupWithRemoteID := &model.Group{
|
|
|
|
|
DisplayName: "dn_" + model.NewId(),
|
|
|
|
|
Name: model.NewString("name" + model.NewId()),
|
|
|
|
|
Source: model.GroupSourceCustom,
|
|
|
|
|
AllowReference: true,
|
|
|
|
|
RemoteId: model.NewString(model.NewId()),
|
|
|
|
|
}
|
2023-06-06 23:29:29 +02:00
|
|
|
_, response, err = th.SystemAdminClient.CreateGroup(context.Background(), customGroupWithRemoteID)
|
2022-02-17 12:34:39 -05:00
|
|
|
require.Error(t, err)
|
2022-08-08 20:02:49 +05:30
|
|
|
CheckBadRequestStatus(t, response)
|
2022-02-17 12:34:39 -05:00
|
|
|
|
2022-09-29 09:23:27 -04:00
|
|
|
reservedNameGroup := &model.Group{
|
|
|
|
|
DisplayName: "dn_" + model.NewId(),
|
|
|
|
|
Name: model.NewString("here"),
|
|
|
|
|
Source: model.GroupSourceCustom,
|
|
|
|
|
AllowReference: true,
|
|
|
|
|
}
|
2023-06-06 23:29:29 +02:00
|
|
|
_, response, err = th.SystemAdminClient.CreateGroup(context.Background(), reservedNameGroup)
|
2022-09-29 09:23:27 -04:00
|
|
|
require.Error(t, err)
|
|
|
|
|
CheckBadRequestStatus(t, response)
|
|
|
|
|
|
2023-06-06 23:29:29 +02:00
|
|
|
th.SystemAdminClient.Logout(context.Background())
|
|
|
|
|
_, response, err = th.SystemAdminClient.CreateGroup(context.Background(), g)
|
2022-02-17 12:34:39 -05:00
|
|
|
require.Error(t, err)
|
|
|
|
|
CheckUnauthorizedStatus(t, response)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestDeleteGroup(t *testing.T) {
|
|
|
|
|
th := Setup(t)
|
|
|
|
|
defer th.TearDown()
|
|
|
|
|
|
|
|
|
|
id := model.NewId()
|
|
|
|
|
g, appErr := th.App.CreateGroup(&model.Group{
|
|
|
|
|
DisplayName: "dn_" + id,
|
|
|
|
|
Name: model.NewString("name" + id),
|
|
|
|
|
Source: model.GroupSourceLdap,
|
|
|
|
|
Description: "description_" + id,
|
|
|
|
|
RemoteId: model.NewString(model.NewId()),
|
|
|
|
|
})
|
|
|
|
|
assert.Nil(t, appErr)
|
|
|
|
|
|
|
|
|
|
th.App.Srv().SetLicense(model.NewTestLicenseSKU(model.LicenseShortSkuProfessional))
|
|
|
|
|
|
2023-06-06 23:29:29 +02:00
|
|
|
_, response, err := th.Client.DeleteGroup(context.Background(), g.Id)
|
2022-02-17 12:34:39 -05:00
|
|
|
require.Error(t, err)
|
2022-08-08 20:02:49 +05:30
|
|
|
CheckBadRequestStatus(t, response)
|
2022-02-17 12:34:39 -05:00
|
|
|
|
|
|
|
|
th.AddPermissionToRole(model.PermissionDeleteCustomGroup.Id, model.SystemUserRoleId)
|
2023-06-06 23:29:29 +02:00
|
|
|
_, response, err = th.Client.DeleteGroup(context.Background(), g.Id)
|
2022-02-17 12:34:39 -05:00
|
|
|
require.Error(t, err)
|
2022-08-08 20:02:49 +05:30
|
|
|
CheckBadRequestStatus(t, response)
|
2022-02-17 12:34:39 -05:00
|
|
|
|
2023-06-06 23:29:29 +02:00
|
|
|
_, response, err = th.Client.DeleteGroup(context.Background(), g.Id)
|
2022-02-17 12:34:39 -05:00
|
|
|
require.Error(t, err)
|
2022-08-08 20:02:49 +05:30
|
|
|
CheckBadRequestStatus(t, response)
|
2022-02-17 12:34:39 -05:00
|
|
|
|
2023-06-06 23:29:29 +02:00
|
|
|
_, response, err = th.Client.DeleteGroup(context.Background(), "wertyuijhbgvfcde")
|
2022-02-17 12:34:39 -05:00
|
|
|
require.Error(t, err)
|
|
|
|
|
CheckBadRequestStatus(t, response)
|
|
|
|
|
|
|
|
|
|
validGroup, appErr := th.App.CreateGroup(&model.Group{
|
|
|
|
|
DisplayName: "dn_" + model.NewId(),
|
|
|
|
|
Name: model.NewString("name" + model.NewId()),
|
|
|
|
|
Source: model.GroupSourceCustom,
|
|
|
|
|
})
|
|
|
|
|
assert.Nil(t, appErr)
|
|
|
|
|
|
2023-06-06 23:29:29 +02:00
|
|
|
_, response, err = th.Client.DeleteGroup(context.Background(), validGroup.Id)
|
2022-02-17 12:34:39 -05:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
CheckOKStatus(t, response)
|
|
|
|
|
}
|
2022-11-17 14:53:54 +05:30
|
|
|
|
|
|
|
|
func TestUndeleteGroup(t *testing.T) {
|
|
|
|
|
th := Setup(t)
|
|
|
|
|
defer th.TearDown()
|
|
|
|
|
|
|
|
|
|
th.App.Srv().SetLicense(model.NewTestLicenseSKU(model.LicenseShortSkuProfessional))
|
|
|
|
|
|
|
|
|
|
validGroup, appErr := th.App.CreateGroup(&model.Group{
|
|
|
|
|
DisplayName: "dn_" + model.NewId(),
|
|
|
|
|
Name: model.NewString("name" + model.NewId()),
|
|
|
|
|
Source: model.GroupSourceCustom,
|
|
|
|
|
})
|
|
|
|
|
assert.Nil(t, appErr)
|
|
|
|
|
|
2023-06-06 23:29:29 +02:00
|
|
|
_, response, err := th.Client.DeleteGroup(context.Background(), validGroup.Id)
|
2022-11-17 14:53:54 +05:30
|
|
|
require.NoError(t, err)
|
|
|
|
|
CheckOKStatus(t, response)
|
2022-12-19 22:31:59 +05:30
|
|
|
th.RemovePermissionFromRole(model.PermissionRestoreCustomGroup.Id, model.SystemUserRoleId)
|
|
|
|
|
// shouldn't allow restoring unless user has required permission
|
2023-06-06 23:29:29 +02:00
|
|
|
_, response, err = th.Client.RestoreGroup(context.Background(), validGroup.Id, "")
|
2022-12-19 22:31:59 +05:30
|
|
|
require.Error(t, err)
|
|
|
|
|
CheckForbiddenStatus(t, response)
|
2022-11-17 14:53:54 +05:30
|
|
|
|
2022-12-19 22:31:59 +05:30
|
|
|
th.AddPermissionToRole(model.PermissionRestoreCustomGroup.Id, model.SystemUserRoleId)
|
2023-06-06 23:29:29 +02:00
|
|
|
_, response, err = th.Client.RestoreGroup(context.Background(), validGroup.Id, "")
|
2022-11-17 14:53:54 +05:30
|
|
|
require.NoError(t, err)
|
|
|
|
|
CheckOKStatus(t, response)
|
|
|
|
|
|
2023-06-06 23:29:29 +02:00
|
|
|
_, response, err = th.Client.RestoreGroup(context.Background(), validGroup.Id, "")
|
2022-11-17 14:53:54 +05:30
|
|
|
require.Error(t, err)
|
|
|
|
|
CheckNotFoundStatus(t, response)
|
|
|
|
|
}
|
|
|
|
|
|
2019-01-10 15:17:31 -05:00
|
|
|
func TestPatchGroup(t *testing.T) {
|
2020-07-22 13:50:33 +05:30
|
|
|
th := Setup(t)
|
2019-01-10 15:17:31 -05:00
|
|
|
defer th.TearDown()
|
|
|
|
|
|
|
|
|
|
id := model.NewId()
|
2021-08-13 13:12:16 +02:00
|
|
|
g, appErr := th.App.CreateGroup(&model.Group{
|
2019-01-10 15:17:31 -05:00
|
|
|
DisplayName: "dn_" + id,
|
2020-05-26 19:21:29 -06:00
|
|
|
Name: model.NewString("name" + id),
|
2019-01-10 15:17:31 -05:00
|
|
|
Source: model.GroupSourceLdap,
|
|
|
|
|
Description: "description_" + id,
|
2022-02-17 12:34:39 -05:00
|
|
|
RemoteId: model.NewString(model.NewId()),
|
|
|
|
|
})
|
|
|
|
|
assert.Nil(t, appErr)
|
|
|
|
|
|
|
|
|
|
g2, appErr := th.App.CreateGroup(&model.Group{
|
|
|
|
|
DisplayName: "dn_" + model.NewId(),
|
|
|
|
|
Name: model.NewString("name" + model.NewId()),
|
|
|
|
|
Source: model.GroupSourceCustom,
|
|
|
|
|
AllowReference: true,
|
2019-01-10 15:17:31 -05:00
|
|
|
})
|
2021-08-13 13:12:16 +02:00
|
|
|
assert.Nil(t, appErr)
|
2019-01-10 15:17:31 -05:00
|
|
|
|
|
|
|
|
updateFmt := "%s_updated"
|
|
|
|
|
|
2020-05-26 19:21:29 -06:00
|
|
|
newName := fmt.Sprintf(updateFmt, *g.Name)
|
2019-01-10 15:17:31 -05:00
|
|
|
newDisplayName := fmt.Sprintf(updateFmt, g.DisplayName)
|
|
|
|
|
newDescription := fmt.Sprintf(updateFmt, g.Description)
|
|
|
|
|
|
|
|
|
|
gp := &model.GroupPatch{
|
|
|
|
|
Name: &newName,
|
|
|
|
|
DisplayName: &newDisplayName,
|
|
|
|
|
Description: &newDescription,
|
|
|
|
|
}
|
|
|
|
|
|
2023-06-06 23:29:29 +02:00
|
|
|
_, response, err := th.Client.PatchGroup(context.Background(), g.Id, gp)
|
2021-08-13 13:12:16 +02:00
|
|
|
require.Error(t, err)
|
2019-01-10 15:17:31 -05:00
|
|
|
CheckNotImplementedStatus(t, response)
|
|
|
|
|
|
2023-06-06 23:29:29 +02:00
|
|
|
_, response, err = th.SystemAdminClient.PatchGroup(context.Background(), g.Id, gp)
|
2021-08-13 13:12:16 +02:00
|
|
|
require.Error(t, err)
|
2019-01-10 15:17:31 -05:00
|
|
|
CheckNotImplementedStatus(t, response)
|
|
|
|
|
|
2022-02-17 12:34:39 -05:00
|
|
|
th.App.Srv().SetLicense(model.NewTestLicenseSKU(model.LicenseShortSkuProfessional, "ldap"))
|
2019-01-10 15:17:31 -05:00
|
|
|
|
2023-06-06 23:29:29 +02:00
|
|
|
group2, response, err := th.SystemAdminClient.PatchGroup(context.Background(), g.Id, gp)
|
2021-08-13 13:12:16 +02:00
|
|
|
require.NoError(t, err)
|
2019-01-10 15:17:31 -05:00
|
|
|
CheckOKStatus(t, response)
|
|
|
|
|
|
2023-06-06 23:29:29 +02:00
|
|
|
group, _, err := th.SystemAdminClient.GetGroup(context.Background(), g.Id, "")
|
2021-08-13 13:12:16 +02:00
|
|
|
require.NoError(t, err)
|
2019-01-10 15:17:31 -05:00
|
|
|
|
|
|
|
|
assert.Equal(t, *gp.DisplayName, group.DisplayName)
|
|
|
|
|
assert.Equal(t, *gp.DisplayName, group2.DisplayName)
|
2020-05-26 19:21:29 -06:00
|
|
|
assert.Equal(t, *gp.Name, *group.Name)
|
|
|
|
|
assert.Equal(t, *gp.Name, *group2.Name)
|
2019-01-10 15:17:31 -05:00
|
|
|
assert.Equal(t, *gp.Description, group.Description)
|
|
|
|
|
assert.Equal(t, *gp.Description, group2.Description)
|
|
|
|
|
|
|
|
|
|
assert.Equal(t, group2.UpdateAt, group.UpdateAt)
|
|
|
|
|
|
|
|
|
|
assert.Equal(t, g.Source, group.Source)
|
|
|
|
|
assert.Equal(t, g.Source, group2.Source)
|
|
|
|
|
assert.Equal(t, g.RemoteId, group.RemoteId)
|
|
|
|
|
assert.Equal(t, g.RemoteId, group2.RemoteId)
|
|
|
|
|
assert.Equal(t, g.CreateAt, group.CreateAt)
|
|
|
|
|
assert.Equal(t, g.CreateAt, group2.CreateAt)
|
|
|
|
|
assert.Equal(t, g.DeleteAt, group.DeleteAt)
|
|
|
|
|
assert.Equal(t, g.DeleteAt, group2.DeleteAt)
|
|
|
|
|
|
2023-06-06 23:29:29 +02:00
|
|
|
_, response, err = th.SystemAdminClient.PatchGroup(context.Background(), model.NewId(), gp)
|
2021-08-13 13:12:16 +02:00
|
|
|
require.Error(t, err)
|
2019-01-10 15:17:31 -05:00
|
|
|
CheckNotFoundStatus(t, response)
|
|
|
|
|
|
2023-06-06 23:29:29 +02:00
|
|
|
_, response, err = th.SystemAdminClient.PatchGroup(context.Background(), g2.Id, &model.GroupPatch{
|
2022-02-17 12:34:39 -05:00
|
|
|
Name: model.NewString(model.NewId()),
|
|
|
|
|
DisplayName: model.NewString("foo"),
|
|
|
|
|
AllowReference: model.NewBool(false),
|
|
|
|
|
})
|
|
|
|
|
require.Error(t, err)
|
|
|
|
|
CheckBadRequestStatus(t, response)
|
|
|
|
|
|
|
|
|
|
// ensure that omitting the AllowReference field from the patch doesn't patch it to false
|
2023-06-06 23:29:29 +02:00
|
|
|
patchedG2, response, err := th.SystemAdminClient.PatchGroup(context.Background(), g2.Id, &model.GroupPatch{
|
2022-02-17 12:34:39 -05:00
|
|
|
Name: model.NewString(model.NewId()),
|
|
|
|
|
DisplayName: model.NewString("foo"),
|
|
|
|
|
})
|
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
CheckOKStatus(t, response)
|
|
|
|
|
require.Equal(t, true, patchedG2.AllowReference)
|
|
|
|
|
|
2023-06-06 23:29:29 +02:00
|
|
|
_, response, err = th.SystemAdminClient.PatchGroup(context.Background(), g2.Id, &model.GroupPatch{
|
2022-09-29 09:23:27 -04:00
|
|
|
Name: model.NewString("here"),
|
|
|
|
|
})
|
|
|
|
|
require.Error(t, err)
|
|
|
|
|
CheckBadRequestStatus(t, response)
|
|
|
|
|
|
2023-06-06 23:29:29 +02:00
|
|
|
th.SystemAdminClient.Logout(context.Background())
|
|
|
|
|
_, response, err = th.SystemAdminClient.PatchGroup(context.Background(), group.Id, gp)
|
2021-08-13 13:12:16 +02:00
|
|
|
require.Error(t, err)
|
2019-01-10 15:17:31 -05:00
|
|
|
CheckUnauthorizedStatus(t, response)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestLinkGroupTeam(t *testing.T) {
|
2020-02-10 19:31:41 +01:00
|
|
|
th := Setup(t).InitBasic()
|
2019-01-10 15:17:31 -05:00
|
|
|
defer th.TearDown()
|
|
|
|
|
|
|
|
|
|
id := model.NewId()
|
2021-08-13 13:12:16 +02:00
|
|
|
g, appErr := th.App.CreateGroup(&model.Group{
|
2019-01-10 15:17:31 -05:00
|
|
|
DisplayName: "dn_" + id,
|
2020-05-26 19:21:29 -06:00
|
|
|
Name: model.NewString("name" + id),
|
2019-01-10 15:17:31 -05:00
|
|
|
Source: model.GroupSourceLdap,
|
|
|
|
|
Description: "description_" + id,
|
2022-02-17 12:34:39 -05:00
|
|
|
RemoteId: model.NewString(model.NewId()),
|
2019-01-10 15:17:31 -05:00
|
|
|
})
|
2021-08-13 13:12:16 +02:00
|
|
|
assert.Nil(t, appErr)
|
2019-01-10 15:17:31 -05:00
|
|
|
|
|
|
|
|
patch := &model.GroupSyncablePatch{
|
2019-03-12 08:58:18 -04:00
|
|
|
AutoAdd: model.NewBool(true),
|
2019-01-10 15:17:31 -05:00
|
|
|
}
|
|
|
|
|
|
2023-06-06 23:29:29 +02:00
|
|
|
_, response, err := th.Client.LinkGroupSyncable(context.Background(), g.Id, th.BasicTeam.Id, model.GroupSyncableTypeTeam, patch)
|
2021-08-13 13:12:16 +02:00
|
|
|
require.Error(t, err)
|
2019-01-10 15:17:31 -05:00
|
|
|
CheckNotImplementedStatus(t, response)
|
|
|
|
|
|
2023-06-06 23:29:29 +02:00
|
|
|
_, response, err = th.SystemAdminClient.LinkGroupSyncable(context.Background(), g.Id, th.BasicTeam.Id, model.GroupSyncableTypeTeam, patch)
|
2021-08-13 13:12:16 +02:00
|
|
|
require.Error(t, err)
|
2019-01-10 15:17:31 -05:00
|
|
|
CheckNotImplementedStatus(t, response)
|
|
|
|
|
|
2020-06-12 13:43:50 +02:00
|
|
|
th.App.Srv().SetLicense(model.NewTestLicense("ldap"))
|
2019-01-10 15:17:31 -05:00
|
|
|
|
2023-06-06 23:29:29 +02:00
|
|
|
_, _, err = th.Client.LinkGroupSyncable(context.Background(), g.Id, th.BasicTeam.Id, model.GroupSyncableTypeTeam, patch)
|
2021-08-13 13:12:16 +02:00
|
|
|
assert.Error(t, err)
|
2019-05-10 11:47:21 -04:00
|
|
|
|
|
|
|
|
th.UpdateUserToTeamAdmin(th.BasicUser, th.BasicTeam)
|
2023-06-06 23:29:29 +02:00
|
|
|
th.Client.Logout(context.Background())
|
|
|
|
|
th.Client.Login(context.Background(), th.BasicUser.Email, th.BasicUser.Password)
|
2019-05-10 11:47:21 -04:00
|
|
|
|
2023-06-06 23:29:29 +02:00
|
|
|
groupTeam, response, _ := th.Client.LinkGroupSyncable(context.Background(), g.Id, th.BasicTeam.Id, model.GroupSyncableTypeTeam, patch)
|
2019-01-10 15:17:31 -05:00
|
|
|
assert.Equal(t, http.StatusCreated, response.StatusCode)
|
|
|
|
|
assert.NotNil(t, groupTeam)
|
2022-02-28 15:06:26 -05:00
|
|
|
|
|
|
|
|
gid := model.NewId()
|
|
|
|
|
g2, app2Err := th.App.CreateGroup(&model.Group{
|
|
|
|
|
DisplayName: "dn_" + gid,
|
|
|
|
|
Name: model.NewString("name" + gid),
|
|
|
|
|
Source: model.GroupSourceCustom,
|
|
|
|
|
Description: "description_" + gid,
|
|
|
|
|
RemoteId: model.NewString(model.NewId()),
|
|
|
|
|
})
|
|
|
|
|
assert.Nil(t, app2Err)
|
|
|
|
|
|
2023-06-06 23:29:29 +02:00
|
|
|
_, response, err = th.Client.LinkGroupSyncable(context.Background(), g2.Id, th.BasicTeam.Id, model.GroupSyncableTypeTeam, patch)
|
2022-02-28 15:06:26 -05:00
|
|
|
require.Error(t, err)
|
|
|
|
|
CheckBadRequestStatus(t, response)
|
2019-01-10 15:17:31 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestLinkGroupChannel(t *testing.T) {
|
2020-02-10 19:31:41 +01:00
|
|
|
th := Setup(t).InitBasic()
|
2019-01-10 15:17:31 -05:00
|
|
|
defer th.TearDown()
|
|
|
|
|
|
|
|
|
|
id := model.NewId()
|
2021-08-13 13:12:16 +02:00
|
|
|
g, appErr := th.App.CreateGroup(&model.Group{
|
2019-01-10 15:17:31 -05:00
|
|
|
DisplayName: "dn_" + id,
|
2020-05-26 19:21:29 -06:00
|
|
|
Name: model.NewString("name" + id),
|
2019-01-10 15:17:31 -05:00
|
|
|
Source: model.GroupSourceLdap,
|
|
|
|
|
Description: "description_" + id,
|
2022-02-17 12:34:39 -05:00
|
|
|
RemoteId: model.NewString(model.NewId()),
|
2019-01-10 15:17:31 -05:00
|
|
|
})
|
2021-08-13 13:12:16 +02:00
|
|
|
assert.Nil(t, appErr)
|
2019-01-10 15:17:31 -05:00
|
|
|
|
|
|
|
|
patch := &model.GroupSyncablePatch{
|
2019-03-12 08:58:18 -04:00
|
|
|
AutoAdd: model.NewBool(true),
|
2019-01-10 15:17:31 -05:00
|
|
|
}
|
|
|
|
|
|
2023-06-06 23:29:29 +02:00
|
|
|
_, response, err := th.Client.LinkGroupSyncable(context.Background(), g.Id, th.BasicChannel.Id, model.GroupSyncableTypeChannel, patch)
|
2021-08-13 13:12:16 +02:00
|
|
|
require.Error(t, err)
|
2019-01-10 15:17:31 -05:00
|
|
|
CheckNotImplementedStatus(t, response)
|
|
|
|
|
|
2023-06-06 23:29:29 +02:00
|
|
|
_, response, err = th.SystemAdminClient.LinkGroupSyncable(context.Background(), g.Id, th.BasicChannel.Id, model.GroupSyncableTypeChannel, patch)
|
2021-08-13 13:12:16 +02:00
|
|
|
require.Error(t, err)
|
2019-01-10 15:17:31 -05:00
|
|
|
CheckNotImplementedStatus(t, response)
|
|
|
|
|
|
2020-06-12 13:43:50 +02:00
|
|
|
th.App.Srv().SetLicense(model.NewTestLicense("ldap"))
|
2019-01-10 15:17:31 -05:00
|
|
|
|
2023-06-06 23:29:29 +02:00
|
|
|
groupTeam, response, _ := th.Client.LinkGroupSyncable(context.Background(), g.Id, th.BasicChannel.Id, model.GroupSyncableTypeChannel, patch)
|
2019-01-10 15:17:31 -05:00
|
|
|
assert.Equal(t, http.StatusCreated, response.StatusCode)
|
2021-05-26 10:12:34 -04:00
|
|
|
assert.Equal(t, th.BasicChannel.TeamId, groupTeam.TeamID)
|
2019-05-10 11:47:21 -04:00
|
|
|
assert.NotNil(t, groupTeam)
|
|
|
|
|
|
2023-06-06 23:29:29 +02:00
|
|
|
_, err = th.SystemAdminClient.UpdateChannelRoles(context.Background(), th.BasicChannel.Id, th.BasicUser.Id, "")
|
2021-08-13 13:12:16 +02:00
|
|
|
require.NoError(t, err)
|
2023-06-06 23:29:29 +02:00
|
|
|
th.Client.Logout(context.Background())
|
|
|
|
|
th.Client.Login(context.Background(), th.BasicUser.Email, th.BasicUser.Password)
|
2019-05-10 11:47:21 -04:00
|
|
|
|
2023-06-06 23:29:29 +02:00
|
|
|
_, _, err = th.Client.LinkGroupSyncable(context.Background(), g.Id, th.BasicChannel.Id, model.GroupSyncableTypeChannel, patch)
|
2021-08-13 13:12:16 +02:00
|
|
|
assert.Error(t, err)
|
2022-02-28 15:06:26 -05:00
|
|
|
|
|
|
|
|
gid := model.NewId()
|
|
|
|
|
g2, app2Err := th.App.CreateGroup(&model.Group{
|
|
|
|
|
DisplayName: "dn_" + gid,
|
|
|
|
|
Name: model.NewString("name" + gid),
|
|
|
|
|
Source: model.GroupSourceCustom,
|
|
|
|
|
Description: "description_" + gid,
|
|
|
|
|
RemoteId: model.NewString(model.NewId()),
|
|
|
|
|
})
|
|
|
|
|
assert.Nil(t, app2Err)
|
|
|
|
|
|
2023-06-06 23:29:29 +02:00
|
|
|
_, response, err = th.Client.LinkGroupSyncable(context.Background(), g2.Id, th.BasicChannel.Id, model.GroupSyncableTypeChannel, patch)
|
2022-02-28 15:06:26 -05:00
|
|
|
require.Error(t, err)
|
|
|
|
|
CheckBadRequestStatus(t, response)
|
2019-01-10 15:17:31 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestUnlinkGroupTeam(t *testing.T) {
|
2020-02-10 19:31:41 +01:00
|
|
|
th := Setup(t).InitBasic()
|
2019-01-10 15:17:31 -05:00
|
|
|
defer th.TearDown()
|
|
|
|
|
|
|
|
|
|
id := model.NewId()
|
2021-08-13 13:12:16 +02:00
|
|
|
g, appErr := th.App.CreateGroup(&model.Group{
|
2019-01-10 15:17:31 -05:00
|
|
|
DisplayName: "dn_" + id,
|
2020-05-26 19:21:29 -06:00
|
|
|
Name: model.NewString("name" + id),
|
2019-01-10 15:17:31 -05:00
|
|
|
Source: model.GroupSourceLdap,
|
|
|
|
|
Description: "description_" + id,
|
2022-02-17 12:34:39 -05:00
|
|
|
RemoteId: model.NewString(model.NewId()),
|
2019-01-10 15:17:31 -05:00
|
|
|
})
|
2021-08-13 13:12:16 +02:00
|
|
|
assert.Nil(t, appErr)
|
2019-01-10 15:17:31 -05:00
|
|
|
|
|
|
|
|
patch := &model.GroupSyncablePatch{
|
2019-03-12 08:58:18 -04:00
|
|
|
AutoAdd: model.NewBool(true),
|
2019-01-10 15:17:31 -05:00
|
|
|
}
|
|
|
|
|
|
2020-06-12 13:43:50 +02:00
|
|
|
th.App.Srv().SetLicense(model.NewTestLicense("ldap"))
|
2019-01-10 15:17:31 -05:00
|
|
|
|
2023-06-06 23:29:29 +02:00
|
|
|
_, response, _ := th.SystemAdminClient.LinkGroupSyncable(context.Background(), g.Id, th.BasicTeam.Id, model.GroupSyncableTypeTeam, patch)
|
2019-01-10 15:17:31 -05:00
|
|
|
assert.Equal(t, http.StatusCreated, response.StatusCode)
|
|
|
|
|
|
2020-06-12 13:43:50 +02:00
|
|
|
th.App.Srv().SetLicense(nil)
|
2019-01-10 15:17:31 -05:00
|
|
|
|
2023-06-06 23:29:29 +02:00
|
|
|
response, err := th.Client.UnlinkGroupSyncable(context.Background(), g.Id, th.BasicTeam.Id, model.GroupSyncableTypeTeam)
|
2021-08-13 13:12:16 +02:00
|
|
|
require.Error(t, err)
|
2019-01-10 15:17:31 -05:00
|
|
|
CheckNotImplementedStatus(t, response)
|
|
|
|
|
|
2023-06-06 23:29:29 +02:00
|
|
|
response, err = th.SystemAdminClient.UnlinkGroupSyncable(context.Background(), g.Id, th.BasicTeam.Id, model.GroupSyncableTypeTeam)
|
2021-08-13 13:12:16 +02:00
|
|
|
require.Error(t, err)
|
2019-01-10 15:17:31 -05:00
|
|
|
CheckNotImplementedStatus(t, response)
|
|
|
|
|
|
2020-06-12 13:43:50 +02:00
|
|
|
th.App.Srv().SetLicense(model.NewTestLicense("ldap"))
|
2019-01-10 15:17:31 -05:00
|
|
|
|
2023-06-06 23:29:29 +02:00
|
|
|
_, err = th.Client.UnlinkGroupSyncable(context.Background(), g.Id, th.BasicTeam.Id, model.GroupSyncableTypeTeam)
|
2021-08-13 13:12:16 +02:00
|
|
|
assert.Error(t, err)
|
2020-03-07 22:42:23 +05:30
|
|
|
time.Sleep(2 * time.Second) // A hack to let "go c.App.SyncRolesAndMembership" finish before moving on.
|
2019-05-10 11:47:21 -04:00
|
|
|
th.UpdateUserToTeamAdmin(th.BasicUser, th.BasicTeam)
|
2023-06-06 23:29:29 +02:00
|
|
|
response, err = th.Client.Logout(context.Background())
|
2021-08-13 13:12:16 +02:00
|
|
|
require.NoError(t, err)
|
2020-03-03 00:04:39 +05:30
|
|
|
CheckOKStatus(t, response)
|
2023-06-06 23:29:29 +02:00
|
|
|
_, response, err = th.Client.Login(context.Background(), th.BasicUser.Email, th.BasicUser.Password)
|
2021-08-13 13:12:16 +02:00
|
|
|
require.NoError(t, err)
|
2020-03-03 00:04:39 +05:30
|
|
|
CheckOKStatus(t, response)
|
2019-05-10 11:47:21 -04:00
|
|
|
|
2023-06-06 23:29:29 +02:00
|
|
|
response, err = th.Client.UnlinkGroupSyncable(context.Background(), g.Id, th.BasicTeam.Id, model.GroupSyncableTypeTeam)
|
2021-08-13 13:12:16 +02:00
|
|
|
require.NoError(t, err)
|
2019-01-10 15:17:31 -05:00
|
|
|
CheckOKStatus(t, response)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestUnlinkGroupChannel(t *testing.T) {
|
2020-02-10 19:31:41 +01:00
|
|
|
th := Setup(t).InitBasic()
|
2019-01-10 15:17:31 -05:00
|
|
|
defer th.TearDown()
|
|
|
|
|
|
|
|
|
|
id := model.NewId()
|
2021-08-13 13:12:16 +02:00
|
|
|
g, appErr := th.App.CreateGroup(&model.Group{
|
2019-01-10 15:17:31 -05:00
|
|
|
DisplayName: "dn_" + id,
|
2020-05-26 19:21:29 -06:00
|
|
|
Name: model.NewString("name" + id),
|
2019-01-10 15:17:31 -05:00
|
|
|
Source: model.GroupSourceLdap,
|
|
|
|
|
Description: "description_" + id,
|
2022-02-17 12:34:39 -05:00
|
|
|
RemoteId: model.NewString(model.NewId()),
|
2019-01-10 15:17:31 -05:00
|
|
|
})
|
2021-08-13 13:12:16 +02:00
|
|
|
assert.Nil(t, appErr)
|
2019-01-10 15:17:31 -05:00
|
|
|
|
|
|
|
|
patch := &model.GroupSyncablePatch{
|
2019-03-12 08:58:18 -04:00
|
|
|
AutoAdd: model.NewBool(true),
|
2019-01-10 15:17:31 -05:00
|
|
|
}
|
|
|
|
|
|
2020-06-12 13:43:50 +02:00
|
|
|
th.App.Srv().SetLicense(model.NewTestLicense("ldap"))
|
2019-01-10 15:17:31 -05:00
|
|
|
|
2023-06-06 23:29:29 +02:00
|
|
|
_, response, _ := th.SystemAdminClient.LinkGroupSyncable(context.Background(), g.Id, th.BasicChannel.Id, model.GroupSyncableTypeChannel, patch)
|
2019-01-10 15:17:31 -05:00
|
|
|
assert.Equal(t, http.StatusCreated, response.StatusCode)
|
|
|
|
|
|
2020-06-12 13:43:50 +02:00
|
|
|
th.App.Srv().SetLicense(nil)
|
2019-01-10 15:17:31 -05:00
|
|
|
|
2023-06-06 23:29:29 +02:00
|
|
|
response, err := th.Client.UnlinkGroupSyncable(context.Background(), g.Id, th.BasicChannel.Id, model.GroupSyncableTypeChannel)
|
2021-08-13 13:12:16 +02:00
|
|
|
require.Error(t, err)
|
2019-01-10 15:17:31 -05:00
|
|
|
CheckNotImplementedStatus(t, response)
|
|
|
|
|
|
2023-06-06 23:29:29 +02:00
|
|
|
response, err = th.SystemAdminClient.UnlinkGroupSyncable(context.Background(), g.Id, th.BasicChannel.Id, model.GroupSyncableTypeChannel)
|
2021-08-13 13:12:16 +02:00
|
|
|
require.Error(t, err)
|
2019-01-10 15:17:31 -05:00
|
|
|
CheckNotImplementedStatus(t, response)
|
|
|
|
|
|
2020-06-12 13:43:50 +02:00
|
|
|
th.App.Srv().SetLicense(model.NewTestLicense("ldap"))
|
2019-01-10 15:17:31 -05:00
|
|
|
|
2023-06-06 23:29:29 +02:00
|
|
|
_, err = th.SystemAdminClient.UpdateChannelRoles(context.Background(), th.BasicChannel.Id, th.BasicUser.Id, "")
|
2021-08-13 13:12:16 +02:00
|
|
|
require.NoError(t, err)
|
2023-06-06 23:29:29 +02:00
|
|
|
th.Client.Logout(context.Background())
|
|
|
|
|
th.Client.Login(context.Background(), th.BasicUser.Email, th.BasicUser.Password)
|
2019-05-10 11:47:21 -04:00
|
|
|
|
2023-06-06 23:29:29 +02:00
|
|
|
_, err = th.Client.UnlinkGroupSyncable(context.Background(), g.Id, th.BasicChannel.Id, model.GroupSyncableTypeChannel)
|
2021-08-13 13:12:16 +02:00
|
|
|
assert.Error(t, err)
|
2019-05-10 11:47:21 -04:00
|
|
|
|
2023-06-06 23:29:29 +02:00
|
|
|
_, err = th.SystemAdminClient.UpdateChannelRoles(context.Background(), th.BasicChannel.Id, th.BasicUser.Id, "channel_admin channel_user")
|
2021-08-13 13:12:16 +02:00
|
|
|
require.NoError(t, err)
|
2023-06-06 23:29:29 +02:00
|
|
|
th.Client.Logout(context.Background())
|
|
|
|
|
th.Client.Login(context.Background(), th.BasicUser.Email, th.BasicUser.Password)
|
2019-05-10 11:47:21 -04:00
|
|
|
|
2023-06-06 23:29:29 +02:00
|
|
|
_, err = th.Client.UnlinkGroupSyncable(context.Background(), g.Id, th.BasicChannel.Id, model.GroupSyncableTypeChannel)
|
2021-08-13 13:12:16 +02:00
|
|
|
assert.NoError(t, err)
|
2019-01-10 15:17:31 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestGetGroupTeam(t *testing.T) {
|
2020-02-10 19:31:41 +01:00
|
|
|
th := Setup(t).InitBasic()
|
2019-01-10 15:17:31 -05:00
|
|
|
defer th.TearDown()
|
|
|
|
|
|
|
|
|
|
id := model.NewId()
|
2021-08-13 13:12:16 +02:00
|
|
|
g, appErr := th.App.CreateGroup(&model.Group{
|
2019-01-10 15:17:31 -05:00
|
|
|
DisplayName: "dn_" + id,
|
2020-05-26 19:21:29 -06:00
|
|
|
Name: model.NewString("name" + id),
|
2019-01-10 15:17:31 -05:00
|
|
|
Source: model.GroupSourceLdap,
|
|
|
|
|
Description: "description_" + id,
|
2022-02-17 12:34:39 -05:00
|
|
|
RemoteId: model.NewString(model.NewId()),
|
2019-01-10 15:17:31 -05:00
|
|
|
})
|
2021-08-13 13:12:16 +02:00
|
|
|
assert.Nil(t, appErr)
|
2019-01-10 15:17:31 -05:00
|
|
|
|
2023-06-06 23:29:29 +02:00
|
|
|
_, response, err := th.Client.GetGroupSyncable(context.Background(), g.Id, th.BasicTeam.Id, model.GroupSyncableTypeTeam, "")
|
2021-08-13 13:12:16 +02:00
|
|
|
require.Error(t, err)
|
2019-01-10 15:17:31 -05:00
|
|
|
CheckNotImplementedStatus(t, response)
|
|
|
|
|
|
2023-06-06 23:29:29 +02:00
|
|
|
_, response, err = th.SystemAdminClient.GetGroupSyncable(context.Background(), g.Id, th.BasicTeam.Id, model.GroupSyncableTypeTeam, "")
|
2021-08-13 13:12:16 +02:00
|
|
|
require.Error(t, err)
|
2019-01-10 15:17:31 -05:00
|
|
|
CheckNotImplementedStatus(t, response)
|
|
|
|
|
|
2020-06-12 13:43:50 +02:00
|
|
|
th.App.Srv().SetLicense(model.NewTestLicense("ldap"))
|
2019-01-10 15:17:31 -05:00
|
|
|
|
|
|
|
|
patch := &model.GroupSyncablePatch{
|
2019-03-12 08:58:18 -04:00
|
|
|
AutoAdd: model.NewBool(true),
|
2019-01-10 15:17:31 -05:00
|
|
|
}
|
|
|
|
|
|
2023-06-06 23:29:29 +02:00
|
|
|
_, response, _ = th.SystemAdminClient.LinkGroupSyncable(context.Background(), g.Id, th.BasicTeam.Id, model.GroupSyncableTypeTeam, patch)
|
2019-01-10 15:17:31 -05:00
|
|
|
assert.Equal(t, http.StatusCreated, response.StatusCode)
|
|
|
|
|
|
2023-06-06 23:29:29 +02:00
|
|
|
groupSyncable, response, err := th.SystemAdminClient.GetGroupSyncable(context.Background(), g.Id, th.BasicTeam.Id, model.GroupSyncableTypeTeam, "")
|
2021-08-13 13:12:16 +02:00
|
|
|
require.NoError(t, err)
|
2019-01-10 15:17:31 -05:00
|
|
|
CheckOKStatus(t, response)
|
|
|
|
|
assert.NotNil(t, groupSyncable)
|
|
|
|
|
|
|
|
|
|
assert.Equal(t, g.Id, groupSyncable.GroupId)
|
|
|
|
|
assert.Equal(t, th.BasicTeam.Id, groupSyncable.SyncableId)
|
|
|
|
|
assert.Equal(t, *patch.AutoAdd, groupSyncable.AutoAdd)
|
|
|
|
|
|
2023-06-06 23:29:29 +02:00
|
|
|
_, response, err = th.SystemAdminClient.GetGroupSyncable(context.Background(), model.NewId(), th.BasicTeam.Id, model.GroupSyncableTypeTeam, "")
|
2021-08-13 13:12:16 +02:00
|
|
|
require.Error(t, err)
|
2019-01-10 15:17:31 -05:00
|
|
|
CheckNotFoundStatus(t, response)
|
|
|
|
|
|
2023-06-06 23:29:29 +02:00
|
|
|
_, response, err = th.SystemAdminClient.GetGroupSyncable(context.Background(), g.Id, model.NewId(), model.GroupSyncableTypeTeam, "")
|
2021-08-13 13:12:16 +02:00
|
|
|
require.Error(t, err)
|
2019-01-10 15:17:31 -05:00
|
|
|
CheckNotFoundStatus(t, response)
|
|
|
|
|
|
2023-06-06 23:29:29 +02:00
|
|
|
_, response, err = th.SystemAdminClient.GetGroupSyncable(context.Background(), "asdfasdfe3", th.BasicTeam.Id, model.GroupSyncableTypeTeam, "")
|
2021-08-13 13:12:16 +02:00
|
|
|
require.Error(t, err)
|
2019-01-10 15:17:31 -05:00
|
|
|
CheckBadRequestStatus(t, response)
|
|
|
|
|
|
2023-06-06 23:29:29 +02:00
|
|
|
_, response, err = th.SystemAdminClient.GetGroupSyncable(context.Background(), g.Id, "asdfasdfe3", model.GroupSyncableTypeTeam, "")
|
2021-08-13 13:12:16 +02:00
|
|
|
require.Error(t, err)
|
2019-01-10 15:17:31 -05:00
|
|
|
CheckBadRequestStatus(t, response)
|
|
|
|
|
|
2023-06-06 23:29:29 +02:00
|
|
|
th.SystemAdminClient.Logout(context.Background())
|
|
|
|
|
_, response, err = th.SystemAdminClient.GetGroupSyncable(context.Background(), g.Id, th.BasicTeam.Id, model.GroupSyncableTypeTeam, "")
|
2021-08-13 13:12:16 +02:00
|
|
|
require.Error(t, err)
|
2019-01-10 15:17:31 -05:00
|
|
|
CheckUnauthorizedStatus(t, response)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestGetGroupChannel(t *testing.T) {
|
2020-02-10 19:31:41 +01:00
|
|
|
th := Setup(t).InitBasic()
|
2019-01-10 15:17:31 -05:00
|
|
|
defer th.TearDown()
|
|
|
|
|
|
|
|
|
|
id := model.NewId()
|
2021-08-13 13:12:16 +02:00
|
|
|
g, appErr := th.App.CreateGroup(&model.Group{
|
2019-01-10 15:17:31 -05:00
|
|
|
DisplayName: "dn_" + id,
|
2020-05-26 19:21:29 -06:00
|
|
|
Name: model.NewString("name" + id),
|
2019-01-10 15:17:31 -05:00
|
|
|
Source: model.GroupSourceLdap,
|
|
|
|
|
Description: "description_" + id,
|
2022-02-17 12:34:39 -05:00
|
|
|
RemoteId: model.NewString(model.NewId()),
|
2019-01-10 15:17:31 -05:00
|
|
|
})
|
2021-08-13 13:12:16 +02:00
|
|
|
assert.Nil(t, appErr)
|
2019-01-10 15:17:31 -05:00
|
|
|
|
2023-06-06 23:29:29 +02:00
|
|
|
_, response, err := th.Client.GetGroupSyncable(context.Background(), g.Id, th.BasicChannel.Id, model.GroupSyncableTypeChannel, "")
|
2021-08-13 13:12:16 +02:00
|
|
|
require.Error(t, err)
|
2019-01-10 15:17:31 -05:00
|
|
|
CheckNotImplementedStatus(t, response)
|
|
|
|
|
|
2023-06-06 23:29:29 +02:00
|
|
|
_, response, err = th.SystemAdminClient.GetGroupSyncable(context.Background(), g.Id, th.BasicChannel.Id, model.GroupSyncableTypeChannel, "")
|
2021-08-13 13:12:16 +02:00
|
|
|
require.Error(t, err)
|
2019-01-10 15:17:31 -05:00
|
|
|
CheckNotImplementedStatus(t, response)
|
|
|
|
|
|
2020-06-12 13:43:50 +02:00
|
|
|
th.App.Srv().SetLicense(model.NewTestLicense("ldap"))
|
2019-01-10 15:17:31 -05:00
|
|
|
|
|
|
|
|
patch := &model.GroupSyncablePatch{
|
2019-03-12 08:58:18 -04:00
|
|
|
AutoAdd: model.NewBool(true),
|
2019-01-10 15:17:31 -05:00
|
|
|
}
|
|
|
|
|
|
2023-06-06 23:29:29 +02:00
|
|
|
_, response, _ = th.SystemAdminClient.LinkGroupSyncable(context.Background(), g.Id, th.BasicChannel.Id, model.GroupSyncableTypeChannel, patch)
|
2019-01-10 15:17:31 -05:00
|
|
|
assert.Equal(t, http.StatusCreated, response.StatusCode)
|
|
|
|
|
|
2023-06-06 23:29:29 +02:00
|
|
|
groupSyncable, response, err := th.SystemAdminClient.GetGroupSyncable(context.Background(), g.Id, th.BasicChannel.Id, model.GroupSyncableTypeChannel, "")
|
2021-08-13 13:12:16 +02:00
|
|
|
require.NoError(t, err)
|
2019-01-10 15:17:31 -05:00
|
|
|
CheckOKStatus(t, response)
|
|
|
|
|
assert.NotNil(t, groupSyncable)
|
|
|
|
|
|
|
|
|
|
assert.Equal(t, g.Id, groupSyncable.GroupId)
|
|
|
|
|
assert.Equal(t, th.BasicChannel.Id, groupSyncable.SyncableId)
|
|
|
|
|
assert.Equal(t, *patch.AutoAdd, groupSyncable.AutoAdd)
|
|
|
|
|
|
2023-06-06 23:29:29 +02:00
|
|
|
_, response, err = th.SystemAdminClient.GetGroupSyncable(context.Background(), model.NewId(), th.BasicChannel.Id, model.GroupSyncableTypeChannel, "")
|
2021-08-13 13:12:16 +02:00
|
|
|
require.Error(t, err)
|
2019-01-10 15:17:31 -05:00
|
|
|
CheckNotFoundStatus(t, response)
|
|
|
|
|
|
2023-06-06 23:29:29 +02:00
|
|
|
_, response, err = th.SystemAdminClient.GetGroupSyncable(context.Background(), g.Id, model.NewId(), model.GroupSyncableTypeChannel, "")
|
2021-08-13 13:12:16 +02:00
|
|
|
require.Error(t, err)
|
2019-01-10 15:17:31 -05:00
|
|
|
CheckNotFoundStatus(t, response)
|
|
|
|
|
|
2023-06-06 23:29:29 +02:00
|
|
|
_, response, err = th.SystemAdminClient.GetGroupSyncable(context.Background(), "asdfasdfe3", th.BasicChannel.Id, model.GroupSyncableTypeChannel, "")
|
2021-08-13 13:12:16 +02:00
|
|
|
require.Error(t, err)
|
2019-01-10 15:17:31 -05:00
|
|
|
CheckBadRequestStatus(t, response)
|
|
|
|
|
|
2023-06-06 23:29:29 +02:00
|
|
|
_, response, err = th.SystemAdminClient.GetGroupSyncable(context.Background(), g.Id, "asdfasdfe3", model.GroupSyncableTypeChannel, "")
|
2021-08-13 13:12:16 +02:00
|
|
|
require.Error(t, err)
|
2019-01-10 15:17:31 -05:00
|
|
|
CheckBadRequestStatus(t, response)
|
|
|
|
|
|
2023-06-06 23:29:29 +02:00
|
|
|
th.SystemAdminClient.Logout(context.Background())
|
|
|
|
|
_, response, err = th.SystemAdminClient.GetGroupSyncable(context.Background(), g.Id, th.BasicChannel.Id, model.GroupSyncableTypeChannel, "")
|
2021-08-13 13:12:16 +02:00
|
|
|
require.Error(t, err)
|
2019-01-10 15:17:31 -05:00
|
|
|
CheckUnauthorizedStatus(t, response)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestGetGroupTeams(t *testing.T) {
|
2020-07-22 13:50:33 +05:30
|
|
|
th := Setup(t)
|
2019-01-10 15:17:31 -05:00
|
|
|
defer th.TearDown()
|
|
|
|
|
|
|
|
|
|
id := model.NewId()
|
2021-08-13 13:12:16 +02:00
|
|
|
g, appErr := th.App.CreateGroup(&model.Group{
|
2019-01-10 15:17:31 -05:00
|
|
|
DisplayName: "dn_" + id,
|
2020-05-26 19:21:29 -06:00
|
|
|
Name: model.NewString("name" + id),
|
2019-01-10 15:17:31 -05:00
|
|
|
Source: model.GroupSourceLdap,
|
|
|
|
|
Description: "description_" + id,
|
2022-02-17 12:34:39 -05:00
|
|
|
RemoteId: model.NewString(model.NewId()),
|
2019-01-10 15:17:31 -05:00
|
|
|
})
|
2021-08-13 13:12:16 +02:00
|
|
|
assert.Nil(t, appErr)
|
2019-01-10 15:17:31 -05:00
|
|
|
|
2020-06-12 13:43:50 +02:00
|
|
|
th.App.Srv().SetLicense(model.NewTestLicense("ldap"))
|
2019-01-10 15:17:31 -05:00
|
|
|
|
|
|
|
|
patch := &model.GroupSyncablePatch{
|
2019-03-12 08:58:18 -04:00
|
|
|
AutoAdd: model.NewBool(true),
|
2019-01-10 15:17:31 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for i := 0; i < 10; i++ {
|
|
|
|
|
team := th.CreateTeam()
|
2023-06-06 23:29:29 +02:00
|
|
|
_, response, _ := th.SystemAdminClient.LinkGroupSyncable(context.Background(), g.Id, team.Id, model.GroupSyncableTypeTeam, patch)
|
2019-01-10 15:17:31 -05:00
|
|
|
assert.Equal(t, http.StatusCreated, response.StatusCode)
|
|
|
|
|
}
|
|
|
|
|
|
2020-06-12 13:43:50 +02:00
|
|
|
th.App.Srv().SetLicense(nil)
|
2019-01-10 15:17:31 -05:00
|
|
|
|
2023-06-06 23:29:29 +02:00
|
|
|
_, response, err := th.Client.GetGroupSyncables(context.Background(), g.Id, model.GroupSyncableTypeTeam, "")
|
2021-08-13 13:12:16 +02:00
|
|
|
require.Error(t, err)
|
2019-01-10 15:17:31 -05:00
|
|
|
CheckNotImplementedStatus(t, response)
|
|
|
|
|
|
2023-06-06 23:29:29 +02:00
|
|
|
_, response, err = th.SystemAdminClient.GetGroupSyncables(context.Background(), g.Id, model.GroupSyncableTypeTeam, "")
|
2021-08-13 13:12:16 +02:00
|
|
|
require.Error(t, err)
|
2019-01-10 15:17:31 -05:00
|
|
|
CheckNotImplementedStatus(t, response)
|
|
|
|
|
|
2020-06-12 13:43:50 +02:00
|
|
|
th.App.Srv().SetLicense(model.NewTestLicense("ldap"))
|
2019-01-10 15:17:31 -05:00
|
|
|
|
2023-06-06 23:29:29 +02:00
|
|
|
_, response, _ = th.Client.GetGroupSyncables(context.Background(), g.Id, model.GroupSyncableTypeTeam, "")
|
2019-01-10 15:17:31 -05:00
|
|
|
assert.Equal(t, http.StatusForbidden, response.StatusCode)
|
|
|
|
|
|
2023-06-06 23:29:29 +02:00
|
|
|
groupSyncables, response, err := th.SystemAdminClient.GetGroupSyncables(context.Background(), g.Id, model.GroupSyncableTypeTeam, "")
|
2021-08-13 13:12:16 +02:00
|
|
|
require.NoError(t, err)
|
2019-01-10 15:17:31 -05:00
|
|
|
CheckOKStatus(t, response)
|
|
|
|
|
|
|
|
|
|
assert.Len(t, groupSyncables, 10)
|
|
|
|
|
|
2023-06-06 23:29:29 +02:00
|
|
|
th.SystemAdminClient.Logout(context.Background())
|
|
|
|
|
_, response, err = th.SystemAdminClient.GetGroupSyncables(context.Background(), g.Id, model.GroupSyncableTypeTeam, "")
|
2021-08-13 13:12:16 +02:00
|
|
|
require.Error(t, err)
|
2019-01-10 15:17:31 -05:00
|
|
|
CheckUnauthorizedStatus(t, response)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestGetGroupChannels(t *testing.T) {
|
2020-02-10 19:31:41 +01:00
|
|
|
th := Setup(t).InitBasic()
|
2019-01-10 15:17:31 -05:00
|
|
|
defer th.TearDown()
|
|
|
|
|
|
|
|
|
|
id := model.NewId()
|
2021-08-13 13:12:16 +02:00
|
|
|
g, appErr := th.App.CreateGroup(&model.Group{
|
2019-01-10 15:17:31 -05:00
|
|
|
DisplayName: "dn_" + id,
|
2020-05-26 19:21:29 -06:00
|
|
|
Name: model.NewString("name" + id),
|
2019-01-10 15:17:31 -05:00
|
|
|
Source: model.GroupSourceLdap,
|
|
|
|
|
Description: "description_" + id,
|
2022-02-17 12:34:39 -05:00
|
|
|
RemoteId: model.NewString(model.NewId()),
|
2019-01-10 15:17:31 -05:00
|
|
|
})
|
2021-08-13 13:12:16 +02:00
|
|
|
assert.Nil(t, appErr)
|
2019-01-10 15:17:31 -05:00
|
|
|
|
2020-06-12 13:43:50 +02:00
|
|
|
th.App.Srv().SetLicense(model.NewTestLicense("ldap"))
|
2019-01-10 15:17:31 -05:00
|
|
|
|
|
|
|
|
patch := &model.GroupSyncablePatch{
|
2019-03-12 08:58:18 -04:00
|
|
|
AutoAdd: model.NewBool(true),
|
2019-01-10 15:17:31 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for i := 0; i < 10; i++ {
|
|
|
|
|
channel := th.CreatePublicChannel()
|
2023-06-06 23:29:29 +02:00
|
|
|
_, response, _ := th.SystemAdminClient.LinkGroupSyncable(context.Background(), g.Id, channel.Id, model.GroupSyncableTypeChannel, patch)
|
2019-01-10 15:17:31 -05:00
|
|
|
assert.Equal(t, http.StatusCreated, response.StatusCode)
|
|
|
|
|
}
|
|
|
|
|
|
2020-06-12 13:43:50 +02:00
|
|
|
th.App.Srv().SetLicense(nil)
|
2019-01-10 15:17:31 -05:00
|
|
|
|
2023-06-06 23:29:29 +02:00
|
|
|
_, response, err := th.Client.GetGroupSyncables(context.Background(), g.Id, model.GroupSyncableTypeChannel, "")
|
2021-08-13 13:12:16 +02:00
|
|
|
require.Error(t, err)
|
2019-01-10 15:17:31 -05:00
|
|
|
CheckNotImplementedStatus(t, response)
|
|
|
|
|
|
2023-06-06 23:29:29 +02:00
|
|
|
_, response, err = th.SystemAdminClient.GetGroupSyncables(context.Background(), g.Id, model.GroupSyncableTypeChannel, "")
|
2021-08-13 13:12:16 +02:00
|
|
|
require.Error(t, err)
|
2019-01-10 15:17:31 -05:00
|
|
|
CheckNotImplementedStatus(t, response)
|
|
|
|
|
|
2020-06-12 13:43:50 +02:00
|
|
|
th.App.Srv().SetLicense(model.NewTestLicense("ldap"))
|
2019-01-10 15:17:31 -05:00
|
|
|
|
2023-06-06 23:29:29 +02:00
|
|
|
_, response, _ = th.Client.GetGroupSyncables(context.Background(), g.Id, model.GroupSyncableTypeChannel, "")
|
2019-01-10 15:17:31 -05:00
|
|
|
assert.Equal(t, http.StatusForbidden, response.StatusCode)
|
|
|
|
|
|
2023-06-06 23:29:29 +02:00
|
|
|
groupSyncables, response, _ := th.SystemAdminClient.GetGroupSyncables(context.Background(), g.Id, model.GroupSyncableTypeChannel, "")
|
2019-01-10 15:17:31 -05:00
|
|
|
CheckOKStatus(t, response)
|
|
|
|
|
|
|
|
|
|
assert.Len(t, groupSyncables, 10)
|
|
|
|
|
|
2023-06-06 23:29:29 +02:00
|
|
|
th.SystemAdminClient.Logout(context.Background())
|
|
|
|
|
_, response, err = th.SystemAdminClient.GetGroupSyncables(context.Background(), g.Id, model.GroupSyncableTypeChannel, "")
|
2021-08-13 13:12:16 +02:00
|
|
|
require.Error(t, err)
|
2019-01-10 15:17:31 -05:00
|
|
|
CheckUnauthorizedStatus(t, response)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestPatchGroupTeam(t *testing.T) {
|
2020-02-10 19:31:41 +01:00
|
|
|
th := Setup(t).InitBasic()
|
2019-01-10 15:17:31 -05:00
|
|
|
defer th.TearDown()
|
|
|
|
|
|
|
|
|
|
id := model.NewId()
|
2021-08-13 13:12:16 +02:00
|
|
|
g, appErr := th.App.CreateGroup(&model.Group{
|
2019-01-10 15:17:31 -05:00
|
|
|
DisplayName: "dn_" + id,
|
2020-05-26 19:21:29 -06:00
|
|
|
Name: model.NewString("name" + id),
|
2019-01-10 15:17:31 -05:00
|
|
|
Source: model.GroupSourceLdap,
|
|
|
|
|
Description: "description_" + id,
|
2022-02-17 12:34:39 -05:00
|
|
|
RemoteId: model.NewString(model.NewId()),
|
2019-01-10 15:17:31 -05:00
|
|
|
})
|
2021-08-13 13:12:16 +02:00
|
|
|
assert.Nil(t, appErr)
|
2019-01-10 15:17:31 -05:00
|
|
|
|
|
|
|
|
patch := &model.GroupSyncablePatch{
|
2019-03-12 08:58:18 -04:00
|
|
|
AutoAdd: model.NewBool(true),
|
2019-01-10 15:17:31 -05:00
|
|
|
}
|
|
|
|
|
|
2020-06-12 13:43:50 +02:00
|
|
|
th.App.Srv().SetLicense(model.NewTestLicense("ldap"))
|
2019-01-10 15:17:31 -05:00
|
|
|
|
2023-06-06 23:29:29 +02:00
|
|
|
groupSyncable, response, _ := th.SystemAdminClient.LinkGroupSyncable(context.Background(), g.Id, th.BasicTeam.Id, model.GroupSyncableTypeTeam, patch)
|
2019-01-10 15:17:31 -05:00
|
|
|
assert.Equal(t, http.StatusCreated, response.StatusCode)
|
|
|
|
|
assert.NotNil(t, groupSyncable)
|
|
|
|
|
assert.True(t, groupSyncable.AutoAdd)
|
|
|
|
|
|
2023-06-06 23:29:29 +02:00
|
|
|
_, response, _ = th.Client.PatchGroupSyncable(context.Background(), g.Id, th.BasicTeam.Id, model.GroupSyncableTypeTeam, patch)
|
2019-01-10 15:17:31 -05:00
|
|
|
assert.Equal(t, http.StatusForbidden, response.StatusCode)
|
|
|
|
|
|
2020-06-12 13:43:50 +02:00
|
|
|
th.App.Srv().SetLicense(nil)
|
2019-01-10 15:17:31 -05:00
|
|
|
|
2023-06-06 23:29:29 +02:00
|
|
|
_, response, err := th.SystemAdminClient.PatchGroupSyncable(context.Background(), g.Id, th.BasicTeam.Id, model.GroupSyncableTypeTeam, patch)
|
2021-08-13 13:12:16 +02:00
|
|
|
require.Error(t, err)
|
2019-01-10 15:17:31 -05:00
|
|
|
CheckNotImplementedStatus(t, response)
|
|
|
|
|
|
2020-06-12 13:43:50 +02:00
|
|
|
th.App.Srv().SetLicense(model.NewTestLicense("ldap"))
|
2019-01-10 15:17:31 -05:00
|
|
|
|
|
|
|
|
patch.AutoAdd = model.NewBool(false)
|
2023-06-06 23:29:29 +02:00
|
|
|
groupSyncable, response, err = th.SystemAdminClient.PatchGroupSyncable(context.Background(), g.Id, th.BasicTeam.Id, model.GroupSyncableTypeTeam, patch)
|
2021-08-13 13:12:16 +02:00
|
|
|
require.NoError(t, err)
|
2019-01-10 15:17:31 -05:00
|
|
|
CheckOKStatus(t, response)
|
|
|
|
|
assert.False(t, groupSyncable.AutoAdd)
|
|
|
|
|
|
|
|
|
|
assert.Equal(t, g.Id, groupSyncable.GroupId)
|
|
|
|
|
assert.Equal(t, th.BasicTeam.Id, groupSyncable.SyncableId)
|
|
|
|
|
assert.Equal(t, model.GroupSyncableTypeTeam, groupSyncable.Type)
|
|
|
|
|
|
|
|
|
|
patch.AutoAdd = model.NewBool(true)
|
2023-06-06 23:29:29 +02:00
|
|
|
_, response, _ = th.SystemAdminClient.PatchGroupSyncable(context.Background(), g.Id, th.BasicTeam.Id, model.GroupSyncableTypeTeam, patch)
|
2019-01-10 15:17:31 -05:00
|
|
|
CheckOKStatus(t, response)
|
|
|
|
|
|
2023-06-06 23:29:29 +02:00
|
|
|
_, response, err = th.SystemAdminClient.PatchGroupSyncable(context.Background(), model.NewId(), th.BasicTeam.Id, model.GroupSyncableTypeTeam, patch)
|
2021-08-13 13:12:16 +02:00
|
|
|
require.Error(t, err)
|
2019-01-10 15:17:31 -05:00
|
|
|
CheckNotFoundStatus(t, response)
|
|
|
|
|
|
2023-06-06 23:29:29 +02:00
|
|
|
_, response, err = th.SystemAdminClient.PatchGroupSyncable(context.Background(), g.Id, model.NewId(), model.GroupSyncableTypeTeam, patch)
|
2021-08-13 13:12:16 +02:00
|
|
|
require.Error(t, err)
|
2019-01-10 15:17:31 -05:00
|
|
|
CheckNotFoundStatus(t, response)
|
|
|
|
|
|
2023-06-06 23:29:29 +02:00
|
|
|
_, response, err = th.SystemAdminClient.PatchGroupSyncable(context.Background(), "abc", th.BasicTeam.Id, model.GroupSyncableTypeTeam, patch)
|
2021-08-13 13:12:16 +02:00
|
|
|
require.Error(t, err)
|
2019-01-10 15:17:31 -05:00
|
|
|
CheckBadRequestStatus(t, response)
|
|
|
|
|
|
2023-06-06 23:29:29 +02:00
|
|
|
_, response, err = th.SystemAdminClient.PatchGroupSyncable(context.Background(), g.Id, "abc", model.GroupSyncableTypeTeam, patch)
|
2021-08-13 13:12:16 +02:00
|
|
|
require.Error(t, err)
|
2019-01-10 15:17:31 -05:00
|
|
|
CheckBadRequestStatus(t, response)
|
|
|
|
|
|
2023-06-06 23:29:29 +02:00
|
|
|
th.SystemAdminClient.Logout(context.Background())
|
|
|
|
|
_, response, err = th.SystemAdminClient.PatchGroupSyncable(context.Background(), g.Id, th.BasicTeam.Id, model.GroupSyncableTypeTeam, patch)
|
2021-08-13 13:12:16 +02:00
|
|
|
require.Error(t, err)
|
2019-01-10 15:17:31 -05:00
|
|
|
CheckUnauthorizedStatus(t, response)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestPatchGroupChannel(t *testing.T) {
|
2020-02-10 19:31:41 +01:00
|
|
|
th := Setup(t).InitBasic()
|
2019-01-10 15:17:31 -05:00
|
|
|
defer th.TearDown()
|
|
|
|
|
|
|
|
|
|
id := model.NewId()
|
2021-08-13 13:12:16 +02:00
|
|
|
g, appErr := th.App.CreateGroup(&model.Group{
|
2019-01-10 15:17:31 -05:00
|
|
|
DisplayName: "dn_" + id,
|
2020-05-26 19:21:29 -06:00
|
|
|
Name: model.NewString("name" + id),
|
2019-01-10 15:17:31 -05:00
|
|
|
Source: model.GroupSourceLdap,
|
|
|
|
|
Description: "description_" + id,
|
2022-02-17 12:34:39 -05:00
|
|
|
RemoteId: model.NewString(model.NewId()),
|
2019-01-10 15:17:31 -05:00
|
|
|
})
|
2021-08-13 13:12:16 +02:00
|
|
|
assert.Nil(t, appErr)
|
2019-01-10 15:17:31 -05:00
|
|
|
|
|
|
|
|
patch := &model.GroupSyncablePatch{
|
2019-03-12 08:58:18 -04:00
|
|
|
AutoAdd: model.NewBool(true),
|
2019-01-10 15:17:31 -05:00
|
|
|
}
|
|
|
|
|
|
2020-06-12 13:43:50 +02:00
|
|
|
th.App.Srv().SetLicense(model.NewTestLicense("ldap"))
|
2019-01-10 15:17:31 -05:00
|
|
|
|
2023-06-06 23:29:29 +02:00
|
|
|
groupSyncable, response, _ := th.SystemAdminClient.LinkGroupSyncable(context.Background(), g.Id, th.BasicChannel.Id, model.GroupSyncableTypeChannel, patch)
|
2019-01-10 15:17:31 -05:00
|
|
|
assert.Equal(t, http.StatusCreated, response.StatusCode)
|
|
|
|
|
assert.NotNil(t, groupSyncable)
|
|
|
|
|
assert.True(t, groupSyncable.AutoAdd)
|
|
|
|
|
|
2021-08-13 13:12:16 +02:00
|
|
|
role, appErr := th.App.GetRoleByName(context.Background(), "channel_user")
|
|
|
|
|
require.Nil(t, appErr)
|
2020-01-10 12:19:39 -05:00
|
|
|
originalPermissions := role.Permissions
|
2021-08-13 13:12:16 +02:00
|
|
|
_, appErr = th.App.PatchRole(role, &model.RolePatch{Permissions: &[]string{}})
|
|
|
|
|
require.Nil(t, appErr)
|
2020-01-10 12:19:39 -05:00
|
|
|
|
2023-06-06 23:29:29 +02:00
|
|
|
_, response, _ = th.Client.PatchGroupSyncable(context.Background(), g.Id, th.BasicChannel.Id, model.GroupSyncableTypeChannel, patch)
|
2019-01-10 15:17:31 -05:00
|
|
|
assert.Equal(t, http.StatusForbidden, response.StatusCode)
|
|
|
|
|
|
2021-08-13 13:12:16 +02:00
|
|
|
_, appErr = th.App.PatchRole(role, &model.RolePatch{Permissions: &originalPermissions})
|
|
|
|
|
require.Nil(t, appErr)
|
2020-01-10 12:19:39 -05:00
|
|
|
|
2020-06-12 13:43:50 +02:00
|
|
|
th.App.Srv().SetLicense(nil)
|
2019-01-10 15:17:31 -05:00
|
|
|
|
2023-06-06 23:29:29 +02:00
|
|
|
_, response, err := th.SystemAdminClient.PatchGroupSyncable(context.Background(), g.Id, th.BasicChannel.Id, model.GroupSyncableTypeChannel, patch)
|
2021-08-13 13:12:16 +02:00
|
|
|
require.Error(t, err)
|
2019-01-10 15:17:31 -05:00
|
|
|
CheckNotImplementedStatus(t, response)
|
|
|
|
|
|
2020-06-12 13:43:50 +02:00
|
|
|
th.App.Srv().SetLicense(model.NewTestLicense("ldap"))
|
2019-01-10 15:17:31 -05:00
|
|
|
|
|
|
|
|
patch.AutoAdd = model.NewBool(false)
|
2023-06-06 23:29:29 +02:00
|
|
|
groupSyncable, response, err = th.SystemAdminClient.PatchGroupSyncable(context.Background(), g.Id, th.BasicChannel.Id, model.GroupSyncableTypeChannel, patch)
|
2021-08-13 13:12:16 +02:00
|
|
|
require.NoError(t, err)
|
2019-01-10 15:17:31 -05:00
|
|
|
CheckOKStatus(t, response)
|
|
|
|
|
assert.False(t, groupSyncable.AutoAdd)
|
|
|
|
|
|
|
|
|
|
assert.Equal(t, g.Id, groupSyncable.GroupId)
|
|
|
|
|
assert.Equal(t, th.BasicChannel.Id, groupSyncable.SyncableId)
|
2021-05-26 10:12:34 -04:00
|
|
|
assert.Equal(t, th.BasicChannel.TeamId, groupSyncable.TeamID)
|
2019-01-10 15:17:31 -05:00
|
|
|
assert.Equal(t, model.GroupSyncableTypeChannel, groupSyncable.Type)
|
|
|
|
|
|
|
|
|
|
patch.AutoAdd = model.NewBool(true)
|
2023-06-06 23:29:29 +02:00
|
|
|
_, response, err = th.SystemAdminClient.PatchGroupSyncable(context.Background(), g.Id, th.BasicChannel.Id, model.GroupSyncableTypeChannel, patch)
|
2021-08-13 13:12:16 +02:00
|
|
|
require.NoError(t, err)
|
2019-01-10 15:17:31 -05:00
|
|
|
CheckOKStatus(t, response)
|
|
|
|
|
|
2023-06-06 23:29:29 +02:00
|
|
|
_, response, err = th.SystemAdminClient.PatchGroupSyncable(context.Background(), model.NewId(), th.BasicChannel.Id, model.GroupSyncableTypeChannel, patch)
|
2021-08-13 13:12:16 +02:00
|
|
|
require.Error(t, err)
|
2019-01-10 15:17:31 -05:00
|
|
|
CheckNotFoundStatus(t, response)
|
|
|
|
|
|
2023-06-06 23:29:29 +02:00
|
|
|
_, response, err = th.SystemAdminClient.PatchGroupSyncable(context.Background(), g.Id, model.NewId(), model.GroupSyncableTypeChannel, patch)
|
2021-08-13 13:12:16 +02:00
|
|
|
require.Error(t, err)
|
2019-01-10 15:17:31 -05:00
|
|
|
CheckNotFoundStatus(t, response)
|
|
|
|
|
|
2023-06-06 23:29:29 +02:00
|
|
|
_, response, err = th.SystemAdminClient.PatchGroupSyncable(context.Background(), "abc", th.BasicChannel.Id, model.GroupSyncableTypeChannel, patch)
|
2021-08-13 13:12:16 +02:00
|
|
|
require.Error(t, err)
|
2019-01-10 15:17:31 -05:00
|
|
|
CheckBadRequestStatus(t, response)
|
|
|
|
|
|
2023-06-06 23:29:29 +02:00
|
|
|
_, response, err = th.SystemAdminClient.PatchGroupSyncable(context.Background(), g.Id, "abc", model.GroupSyncableTypeChannel, patch)
|
2021-08-13 13:12:16 +02:00
|
|
|
require.Error(t, err)
|
2019-01-10 15:17:31 -05:00
|
|
|
CheckBadRequestStatus(t, response)
|
|
|
|
|
|
2023-06-06 23:29:29 +02:00
|
|
|
th.SystemAdminClient.Logout(context.Background())
|
|
|
|
|
_, response, err = th.SystemAdminClient.PatchGroupSyncable(context.Background(), g.Id, th.BasicChannel.Id, model.GroupSyncableTypeChannel, patch)
|
2021-08-13 13:12:16 +02:00
|
|
|
require.Error(t, err)
|
2019-01-10 15:17:31 -05:00
|
|
|
CheckUnauthorizedStatus(t, response)
|
|
|
|
|
}
|
2019-04-02 21:02:51 +01:00
|
|
|
|
|
|
|
|
func TestGetGroupsByChannel(t *testing.T) {
|
2020-02-10 19:31:41 +01:00
|
|
|
th := Setup(t).InitBasic()
|
2019-04-02 21:02:51 +01:00
|
|
|
defer th.TearDown()
|
|
|
|
|
|
|
|
|
|
id := model.NewId()
|
2021-08-13 13:12:16 +02:00
|
|
|
group, appErr := th.App.CreateGroup(&model.Group{
|
2019-04-02 21:02:51 +01:00
|
|
|
DisplayName: "dn_" + id,
|
2020-05-26 19:21:29 -06:00
|
|
|
Name: model.NewString("name" + id),
|
2019-04-02 21:02:51 +01:00
|
|
|
Source: model.GroupSourceLdap,
|
|
|
|
|
Description: "description_" + id,
|
2022-02-17 12:34:39 -05:00
|
|
|
RemoteId: model.NewString(model.NewId()),
|
2019-04-02 21:02:51 +01:00
|
|
|
})
|
2021-08-13 13:12:16 +02:00
|
|
|
assert.Nil(t, appErr)
|
2019-04-02 21:02:51 +01:00
|
|
|
|
2021-08-13 13:12:16 +02:00
|
|
|
groupSyncable, appErr := th.App.UpsertGroupSyncable(&model.GroupSyncable{
|
2019-04-02 21:02:51 +01:00
|
|
|
AutoAdd: true,
|
|
|
|
|
SyncableId: th.BasicChannel.Id,
|
|
|
|
|
Type: model.GroupSyncableTypeChannel,
|
|
|
|
|
GroupId: group.Id,
|
|
|
|
|
})
|
2021-08-13 13:12:16 +02:00
|
|
|
assert.Nil(t, appErr)
|
2019-04-02 21:02:51 +01:00
|
|
|
|
2019-05-15 12:03:47 -04:00
|
|
|
opts := model.GroupSearchOpts{
|
|
|
|
|
PageOpts: &model.PageOpts{
|
|
|
|
|
Page: 0,
|
|
|
|
|
PerPage: 60,
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
|
2022-02-17 12:34:39 -05:00
|
|
|
th.App.Srv().SetLicense(model.NewTestLicense("ldap"))
|
|
|
|
|
|
2020-06-01 15:31:05 +05:30
|
|
|
th.TestForSystemAdminAndLocal(t, func(t *testing.T, client *model.Client4) {
|
2023-06-06 23:29:29 +02:00
|
|
|
_, _, response, err := client.GetGroupsByChannel(context.Background(), "asdfasdf", opts)
|
2021-08-13 13:12:16 +02:00
|
|
|
require.Error(t, err)
|
2020-06-01 15:31:05 +05:30
|
|
|
CheckBadRequestStatus(t, response)
|
|
|
|
|
})
|
2019-04-02 21:02:51 +01:00
|
|
|
|
2020-06-12 13:43:50 +02:00
|
|
|
th.App.Srv().SetLicense(nil)
|
2019-04-02 21:02:51 +01:00
|
|
|
|
2020-06-01 15:31:05 +05:30
|
|
|
th.TestForSystemAdminAndLocal(t, func(t *testing.T, client *model.Client4) {
|
2023-06-06 23:29:29 +02:00
|
|
|
_, _, response, err := client.GetGroupsByChannel(context.Background(), th.BasicChannel.Id, opts)
|
2021-08-13 13:12:16 +02:00
|
|
|
require.Error(t, err)
|
2022-08-08 20:02:49 +05:30
|
|
|
if client == th.SystemAdminClient {
|
|
|
|
|
CheckNotImplementedStatus(t, response)
|
|
|
|
|
} else {
|
|
|
|
|
CheckForbiddenStatus(t, response)
|
|
|
|
|
}
|
2020-06-01 15:31:05 +05:30
|
|
|
})
|
2019-04-02 21:02:51 +01:00
|
|
|
|
2020-06-12 13:43:50 +02:00
|
|
|
th.App.Srv().SetLicense(model.NewTestLicense("ldap"))
|
2019-04-02 21:02:51 +01:00
|
|
|
|
2021-07-12 20:05:36 +02:00
|
|
|
privateChannel := th.CreateChannelWithClient(th.SystemAdminClient, model.ChannelTypePrivate)
|
2019-05-15 12:03:47 -04:00
|
|
|
|
2023-06-06 23:29:29 +02:00
|
|
|
_, _, response, err := th.Client.GetGroupsByChannel(context.Background(), privateChannel.Id, opts)
|
2021-08-13 13:12:16 +02:00
|
|
|
require.Error(t, err)
|
2019-04-02 21:02:51 +01:00
|
|
|
CheckForbiddenStatus(t, response)
|
|
|
|
|
|
2020-06-01 15:31:05 +05:30
|
|
|
th.TestForSystemAdminAndLocal(t, func(t *testing.T, client *model.Client4) {
|
2021-08-13 13:12:16 +02:00
|
|
|
var groups []*model.GroupWithSchemeAdmin
|
2023-06-06 23:29:29 +02:00
|
|
|
groups, _, _, err = client.GetGroupsByChannel(context.Background(), th.BasicChannel.Id, opts)
|
2021-08-13 13:12:16 +02:00
|
|
|
assert.NoError(t, err)
|
2020-06-01 15:31:05 +05:30
|
|
|
assert.ElementsMatch(t, []*model.GroupWithSchemeAdmin{{Group: *group, SchemeAdmin: model.NewBool(false)}}, groups)
|
|
|
|
|
require.NotNil(t, groups[0].SchemeAdmin)
|
|
|
|
|
require.False(t, *groups[0].SchemeAdmin)
|
|
|
|
|
})
|
2020-01-10 12:19:39 -05:00
|
|
|
|
|
|
|
|
// set syncable to true
|
|
|
|
|
groupSyncable.SchemeAdmin = true
|
2021-08-13 13:12:16 +02:00
|
|
|
_, appErr = th.App.UpdateGroupSyncable(groupSyncable)
|
|
|
|
|
require.Nil(t, appErr)
|
2020-01-10 12:19:39 -05:00
|
|
|
|
2020-06-01 15:31:05 +05:30
|
|
|
th.TestForSystemAdminAndLocal(t, func(t *testing.T, client *model.Client4) {
|
2023-06-06 23:29:29 +02:00
|
|
|
groups, _, _, err := client.GetGroupsByChannel(context.Background(), th.BasicChannel.Id, opts)
|
2021-08-13 13:12:16 +02:00
|
|
|
assert.NoError(t, err)
|
2020-06-01 15:31:05 +05:30
|
|
|
// ensure that SchemeAdmin field is updated
|
|
|
|
|
assert.ElementsMatch(t, []*model.GroupWithSchemeAdmin{{Group: *group, SchemeAdmin: model.NewBool(true)}}, groups)
|
|
|
|
|
require.NotNil(t, groups[0].SchemeAdmin)
|
|
|
|
|
require.True(t, *groups[0].SchemeAdmin)
|
|
|
|
|
|
2023-06-06 23:29:29 +02:00
|
|
|
groups, _, _, err = client.GetGroupsByChannel(context.Background(), model.NewId(), opts)
|
2021-08-13 13:12:16 +02:00
|
|
|
CheckErrorID(t, err, "app.channel.get.existing.app_error")
|
2020-06-01 15:31:05 +05:30
|
|
|
assert.Empty(t, groups)
|
|
|
|
|
})
|
2019-04-02 21:02:51 +01:00
|
|
|
}
|
|
|
|
|
|
2020-04-13 11:37:29 -07:00
|
|
|
func TestGetGroupsAssociatedToChannelsByTeam(t *testing.T) {
|
|
|
|
|
th := Setup(t).InitBasic()
|
|
|
|
|
defer th.TearDown()
|
|
|
|
|
|
|
|
|
|
id := model.NewId()
|
2021-08-13 13:12:16 +02:00
|
|
|
group, appErr := th.App.CreateGroup(&model.Group{
|
2020-04-13 11:37:29 -07:00
|
|
|
DisplayName: "dn_" + id,
|
2020-05-26 19:21:29 -06:00
|
|
|
Name: model.NewString("name" + id),
|
2020-04-13 11:37:29 -07:00
|
|
|
Source: model.GroupSourceLdap,
|
|
|
|
|
Description: "description_" + id,
|
2022-02-17 12:34:39 -05:00
|
|
|
RemoteId: model.NewString(model.NewId()),
|
2020-04-13 11:37:29 -07:00
|
|
|
})
|
2021-08-13 13:12:16 +02:00
|
|
|
assert.Nil(t, appErr)
|
2020-04-13 11:37:29 -07:00
|
|
|
|
2021-08-13 13:12:16 +02:00
|
|
|
groupSyncable, appErr := th.App.UpsertGroupSyncable(&model.GroupSyncable{
|
2020-04-13 11:37:29 -07:00
|
|
|
AutoAdd: true,
|
|
|
|
|
SyncableId: th.BasicChannel.Id,
|
|
|
|
|
Type: model.GroupSyncableTypeChannel,
|
|
|
|
|
GroupId: group.Id,
|
|
|
|
|
})
|
2021-08-13 13:12:16 +02:00
|
|
|
assert.Nil(t, appErr)
|
2020-04-13 11:37:29 -07:00
|
|
|
|
|
|
|
|
opts := model.GroupSearchOpts{
|
|
|
|
|
PageOpts: &model.PageOpts{
|
|
|
|
|
Page: 0,
|
|
|
|
|
PerPage: 60,
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
|
2022-02-17 12:34:39 -05:00
|
|
|
th.App.Srv().SetLicense(model.NewTestLicense("ldap"))
|
|
|
|
|
|
2023-06-06 23:29:29 +02:00
|
|
|
_, response, err := th.SystemAdminClient.GetGroupsAssociatedToChannelsByTeam(context.Background(), "asdfasdf", opts)
|
2021-08-13 13:12:16 +02:00
|
|
|
require.Error(t, err)
|
2020-04-13 11:37:29 -07:00
|
|
|
CheckBadRequestStatus(t, response)
|
|
|
|
|
|
2020-06-12 13:43:50 +02:00
|
|
|
th.App.Srv().SetLicense(nil)
|
2020-04-13 11:37:29 -07:00
|
|
|
|
2023-06-06 23:29:29 +02:00
|
|
|
_, response, err = th.SystemAdminClient.GetGroupsAssociatedToChannelsByTeam(context.Background(), th.BasicTeam.Id, opts)
|
2021-08-13 13:12:16 +02:00
|
|
|
require.Error(t, err)
|
2020-04-13 11:37:29 -07:00
|
|
|
CheckNotImplementedStatus(t, response)
|
|
|
|
|
|
2020-06-12 13:43:50 +02:00
|
|
|
th.App.Srv().SetLicense(model.NewTestLicense("ldap"))
|
2020-04-13 11:37:29 -07:00
|
|
|
|
2023-06-06 23:29:29 +02:00
|
|
|
groups, _, err := th.SystemAdminClient.GetGroupsAssociatedToChannelsByTeam(context.Background(), th.BasicTeam.Id, opts)
|
2021-08-13 13:12:16 +02:00
|
|
|
assert.NoError(t, err)
|
2020-04-13 11:37:29 -07:00
|
|
|
|
|
|
|
|
assert.Equal(t, map[string][]*model.GroupWithSchemeAdmin{
|
|
|
|
|
th.BasicChannel.Id: {
|
|
|
|
|
{Group: *group, SchemeAdmin: model.NewBool(false)},
|
|
|
|
|
},
|
|
|
|
|
}, groups)
|
|
|
|
|
|
|
|
|
|
require.NotNil(t, groups[th.BasicChannel.Id][0].SchemeAdmin)
|
|
|
|
|
require.False(t, *groups[th.BasicChannel.Id][0].SchemeAdmin)
|
|
|
|
|
|
|
|
|
|
// set syncable to true
|
|
|
|
|
groupSyncable.SchemeAdmin = true
|
2021-08-13 13:12:16 +02:00
|
|
|
_, appErr = th.App.UpdateGroupSyncable(groupSyncable)
|
|
|
|
|
require.Nil(t, appErr)
|
2020-04-13 11:37:29 -07:00
|
|
|
|
|
|
|
|
// ensure that SchemeAdmin field is updated
|
2023-06-06 23:29:29 +02:00
|
|
|
groups, _, err = th.SystemAdminClient.GetGroupsAssociatedToChannelsByTeam(context.Background(), th.BasicTeam.Id, opts)
|
2021-08-13 13:12:16 +02:00
|
|
|
assert.NoError(t, err)
|
2020-04-13 11:37:29 -07:00
|
|
|
|
|
|
|
|
assert.Equal(t, map[string][]*model.GroupWithSchemeAdmin{
|
|
|
|
|
th.BasicChannel.Id: {
|
|
|
|
|
{Group: *group, SchemeAdmin: model.NewBool(true)},
|
|
|
|
|
},
|
|
|
|
|
}, groups)
|
|
|
|
|
|
|
|
|
|
require.NotNil(t, groups[th.BasicChannel.Id][0].SchemeAdmin)
|
|
|
|
|
require.True(t, *groups[th.BasicChannel.Id][0].SchemeAdmin)
|
|
|
|
|
|
2023-06-06 23:29:29 +02:00
|
|
|
groups, _, err = th.SystemAdminClient.GetGroupsAssociatedToChannelsByTeam(context.Background(), model.NewId(), opts)
|
2021-08-13 13:12:16 +02:00
|
|
|
assert.NoError(t, err)
|
2020-04-13 11:37:29 -07:00
|
|
|
assert.Empty(t, groups)
|
2024-01-08 13:28:51 +01:00
|
|
|
|
|
|
|
|
t.Run("should get the groups ok when belonging to the team", func(t *testing.T) {
|
|
|
|
|
groups, resp, err := th.Client.GetGroupsAssociatedToChannelsByTeam(context.Background(), th.BasicTeam.Id, opts)
|
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
CheckOKStatus(t, resp)
|
|
|
|
|
require.NotEmpty(t, groups)
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
t.Run("should return forbidden when the user doesn't have the right permissions", func(t *testing.T) {
|
|
|
|
|
require.Nil(t, th.App.RemoveUserFromTeam(th.Context, th.BasicTeam.Id, th.BasicUser.Id, th.SystemAdminUser.Id))
|
|
|
|
|
defer th.App.AddUserToTeam(th.Context, th.BasicTeam.Id, th.BasicUser.Id, th.SystemAdminUser.Id)
|
|
|
|
|
|
|
|
|
|
groups, resp, err := th.Client.GetGroupsAssociatedToChannelsByTeam(context.Background(), th.BasicTeam.Id, opts)
|
|
|
|
|
require.Error(t, err)
|
|
|
|
|
CheckForbiddenStatus(t, resp)
|
|
|
|
|
require.Empty(t, groups)
|
|
|
|
|
})
|
2020-04-13 11:37:29 -07:00
|
|
|
}
|
|
|
|
|
|
2019-04-02 21:02:51 +01:00
|
|
|
func TestGetGroupsByTeam(t *testing.T) {
|
2020-02-10 19:31:41 +01:00
|
|
|
th := Setup(t).InitBasic()
|
2019-04-02 21:02:51 +01:00
|
|
|
defer th.TearDown()
|
|
|
|
|
|
|
|
|
|
id := model.NewId()
|
|
|
|
|
group, err := th.App.CreateGroup(&model.Group{
|
|
|
|
|
DisplayName: "dn_" + id,
|
2020-05-26 19:21:29 -06:00
|
|
|
Name: model.NewString("name" + id),
|
2019-04-02 21:02:51 +01:00
|
|
|
Source: model.GroupSourceLdap,
|
|
|
|
|
Description: "description_" + id,
|
2022-02-17 12:34:39 -05:00
|
|
|
RemoteId: model.NewString(model.NewId()),
|
2019-04-02 21:02:51 +01:00
|
|
|
})
|
|
|
|
|
assert.Nil(t, err)
|
|
|
|
|
|
2020-01-10 12:19:39 -05:00
|
|
|
groupSyncable, err := th.App.UpsertGroupSyncable(&model.GroupSyncable{
|
2019-04-02 21:02:51 +01:00
|
|
|
AutoAdd: true,
|
|
|
|
|
SyncableId: th.BasicTeam.Id,
|
|
|
|
|
Type: model.GroupSyncableTypeTeam,
|
|
|
|
|
GroupId: group.Id,
|
|
|
|
|
})
|
|
|
|
|
assert.Nil(t, err)
|
|
|
|
|
|
2019-05-10 11:47:21 -04:00
|
|
|
opts := model.GroupSearchOpts{
|
|
|
|
|
PageOpts: &model.PageOpts{
|
|
|
|
|
Page: 0,
|
|
|
|
|
PerPage: 60,
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
|
2022-02-17 12:34:39 -05:00
|
|
|
th.App.Srv().SetLicense(model.NewTestLicenseSKU(model.LicenseShortSkuProfessional))
|
|
|
|
|
|
2020-06-01 15:31:05 +05:30
|
|
|
th.TestForSystemAdminAndLocal(t, func(t *testing.T, client *model.Client4) {
|
2023-06-06 23:29:29 +02:00
|
|
|
_, _, response, err := client.GetGroupsByTeam(context.Background(), "asdfasdf", opts)
|
2021-08-13 13:12:16 +02:00
|
|
|
require.Error(t, err)
|
2020-06-01 15:31:05 +05:30
|
|
|
CheckBadRequestStatus(t, response)
|
|
|
|
|
})
|
2019-04-02 21:02:51 +01:00
|
|
|
|
2022-02-17 12:34:39 -05:00
|
|
|
th.App.Srv().RemoveLicense()
|
2019-04-02 21:02:51 +01:00
|
|
|
|
2020-06-01 15:31:05 +05:30
|
|
|
th.TestForSystemAdminAndLocal(t, func(t *testing.T, client *model.Client4) {
|
2023-06-06 23:29:29 +02:00
|
|
|
_, _, response, err := client.GetGroupsByTeam(context.Background(), th.BasicTeam.Id, opts)
|
2021-08-13 13:12:16 +02:00
|
|
|
require.Error(t, err)
|
2022-08-08 20:02:49 +05:30
|
|
|
if client == th.SystemAdminClient {
|
|
|
|
|
CheckNotImplementedStatus(t, response)
|
|
|
|
|
} else {
|
|
|
|
|
CheckForbiddenStatus(t, response)
|
|
|
|
|
}
|
2020-06-01 15:31:05 +05:30
|
|
|
})
|
2019-04-02 21:02:51 +01:00
|
|
|
|
2020-06-12 13:43:50 +02:00
|
|
|
th.App.Srv().SetLicense(model.NewTestLicense("ldap"))
|
2019-04-02 21:02:51 +01:00
|
|
|
|
2020-06-01 15:31:05 +05:30
|
|
|
th.TestForSystemAdminAndLocal(t, func(t *testing.T, client *model.Client4) {
|
2023-06-06 23:29:29 +02:00
|
|
|
groups, _, _, err := client.GetGroupsByTeam(context.Background(), th.BasicTeam.Id, opts)
|
2021-08-13 13:12:16 +02:00
|
|
|
assert.NoError(t, err)
|
2020-06-01 15:31:05 +05:30
|
|
|
assert.ElementsMatch(t, []*model.GroupWithSchemeAdmin{{Group: *group, SchemeAdmin: model.NewBool(false)}}, groups)
|
|
|
|
|
require.NotNil(t, groups[0].SchemeAdmin)
|
|
|
|
|
require.False(t, *groups[0].SchemeAdmin)
|
|
|
|
|
})
|
2020-01-10 12:19:39 -05:00
|
|
|
|
|
|
|
|
// set syncable to true
|
|
|
|
|
groupSyncable.SchemeAdmin = true
|
|
|
|
|
_, err = th.App.UpdateGroupSyncable(groupSyncable)
|
|
|
|
|
require.Nil(t, err)
|
|
|
|
|
|
2020-06-01 15:31:05 +05:30
|
|
|
th.TestForSystemAdminAndLocal(t, func(t *testing.T, client *model.Client4) {
|
2023-06-06 23:29:29 +02:00
|
|
|
groups, _, _, err := client.GetGroupsByTeam(context.Background(), th.BasicTeam.Id, opts)
|
2021-08-13 13:12:16 +02:00
|
|
|
assert.NoError(t, err)
|
2020-06-01 15:31:05 +05:30
|
|
|
// ensure that SchemeAdmin field is updated
|
|
|
|
|
assert.ElementsMatch(t, []*model.GroupWithSchemeAdmin{{Group: *group, SchemeAdmin: model.NewBool(true)}}, groups)
|
|
|
|
|
require.NotNil(t, groups[0].SchemeAdmin)
|
|
|
|
|
require.True(t, *groups[0].SchemeAdmin)
|
|
|
|
|
|
2023-06-06 23:29:29 +02:00
|
|
|
groups, _, _, err = client.GetGroupsByTeam(context.Background(), model.NewId(), opts)
|
2021-08-13 13:12:16 +02:00
|
|
|
assert.NoError(t, err)
|
2020-06-01 15:31:05 +05:30
|
|
|
assert.Empty(t, groups)
|
|
|
|
|
})
|
2024-01-08 13:28:51 +01:00
|
|
|
|
|
|
|
|
t.Run("groups should be fetched only by users with the right permissions", func(t *testing.T) {
|
|
|
|
|
th.TestForSystemAdminAndLocal(t, func(t *testing.T, client *model.Client4) {
|
|
|
|
|
groups, _, _, err := client.GetGroupsByTeam(context.Background(), th.BasicTeam.Id, opts)
|
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
require.Len(t, groups, 1)
|
|
|
|
|
require.ElementsMatch(t, []*model.GroupWithSchemeAdmin{{Group: *group, SchemeAdmin: model.NewBool(true)}}, groups)
|
|
|
|
|
require.NotNil(t, groups[0].SchemeAdmin)
|
|
|
|
|
require.True(t, *groups[0].SchemeAdmin)
|
|
|
|
|
}, "groups can be fetched by system admins even if they're not part of a team")
|
|
|
|
|
|
|
|
|
|
t.Run("user can fetch groups if it's part of the team", func(t *testing.T) {
|
|
|
|
|
groups, _, _, err := th.Client.GetGroupsByTeam(context.Background(), th.BasicTeam.Id, opts)
|
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
require.Len(t, groups, 1)
|
|
|
|
|
require.ElementsMatch(t, []*model.GroupWithSchemeAdmin{{Group: *group, SchemeAdmin: model.NewBool(true)}}, groups)
|
|
|
|
|
require.NotNil(t, groups[0].SchemeAdmin)
|
|
|
|
|
require.True(t, *groups[0].SchemeAdmin)
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
t.Run("user can't fetch groups if it's not part of the team", func(t *testing.T) {
|
|
|
|
|
require.Nil(t, th.App.RemoveUserFromTeam(th.Context, th.BasicTeam.Id, th.BasicUser.Id, th.SystemAdminUser.Id))
|
|
|
|
|
defer th.App.AddUserToTeam(th.Context, th.BasicTeam.Id, th.BasicUser.Id, th.SystemAdminUser.Id)
|
|
|
|
|
|
|
|
|
|
groups, _, response, err := th.Client.GetGroupsByTeam(context.Background(), th.BasicTeam.Id, opts)
|
|
|
|
|
require.Error(t, err)
|
|
|
|
|
CheckForbiddenStatus(t, response)
|
|
|
|
|
require.Empty(t, groups)
|
|
|
|
|
})
|
|
|
|
|
})
|
2019-04-02 21:02:51 +01:00
|
|
|
}
|
2019-05-10 11:47:21 -04:00
|
|
|
|
|
|
|
|
func TestGetGroups(t *testing.T) {
|
2020-02-10 19:31:41 +01:00
|
|
|
th := Setup(t).InitBasic()
|
2019-05-10 11:47:21 -04:00
|
|
|
defer th.TearDown()
|
|
|
|
|
|
2020-05-07 14:35:09 -06:00
|
|
|
// make sure "createdDate" for next group is after one created in InitBasic()
|
|
|
|
|
time.Sleep(2 * time.Millisecond)
|
2019-05-10 11:47:21 -04:00
|
|
|
id := model.NewId()
|
2021-08-13 13:12:16 +02:00
|
|
|
group, appErr := th.App.CreateGroup(&model.Group{
|
2019-05-10 11:47:21 -04:00
|
|
|
DisplayName: "dn-foo_" + id,
|
2020-05-26 19:21:29 -06:00
|
|
|
Name: model.NewString("name" + id),
|
2019-05-10 11:47:21 -04:00
|
|
|
Source: model.GroupSourceLdap,
|
|
|
|
|
Description: "description_" + id,
|
2022-02-17 12:34:39 -05:00
|
|
|
RemoteId: model.NewString(model.NewId()),
|
2019-05-10 11:47:21 -04:00
|
|
|
})
|
2021-08-13 13:12:16 +02:00
|
|
|
assert.Nil(t, appErr)
|
2020-05-07 14:35:09 -06:00
|
|
|
start := group.UpdateAt - 1
|
2019-05-10 11:47:21 -04:00
|
|
|
|
2022-02-17 12:34:39 -05:00
|
|
|
id2 := model.NewId()
|
|
|
|
|
group2, appErr := th.App.CreateGroup(&model.Group{
|
|
|
|
|
DisplayName: "dn-foo_" + id2,
|
|
|
|
|
Name: model.NewString("name" + id2),
|
|
|
|
|
Source: model.GroupSourceCustom,
|
|
|
|
|
Description: "description_" + id2,
|
|
|
|
|
RemoteId: model.NewString(model.NewId()),
|
|
|
|
|
})
|
|
|
|
|
assert.Nil(t, appErr)
|
|
|
|
|
|
2019-05-10 11:47:21 -04:00
|
|
|
opts := model.GroupSearchOpts{
|
2022-02-17 12:34:39 -05:00
|
|
|
Source: model.GroupSourceLdap,
|
2019-05-10 11:47:21 -04:00
|
|
|
PageOpts: &model.PageOpts{
|
|
|
|
|
Page: 0,
|
|
|
|
|
PerPage: 60,
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
|
2022-02-17 12:34:39 -05:00
|
|
|
th.App.Srv().SetLicense(model.NewTestLicenseSKU(model.LicenseShortSkuProfessional))
|
2019-05-10 11:47:21 -04:00
|
|
|
|
2023-06-06 23:29:29 +02:00
|
|
|
_, _, err := th.SystemAdminClient.GetGroups(context.Background(), opts)
|
2021-08-13 13:12:16 +02:00
|
|
|
require.NoError(t, err)
|
2019-11-14 09:21:23 -05:00
|
|
|
|
2023-06-06 23:29:29 +02:00
|
|
|
_, err = th.SystemAdminClient.UpdateChannelRoles(context.Background(), th.BasicChannel.Id, th.BasicUser.Id, "")
|
2021-08-13 13:12:16 +02:00
|
|
|
require.NoError(t, err)
|
2019-11-14 09:21:23 -05:00
|
|
|
|
|
|
|
|
opts.NotAssociatedToChannel = th.BasicChannel.Id
|
|
|
|
|
|
2023-06-06 23:29:29 +02:00
|
|
|
_, err = th.SystemAdminClient.UpdateChannelRoles(context.Background(), th.BasicChannel.Id, th.BasicUser.Id, "channel_user channel_admin")
|
2021-08-13 13:12:16 +02:00
|
|
|
require.NoError(t, err)
|
2019-11-14 09:21:23 -05:00
|
|
|
|
2023-06-06 23:29:29 +02:00
|
|
|
groups, _, err := th.SystemAdminClient.GetGroups(context.Background(), opts)
|
2021-08-13 13:12:16 +02:00
|
|
|
assert.NoError(t, err)
|
2019-05-10 11:47:21 -04:00
|
|
|
assert.ElementsMatch(t, []*model.Group{group, th.Group}, groups)
|
|
|
|
|
assert.Nil(t, groups[0].MemberCount)
|
|
|
|
|
|
|
|
|
|
opts.IncludeMemberCount = true
|
2023-06-06 23:29:29 +02:00
|
|
|
groups, _, _ = th.SystemAdminClient.GetGroups(context.Background(), opts)
|
2019-05-10 11:47:21 -04:00
|
|
|
assert.NotNil(t, groups[0].MemberCount)
|
|
|
|
|
opts.IncludeMemberCount = false
|
|
|
|
|
|
|
|
|
|
opts.Q = "-fOo"
|
2023-06-06 23:29:29 +02:00
|
|
|
groups, _, _ = th.SystemAdminClient.GetGroups(context.Background(), opts)
|
2019-05-10 11:47:21 -04:00
|
|
|
assert.Len(t, groups, 1)
|
|
|
|
|
opts.Q = ""
|
|
|
|
|
|
2023-06-06 23:29:29 +02:00
|
|
|
_, err = th.SystemAdminClient.UpdateTeamMemberRoles(context.Background(), th.BasicTeam.Id, th.BasicUser.Id, "")
|
2021-08-13 13:12:16 +02:00
|
|
|
require.NoError(t, err)
|
2019-05-10 11:47:21 -04:00
|
|
|
|
|
|
|
|
opts.NotAssociatedToTeam = th.BasicTeam.Id
|
|
|
|
|
|
2023-06-06 23:29:29 +02:00
|
|
|
_, err = th.SystemAdminClient.UpdateTeamMemberRoles(context.Background(), th.BasicTeam.Id, th.BasicUser.Id, "team_user team_admin")
|
2021-08-13 13:12:16 +02:00
|
|
|
require.NoError(t, err)
|
2019-05-10 11:47:21 -04:00
|
|
|
|
2023-06-06 23:29:29 +02:00
|
|
|
_, _, err = th.Client.GetGroups(context.Background(), opts)
|
2021-08-13 13:12:16 +02:00
|
|
|
assert.NoError(t, err)
|
2020-05-07 14:35:09 -06:00
|
|
|
|
|
|
|
|
// test "since", should only return group created in this test, not th.Group
|
|
|
|
|
opts.Since = start
|
2023-06-06 23:29:29 +02:00
|
|
|
groups, _, err = th.Client.GetGroups(context.Background(), opts)
|
2021-08-13 13:12:16 +02:00
|
|
|
assert.NoError(t, err)
|
2020-05-07 14:35:09 -06:00
|
|
|
assert.Len(t, groups, 1)
|
|
|
|
|
// test correct group returned
|
|
|
|
|
assert.Equal(t, groups[0].Id, group.Id)
|
|
|
|
|
|
|
|
|
|
// delete group, should still return
|
|
|
|
|
th.App.DeleteGroup(group.Id)
|
2023-06-06 23:29:29 +02:00
|
|
|
groups, _, err = th.Client.GetGroups(context.Background(), opts)
|
2021-08-13 13:12:16 +02:00
|
|
|
assert.NoError(t, err)
|
2020-05-07 14:35:09 -06:00
|
|
|
assert.Len(t, groups, 1)
|
|
|
|
|
assert.Equal(t, groups[0].Id, group.Id)
|
|
|
|
|
|
|
|
|
|
// test with current since value, return none
|
|
|
|
|
opts.Since = model.GetMillis()
|
2023-06-06 23:29:29 +02:00
|
|
|
groups, _, err = th.Client.GetGroups(context.Background(), opts)
|
2021-08-13 13:12:16 +02:00
|
|
|
assert.NoError(t, err)
|
2020-05-07 14:35:09 -06:00
|
|
|
assert.Empty(t, groups)
|
|
|
|
|
|
|
|
|
|
// make sure delete group is not returned without Since
|
|
|
|
|
opts.Since = 0
|
2023-06-06 23:29:29 +02:00
|
|
|
groups, _, err = th.Client.GetGroups(context.Background(), opts)
|
2021-08-13 13:12:16 +02:00
|
|
|
assert.NoError(t, err)
|
2020-05-07 14:35:09 -06:00
|
|
|
//'Normal getGroups should not return delete groups
|
|
|
|
|
assert.Len(t, groups, 1)
|
|
|
|
|
// make sure it returned th.Group,not group
|
|
|
|
|
assert.Equal(t, groups[0].Id, th.Group.Id)
|
2022-02-17 12:34:39 -05:00
|
|
|
|
2023-08-31 10:07:51 -04:00
|
|
|
// Test include_archived parameter
|
|
|
|
|
opts.IncludeArchived = true
|
|
|
|
|
groups, _, err = th.Client.GetGroups(context.Background(), opts)
|
|
|
|
|
assert.NoError(t, err)
|
|
|
|
|
assert.Len(t, groups, 2)
|
|
|
|
|
opts.IncludeArchived = false
|
|
|
|
|
|
|
|
|
|
// Test returning only archived groups
|
|
|
|
|
opts.FilterArchived = true
|
|
|
|
|
groups, _, err = th.Client.GetGroups(context.Background(), opts)
|
|
|
|
|
assert.NoError(t, err)
|
|
|
|
|
assert.Len(t, groups, 1)
|
|
|
|
|
assert.Equal(t, groups[0].Id, group.Id)
|
|
|
|
|
opts.FilterArchived = false
|
|
|
|
|
|
2022-02-17 12:34:39 -05:00
|
|
|
opts.Source = model.GroupSourceCustom
|
2023-06-06 23:29:29 +02:00
|
|
|
groups, _, err = th.Client.GetGroups(context.Background(), opts)
|
2022-02-17 12:34:39 -05:00
|
|
|
assert.NoError(t, err)
|
|
|
|
|
assert.Len(t, groups, 1)
|
|
|
|
|
assert.Equal(t, groups[0].Id, group2.Id)
|
2022-03-03 15:50:17 -05:00
|
|
|
|
2022-11-22 11:31:04 -05:00
|
|
|
// Test IncludeChannelMemberCount url param is working
|
|
|
|
|
opts.IncludeChannelMemberCount = th.BasicChannel.Id
|
|
|
|
|
opts.IncludeTimezones = true
|
|
|
|
|
opts.Q = "-fOo"
|
|
|
|
|
opts.IncludeMemberCount = true
|
|
|
|
|
|
2023-06-06 23:29:29 +02:00
|
|
|
groups, _, _ = th.SystemAdminClient.GetGroups(context.Background(), opts)
|
2022-11-22 11:31:04 -05:00
|
|
|
assert.Equal(t, *groups[0].MemberCount, int(0))
|
|
|
|
|
assert.Equal(t, *groups[0].ChannelMemberCount, int(0))
|
|
|
|
|
|
|
|
|
|
_, appErr = th.App.UpsertGroupMember(group2.Id, th.BasicUser.Id)
|
|
|
|
|
assert.Nil(t, appErr)
|
|
|
|
|
|
2023-06-06 23:29:29 +02:00
|
|
|
groups, _, _ = th.SystemAdminClient.GetGroups(context.Background(), opts)
|
2022-11-22 11:31:04 -05:00
|
|
|
assert.NotNil(t, groups[0].MemberCount)
|
|
|
|
|
assert.Equal(t, *groups[0].ChannelMemberCount, int(1))
|
|
|
|
|
|
|
|
|
|
opts.IncludeChannelMemberCount = ""
|
|
|
|
|
opts.IncludeTimezones = false
|
|
|
|
|
opts.Q = ""
|
|
|
|
|
opts.IncludeMemberCount = false
|
|
|
|
|
|
2022-03-03 15:50:17 -05:00
|
|
|
th.App.UpdateConfig(func(cfg *model.Config) {
|
|
|
|
|
*cfg.ServiceSettings.EnableCustomGroups = false
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
// Specify custom groups source when feature is disabled
|
|
|
|
|
opts.Source = model.GroupSourceCustom
|
2023-06-06 23:29:29 +02:00
|
|
|
_, response, err := th.Client.GetGroups(context.Background(), opts)
|
2022-03-03 15:50:17 -05:00
|
|
|
require.Error(t, err)
|
2022-08-08 20:02:49 +05:30
|
|
|
CheckBadRequestStatus(t, response)
|
2022-03-03 15:50:17 -05:00
|
|
|
|
|
|
|
|
// Specify ldap groups source when custom groups feature is disabled
|
|
|
|
|
opts.Source = model.GroupSourceLdap
|
2023-06-06 23:29:29 +02:00
|
|
|
groups, _, err = th.Client.GetGroups(context.Background(), opts)
|
2022-03-03 15:50:17 -05:00
|
|
|
assert.NoError(t, err)
|
|
|
|
|
assert.Len(t, groups, 1)
|
|
|
|
|
assert.Equal(t, groups[0].Source, model.GroupSourceLdap)
|
|
|
|
|
|
|
|
|
|
// don't include source and should only get ldap groups in response
|
|
|
|
|
opts.Source = ""
|
2023-06-06 23:29:29 +02:00
|
|
|
groups, _, err = th.Client.GetGroups(context.Background(), opts)
|
2022-03-03 15:50:17 -05:00
|
|
|
assert.NoError(t, err)
|
|
|
|
|
assert.Len(t, groups, 1)
|
|
|
|
|
assert.Equal(t, groups[0].Source, model.GroupSourceLdap)
|
2019-05-10 11:47:21 -04:00
|
|
|
}
|
2020-05-07 13:35:56 -06:00
|
|
|
|
2021-03-23 10:32:54 +01:00
|
|
|
func TestGetGroupsByUserId(t *testing.T) {
|
2020-05-07 13:35:56 -06:00
|
|
|
th := Setup(t).InitBasic()
|
|
|
|
|
defer th.TearDown()
|
|
|
|
|
|
|
|
|
|
id := model.NewId()
|
2021-08-13 13:12:16 +02:00
|
|
|
group1, appErr := th.App.CreateGroup(&model.Group{
|
2020-05-07 13:35:56 -06:00
|
|
|
DisplayName: "dn-foo_" + id,
|
2020-05-26 19:21:29 -06:00
|
|
|
Name: model.NewString("name" + id),
|
2020-05-07 13:35:56 -06:00
|
|
|
Source: model.GroupSourceLdap,
|
|
|
|
|
Description: "description_" + id,
|
2022-02-17 12:34:39 -05:00
|
|
|
RemoteId: model.NewString(model.NewId()),
|
2020-05-07 13:35:56 -06:00
|
|
|
})
|
2021-08-13 13:12:16 +02:00
|
|
|
assert.Nil(t, appErr)
|
2020-05-07 13:35:56 -06:00
|
|
|
|
2021-08-13 13:12:16 +02:00
|
|
|
user1, appErr := th.App.CreateUser(th.Context, &model.User{Email: th.GenerateTestEmail(), Nickname: "test user1", Password: "test-password-1", Username: "test-user-1", Roles: model.SystemUserRoleId})
|
|
|
|
|
assert.Nil(t, appErr)
|
2020-05-07 13:35:56 -06:00
|
|
|
user1.Password = "test-password-1"
|
2021-08-13 13:12:16 +02:00
|
|
|
_, appErr = th.App.UpsertGroupMember(group1.Id, user1.Id)
|
|
|
|
|
assert.Nil(t, appErr)
|
2020-05-07 13:35:56 -06:00
|
|
|
|
|
|
|
|
id = model.NewId()
|
2021-08-13 13:12:16 +02:00
|
|
|
group2, appErr := th.App.CreateGroup(&model.Group{
|
2020-05-07 13:35:56 -06:00
|
|
|
DisplayName: "dn-foo_" + id,
|
2020-05-26 19:21:29 -06:00
|
|
|
Name: model.NewString("name" + id),
|
2020-05-07 13:35:56 -06:00
|
|
|
Source: model.GroupSourceLdap,
|
|
|
|
|
Description: "description_" + id,
|
2022-02-17 12:34:39 -05:00
|
|
|
RemoteId: model.NewString(model.NewId()),
|
2020-05-07 13:35:56 -06:00
|
|
|
})
|
2021-08-13 13:12:16 +02:00
|
|
|
assert.Nil(t, appErr)
|
2020-05-07 13:35:56 -06:00
|
|
|
|
2021-08-13 13:12:16 +02:00
|
|
|
_, appErr = th.App.UpsertGroupMember(group2.Id, user1.Id)
|
|
|
|
|
assert.Nil(t, appErr)
|
2020-05-07 13:35:56 -06:00
|
|
|
|
2020-06-12 13:43:50 +02:00
|
|
|
th.App.Srv().SetLicense(nil)
|
2023-06-06 23:29:29 +02:00
|
|
|
_, response, err := th.SystemAdminClient.GetGroupsByUserId(context.Background(), user1.Id)
|
2021-08-13 13:12:16 +02:00
|
|
|
require.Error(t, err)
|
2020-05-07 13:35:56 -06:00
|
|
|
CheckNotImplementedStatus(t, response)
|
|
|
|
|
|
2020-06-12 13:43:50 +02:00
|
|
|
th.App.Srv().SetLicense(model.NewTestLicense("ldap"))
|
2023-06-06 23:29:29 +02:00
|
|
|
_, response, err = th.SystemAdminClient.GetGroupsByUserId(context.Background(), "")
|
2021-08-13 13:12:16 +02:00
|
|
|
require.Error(t, err)
|
2020-05-07 13:35:56 -06:00
|
|
|
CheckBadRequestStatus(t, response)
|
|
|
|
|
|
2023-06-06 23:29:29 +02:00
|
|
|
_, response, err = th.SystemAdminClient.GetGroupsByUserId(context.Background(), "notvaliduserid")
|
2021-08-13 13:12:16 +02:00
|
|
|
require.Error(t, err)
|
2020-05-07 13:35:56 -06:00
|
|
|
CheckBadRequestStatus(t, response)
|
|
|
|
|
|
2023-06-06 23:29:29 +02:00
|
|
|
groups, _, err := th.SystemAdminClient.GetGroupsByUserId(context.Background(), user1.Id)
|
2021-08-13 13:12:16 +02:00
|
|
|
require.NoError(t, err)
|
2020-05-07 13:35:56 -06:00
|
|
|
assert.ElementsMatch(t, []*model.Group{group1, group2}, groups)
|
|
|
|
|
|
|
|
|
|
// test permissions
|
2023-06-06 23:29:29 +02:00
|
|
|
th.Client.Logout(context.Background())
|
|
|
|
|
th.Client.Login(context.Background(), th.BasicUser.Email, th.BasicUser.Password)
|
|
|
|
|
_, response, err = th.Client.GetGroupsByUserId(context.Background(), user1.Id)
|
2021-08-13 13:12:16 +02:00
|
|
|
require.Error(t, err)
|
2020-05-07 13:35:56 -06:00
|
|
|
CheckForbiddenStatus(t, response)
|
|
|
|
|
|
2023-06-06 23:29:29 +02:00
|
|
|
th.Client.Logout(context.Background())
|
|
|
|
|
th.Client.Login(context.Background(), user1.Email, user1.Password)
|
|
|
|
|
groups, _, err = th.Client.GetGroupsByUserId(context.Background(), user1.Id)
|
2021-08-13 13:12:16 +02:00
|
|
|
require.NoError(t, err)
|
2020-05-07 13:35:56 -06:00
|
|
|
assert.ElementsMatch(t, []*model.Group{group1, group2}, groups)
|
|
|
|
|
}
|
2020-05-29 10:46:52 -04:00
|
|
|
|
2020-06-18 10:22:35 -04:00
|
|
|
func TestGetGroupStats(t *testing.T) {
|
|
|
|
|
th := Setup(t).InitBasic()
|
|
|
|
|
defer th.TearDown()
|
|
|
|
|
|
|
|
|
|
id := model.NewId()
|
2021-08-13 13:12:16 +02:00
|
|
|
group, appErr := th.App.CreateGroup(&model.Group{
|
2020-06-18 10:22:35 -04:00
|
|
|
DisplayName: "dn-foo_" + id,
|
|
|
|
|
Name: model.NewString("name" + id),
|
|
|
|
|
Source: model.GroupSourceLdap,
|
|
|
|
|
Description: "description_" + id,
|
2022-02-17 12:34:39 -05:00
|
|
|
RemoteId: model.NewString(model.NewId()),
|
2020-06-18 10:22:35 -04:00
|
|
|
})
|
2021-08-13 13:12:16 +02:00
|
|
|
assert.Nil(t, appErr)
|
2020-06-18 10:22:35 -04:00
|
|
|
|
|
|
|
|
t.Run("Requires ldap license", func(t *testing.T) {
|
2023-06-06 23:29:29 +02:00
|
|
|
_, response, err := th.SystemAdminClient.GetGroupStats(context.Background(), group.Id)
|
2021-08-13 13:12:16 +02:00
|
|
|
require.Error(t, err)
|
2020-06-18 10:22:35 -04:00
|
|
|
CheckNotImplementedStatus(t, response)
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
th.App.Srv().SetLicense(model.NewTestLicense("ldap"))
|
|
|
|
|
|
|
|
|
|
t.Run("Requires manage system permission to access group stats", func(t *testing.T) {
|
2023-06-06 23:29:29 +02:00
|
|
|
th.Client.Login(context.Background(), th.BasicUser.Email, th.BasicUser.Password)
|
|
|
|
|
_, response, err := th.Client.GetGroupStats(context.Background(), group.Id)
|
2021-08-13 13:12:16 +02:00
|
|
|
require.Error(t, err)
|
2020-06-18 10:22:35 -04:00
|
|
|
CheckForbiddenStatus(t, response)
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
t.Run("Returns stats for a group with no members", func(t *testing.T) {
|
2023-06-06 23:29:29 +02:00
|
|
|
stats, _, err := th.SystemAdminClient.GetGroupStats(context.Background(), group.Id)
|
2022-02-17 12:34:39 -05:00
|
|
|
require.NoError(t, err)
|
2020-06-18 10:22:35 -04:00
|
|
|
assert.Equal(t, stats.GroupID, group.Id)
|
|
|
|
|
assert.Equal(t, stats.TotalMemberCount, int64(0))
|
|
|
|
|
})
|
|
|
|
|
|
2021-07-12 20:05:36 +02:00
|
|
|
user1, err := th.App.CreateUser(th.Context, &model.User{Email: th.GenerateTestEmail(), Nickname: "test user1", Password: "test-password-1", Username: "test-user-1", Roles: model.SystemUserRoleId})
|
2020-06-18 10:22:35 -04:00
|
|
|
assert.Nil(t, err)
|
2021-08-13 13:12:16 +02:00
|
|
|
_, appErr = th.App.UpsertGroupMember(group.Id, user1.Id)
|
|
|
|
|
assert.Nil(t, appErr)
|
2020-06-18 10:22:35 -04:00
|
|
|
|
|
|
|
|
t.Run("Returns stats for a group with members", func(t *testing.T) {
|
2023-06-06 23:29:29 +02:00
|
|
|
stats, _, _ := th.SystemAdminClient.GetGroupStats(context.Background(), group.Id)
|
2020-06-18 10:22:35 -04:00
|
|
|
assert.Equal(t, stats.GroupID, group.Id)
|
|
|
|
|
assert.Equal(t, stats.TotalMemberCount, int64(1))
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-29 10:46:52 -04:00
|
|
|
func TestGetGroupsGroupConstrainedParentTeam(t *testing.T) {
|
2020-07-22 13:50:33 +05:30
|
|
|
th := Setup(t)
|
2020-05-29 10:46:52 -04:00
|
|
|
defer th.TearDown()
|
|
|
|
|
|
2020-06-12 13:43:50 +02:00
|
|
|
th.App.Srv().SetLicense(model.NewTestLicense("ldap"))
|
2020-05-29 10:46:52 -04:00
|
|
|
|
|
|
|
|
var groups []*model.Group
|
|
|
|
|
for i := 0; i < 4; i++ {
|
|
|
|
|
id := model.NewId()
|
|
|
|
|
group, err := th.App.CreateGroup(&model.Group{
|
|
|
|
|
DisplayName: fmt.Sprintf("dn-foo_%d", i),
|
|
|
|
|
Name: model.NewString("name" + id),
|
|
|
|
|
Source: model.GroupSourceLdap,
|
|
|
|
|
Description: "description_" + id,
|
2022-02-17 12:34:39 -05:00
|
|
|
RemoteId: model.NewString(model.NewId()),
|
2020-05-29 10:46:52 -04:00
|
|
|
})
|
|
|
|
|
require.Nil(t, err)
|
|
|
|
|
groups = append(groups, group)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
team := th.CreateTeam()
|
|
|
|
|
|
|
|
|
|
id := model.NewId()
|
|
|
|
|
channel := &model.Channel{
|
|
|
|
|
DisplayName: "dn_" + id,
|
|
|
|
|
Name: "name" + id,
|
2021-07-12 20:05:36 +02:00
|
|
|
Type: model.ChannelTypePrivate,
|
2020-05-29 10:46:52 -04:00
|
|
|
TeamId: team.Id,
|
|
|
|
|
GroupConstrained: model.NewBool(true),
|
|
|
|
|
}
|
2021-08-13 13:12:16 +02:00
|
|
|
channel, appErr := th.App.CreateChannel(th.Context, channel, false)
|
|
|
|
|
require.Nil(t, appErr)
|
2020-05-29 10:46:52 -04:00
|
|
|
|
|
|
|
|
// normal result of groups are returned if the team is not group-constrained
|
2023-06-06 23:29:29 +02:00
|
|
|
apiGroups, _, err := th.SystemAdminClient.GetGroups(context.Background(), model.GroupSearchOpts{NotAssociatedToChannel: channel.Id})
|
2021-08-13 13:12:16 +02:00
|
|
|
require.NoError(t, err)
|
2020-05-29 10:46:52 -04:00
|
|
|
require.Contains(t, apiGroups, groups[0])
|
|
|
|
|
require.Contains(t, apiGroups, groups[1])
|
|
|
|
|
require.Contains(t, apiGroups, groups[2])
|
|
|
|
|
|
|
|
|
|
team.GroupConstrained = model.NewBool(true)
|
2021-08-13 13:12:16 +02:00
|
|
|
team, appErr = th.App.UpdateTeam(team)
|
|
|
|
|
require.Nil(t, appErr)
|
2020-05-29 10:46:52 -04:00
|
|
|
|
|
|
|
|
// team is group-constrained but has no associated groups
|
2023-06-06 23:29:29 +02:00
|
|
|
apiGroups, _, err = th.SystemAdminClient.GetGroups(context.Background(), model.GroupSearchOpts{NotAssociatedToChannel: channel.Id, FilterParentTeamPermitted: true})
|
2021-08-13 13:12:16 +02:00
|
|
|
require.NoError(t, err)
|
2020-05-29 10:46:52 -04:00
|
|
|
require.Len(t, apiGroups, 0)
|
|
|
|
|
|
|
|
|
|
for _, group := range []*model.Group{groups[0], groups[2], groups[3]} {
|
2021-08-13 13:12:16 +02:00
|
|
|
_, appErr = th.App.UpsertGroupSyncable(model.NewGroupTeam(group.Id, team.Id, false))
|
|
|
|
|
require.Nil(t, appErr)
|
2020-05-29 10:46:52 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// set of the teams groups are returned
|
2023-06-06 23:29:29 +02:00
|
|
|
apiGroups, _, err = th.SystemAdminClient.GetGroups(context.Background(), model.GroupSearchOpts{NotAssociatedToChannel: channel.Id, FilterParentTeamPermitted: true})
|
2021-08-13 13:12:16 +02:00
|
|
|
require.NoError(t, err)
|
2020-05-29 10:46:52 -04:00
|
|
|
require.Contains(t, apiGroups, groups[0])
|
|
|
|
|
require.NotContains(t, apiGroups, groups[1])
|
|
|
|
|
require.Contains(t, apiGroups, groups[2])
|
|
|
|
|
|
|
|
|
|
// paged results function as expected
|
2023-06-06 23:29:29 +02:00
|
|
|
apiGroups, _, err = th.SystemAdminClient.GetGroups(context.Background(), model.GroupSearchOpts{NotAssociatedToChannel: channel.Id, FilterParentTeamPermitted: true, PageOpts: &model.PageOpts{PerPage: 2, Page: 0}})
|
2021-08-13 13:12:16 +02:00
|
|
|
require.NoError(t, err)
|
2020-05-29 10:46:52 -04:00
|
|
|
require.Len(t, apiGroups, 2)
|
|
|
|
|
require.Equal(t, apiGroups[0].Id, groups[0].Id)
|
|
|
|
|
require.Equal(t, apiGroups[1].Id, groups[2].Id)
|
|
|
|
|
|
2023-06-06 23:29:29 +02:00
|
|
|
apiGroups, _, err = th.SystemAdminClient.GetGroups(context.Background(), model.GroupSearchOpts{NotAssociatedToChannel: channel.Id, FilterParentTeamPermitted: true, PageOpts: &model.PageOpts{PerPage: 2, Page: 1}})
|
2021-08-13 13:12:16 +02:00
|
|
|
require.NoError(t, err)
|
2020-05-29 10:46:52 -04:00
|
|
|
require.Len(t, apiGroups, 1)
|
|
|
|
|
require.Equal(t, apiGroups[0].Id, groups[3].Id)
|
|
|
|
|
|
2021-08-13 13:12:16 +02:00
|
|
|
_, appErr = th.App.UpsertGroupSyncable(model.NewGroupChannel(groups[0].Id, channel.Id, false))
|
|
|
|
|
require.Nil(t, appErr)
|
2020-05-29 10:46:52 -04:00
|
|
|
|
|
|
|
|
// as usual it doesn't return groups already associated to the channel
|
2023-06-06 23:29:29 +02:00
|
|
|
apiGroups, _, err = th.SystemAdminClient.GetGroups(context.Background(), model.GroupSearchOpts{NotAssociatedToChannel: channel.Id})
|
2021-08-13 13:12:16 +02:00
|
|
|
require.NoError(t, err)
|
2020-05-29 10:46:52 -04:00
|
|
|
require.NotContains(t, apiGroups, groups[0])
|
|
|
|
|
require.Contains(t, apiGroups, groups[2])
|
|
|
|
|
}
|
2022-02-17 12:34:39 -05:00
|
|
|
|
|
|
|
|
func TestAddMembersToGroup(t *testing.T) {
|
|
|
|
|
th := Setup(t)
|
|
|
|
|
defer th.TearDown()
|
|
|
|
|
|
|
|
|
|
// 1. Test with custom source
|
|
|
|
|
id := model.NewId()
|
|
|
|
|
group, err := th.App.CreateGroup(&model.Group{
|
|
|
|
|
DisplayName: "dn_" + id,
|
|
|
|
|
Name: model.NewString("name" + id),
|
|
|
|
|
Source: model.GroupSourceCustom,
|
|
|
|
|
Description: "description_" + id,
|
|
|
|
|
})
|
|
|
|
|
assert.Nil(t, err)
|
|
|
|
|
|
|
|
|
|
user1, appErr := th.App.CreateUser(th.Context, &model.User{Email: th.GenerateTestEmail(), Nickname: "test user1", Password: "test-password-1", Username: "test-user-1", Roles: model.SystemUserRoleId})
|
|
|
|
|
assert.Nil(t, appErr)
|
|
|
|
|
|
|
|
|
|
user2, appErr := th.App.CreateUser(th.Context, &model.User{Email: th.GenerateTestEmail(), Nickname: "test user2", Password: "test-password-2", Username: "test-user-2", Roles: model.SystemUserRoleId})
|
|
|
|
|
assert.Nil(t, appErr)
|
|
|
|
|
|
|
|
|
|
members := &model.GroupModifyMembers{
|
|
|
|
|
UserIds: []string{user1.Id, user2.Id},
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
th.App.Srv().SetLicense(model.NewTestLicenseSKU(model.LicenseShortSkuProfessional))
|
|
|
|
|
|
2023-10-05 14:55:59 +01:00
|
|
|
//Empty group members returns bad request
|
|
|
|
|
_, resp, nullErr := th.SystemAdminClient.UpsertGroupMembers(context.Background(), group.Id, nil)
|
|
|
|
|
require.Error(t, nullErr)
|
|
|
|
|
CheckBadRequestStatus(t, resp)
|
|
|
|
|
|
2023-06-06 23:29:29 +02:00
|
|
|
groupMembers, response, upsertErr := th.SystemAdminClient.UpsertGroupMembers(context.Background(), group.Id, members)
|
2022-02-17 12:34:39 -05:00
|
|
|
require.NoError(t, upsertErr)
|
|
|
|
|
CheckOKStatus(t, response)
|
|
|
|
|
|
|
|
|
|
assert.Len(t, groupMembers, 2)
|
|
|
|
|
|
2022-10-25 11:54:51 -04:00
|
|
|
count, countErr := th.App.GetGroupMemberCount(group.Id, nil)
|
2022-02-17 12:34:39 -05:00
|
|
|
assert.Nil(t, countErr)
|
|
|
|
|
|
|
|
|
|
assert.Equal(t, count, int64(2))
|
|
|
|
|
|
|
|
|
|
// 2. Test invalid group ID
|
2023-06-06 23:29:29 +02:00
|
|
|
_, response, upsertErr = th.Client.UpsertGroupMembers(context.Background(), "abc123", members)
|
2022-02-17 12:34:39 -05:00
|
|
|
require.Error(t, upsertErr)
|
|
|
|
|
CheckBadRequestStatus(t, response)
|
|
|
|
|
|
|
|
|
|
// 3. Test invalid user ID
|
|
|
|
|
invalidMembers := &model.GroupModifyMembers{
|
|
|
|
|
UserIds: []string{"abc123"},
|
|
|
|
|
}
|
|
|
|
|
|
2023-06-06 23:29:29 +02:00
|
|
|
_, response, upsertErr = th.SystemAdminClient.UpsertGroupMembers(context.Background(), group.Id, invalidMembers)
|
2022-02-17 12:34:39 -05:00
|
|
|
require.Error(t, upsertErr)
|
|
|
|
|
CheckInternalErrorStatus(t, response)
|
|
|
|
|
|
|
|
|
|
// 4. Test with ldap source
|
|
|
|
|
ldapId := model.NewId()
|
|
|
|
|
ldapGroup, err := th.App.CreateGroup(&model.Group{
|
|
|
|
|
DisplayName: "dn_" + ldapId,
|
|
|
|
|
Name: model.NewString("name" + ldapId),
|
|
|
|
|
Source: model.GroupSourceLdap,
|
|
|
|
|
Description: "description_" + ldapId,
|
|
|
|
|
RemoteId: model.NewString(model.NewId()),
|
|
|
|
|
})
|
|
|
|
|
assert.Nil(t, err)
|
|
|
|
|
|
2023-06-06 23:29:29 +02:00
|
|
|
_, response, upsertErr = th.SystemAdminClient.UpsertGroupMembers(context.Background(), ldapGroup.Id, members)
|
2022-02-17 12:34:39 -05:00
|
|
|
|
|
|
|
|
require.Error(t, upsertErr)
|
2022-08-08 20:02:49 +05:30
|
|
|
CheckBadRequestStatus(t, response)
|
2022-02-17 12:34:39 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestDeleteMembersFromGroup(t *testing.T) {
|
|
|
|
|
th := Setup(t)
|
|
|
|
|
defer th.TearDown()
|
|
|
|
|
|
|
|
|
|
// 1. Test with custom source
|
|
|
|
|
user1, appErr := th.App.CreateUser(th.Context, &model.User{Email: th.GenerateTestEmail(), Nickname: "test user1", Password: "test-password-1", Username: "test-user-1", Roles: model.SystemUserRoleId})
|
|
|
|
|
assert.Nil(t, appErr)
|
|
|
|
|
|
|
|
|
|
user2, appErr := th.App.CreateUser(th.Context, &model.User{Email: th.GenerateTestEmail(), Nickname: "test user2", Password: "test-password-2", Username: "test-user-2", Roles: model.SystemUserRoleId})
|
|
|
|
|
assert.Nil(t, appErr)
|
|
|
|
|
|
|
|
|
|
id := model.NewId()
|
|
|
|
|
g := &model.Group{
|
|
|
|
|
DisplayName: "dn_" + id,
|
|
|
|
|
Name: model.NewString("name" + id),
|
|
|
|
|
Source: model.GroupSourceCustom,
|
|
|
|
|
Description: "description_" + id,
|
|
|
|
|
}
|
|
|
|
|
group, err := th.App.CreateGroupWithUserIds(&model.GroupWithUserIds{
|
|
|
|
|
Group: *g,
|
|
|
|
|
UserIds: []string{user1.Id, user2.Id},
|
|
|
|
|
})
|
|
|
|
|
assert.Nil(t, err)
|
|
|
|
|
|
|
|
|
|
members := &model.GroupModifyMembers{
|
|
|
|
|
UserIds: []string{user1.Id},
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
th.App.Srv().SetLicense(model.NewTestLicenseSKU(model.LicenseShortSkuProfessional))
|
|
|
|
|
|
2023-10-05 14:55:59 +01:00
|
|
|
_, resp, nullErr := th.SystemAdminClient.DeleteGroupMembers(context.Background(), group.Id, nil)
|
|
|
|
|
require.Error(t, nullErr)
|
|
|
|
|
CheckBadRequestStatus(t, resp)
|
|
|
|
|
|
2023-06-06 23:29:29 +02:00
|
|
|
groupMembers, response, deleteErr := th.SystemAdminClient.DeleteGroupMembers(context.Background(), group.Id, members)
|
2022-02-17 12:34:39 -05:00
|
|
|
require.NoError(t, deleteErr)
|
|
|
|
|
CheckOKStatus(t, response)
|
|
|
|
|
|
|
|
|
|
assert.Len(t, groupMembers, 1)
|
|
|
|
|
assert.Equal(t, groupMembers[0].UserId, user1.Id)
|
|
|
|
|
|
|
|
|
|
users, usersErr := th.App.GetGroupMemberUsers(group.Id)
|
|
|
|
|
assert.Nil(t, usersErr)
|
|
|
|
|
|
|
|
|
|
assert.Len(t, users, 1)
|
|
|
|
|
assert.Equal(t, users[0].Id, user2.Id)
|
|
|
|
|
|
|
|
|
|
// 2. Test invalid group ID
|
2023-06-06 23:29:29 +02:00
|
|
|
_, response, deleteErr = th.Client.DeleteGroupMembers(context.Background(), "abc123", members)
|
2022-02-17 12:34:39 -05:00
|
|
|
require.Error(t, deleteErr)
|
|
|
|
|
CheckBadRequestStatus(t, response)
|
|
|
|
|
|
|
|
|
|
// 3. Test invalid user ID
|
|
|
|
|
invalidMembers := &model.GroupModifyMembers{
|
|
|
|
|
UserIds: []string{"abc123"},
|
|
|
|
|
}
|
|
|
|
|
|
2023-06-06 23:29:29 +02:00
|
|
|
_, response, deleteErr = th.SystemAdminClient.DeleteGroupMembers(context.Background(), group.Id, invalidMembers)
|
2022-02-17 12:34:39 -05:00
|
|
|
require.Error(t, deleteErr)
|
|
|
|
|
CheckInternalErrorStatus(t, response)
|
|
|
|
|
|
|
|
|
|
// 4. Test with ldap source
|
|
|
|
|
ldapId := model.NewId()
|
|
|
|
|
g1 := &model.Group{
|
|
|
|
|
DisplayName: "dn_" + ldapId,
|
|
|
|
|
Name: model.NewString("name" + ldapId),
|
|
|
|
|
Source: model.GroupSourceLdap,
|
|
|
|
|
Description: "description_" + ldapId,
|
|
|
|
|
RemoteId: model.NewString(model.NewId()),
|
|
|
|
|
}
|
|
|
|
|
ldapGroup, err := th.App.CreateGroupWithUserIds(&model.GroupWithUserIds{
|
|
|
|
|
Group: *g1,
|
|
|
|
|
UserIds: []string{user1.Id, user2.Id},
|
|
|
|
|
})
|
|
|
|
|
assert.Nil(t, err)
|
|
|
|
|
|
2023-06-06 23:29:29 +02:00
|
|
|
_, response, deleteErr = th.SystemAdminClient.DeleteGroupMembers(context.Background(), ldapGroup.Id, members)
|
2022-02-17 12:34:39 -05:00
|
|
|
|
|
|
|
|
require.Error(t, deleteErr)
|
2022-08-08 20:02:49 +05:30
|
|
|
CheckBadRequestStatus(t, response)
|
2022-02-17 12:34:39 -05:00
|
|
|
}
|