summaryrefslogtreecommitdiffstats
path: root/api4/role_test.go
diff options
context:
space:
mode:
authorGeorge Goldberg <george@gberg.me>2018-02-08 16:07:40 +0000
committerJesús Espino <jespinog@gmail.com>2018-02-08 17:07:40 +0100
commitfa5cba9cc79b3bdc48ad42f276652bc699795a39 (patch)
tree39549319db989cd3429d82ab41766e1b73c7dcb3 /api4/role_test.go
parenta735725d116c3e8dca2b4d1cad3425bcd473311c (diff)
downloadchat-fa5cba9cc79b3bdc48ad42f276652bc699795a39.tar.gz
chat-fa5cba9cc79b3bdc48ad42f276652bc699795a39.tar.bz2
chat-fa5cba9cc79b3bdc48ad42f276652bc699795a39.zip
XYZ-76: Add license check to patchRoles endpoint. (#8224)
Diffstat (limited to 'api4/role_test.go')
-rw-r--r--api4/role_test.go37
1 files changed, 34 insertions, 3 deletions
diff --git a/api4/role_test.go b/api4/role_test.go
index 64b8303e2..a3e6d35be 100644
--- a/api4/role_test.go
+++ b/api4/role_test.go
@@ -10,6 +10,7 @@ import (
"github.com/stretchr/testify/assert"
"github.com/mattermost/mattermost-server/model"
+ "github.com/mattermost/mattermost-server/utils"
)
func TestGetRole(t *testing.T) {
@@ -146,7 +147,7 @@ func TestPatchRole(t *testing.T) {
Name: model.NewId(),
DisplayName: model.NewId(),
Description: model.NewId(),
- Permissions: []string{"manage_system", "create_public_channel"},
+ Permissions: []string{"manage_system", "create_public_channel", "manage_slash_commands"},
SchemeManaged: true,
}
@@ -156,7 +157,7 @@ func TestPatchRole(t *testing.T) {
defer th.App.Srv.Store.Job().Delete(role.Id)
patch := &model.RolePatch{
- Permissions: &[]string{"manage_system", "delete_public_channel"},
+ Permissions: &[]string{"manage_system", "create_public_channel", "manage_webhooks"},
}
received, resp := th.SystemAdminClient.PatchRole(role.Id, patch)
@@ -166,7 +167,7 @@ func TestPatchRole(t *testing.T) {
assert.Equal(t, received.Name, role.Name)
assert.Equal(t, received.DisplayName, role.DisplayName)
assert.Equal(t, received.Description, role.Description)
- assert.EqualValues(t, received.Permissions, []string{"manage_system", "delete_public_channel"})
+ assert.EqualValues(t, received.Permissions, []string{"manage_system", "create_public_channel", "manage_webhooks"})
assert.Equal(t, received.SchemeManaged, role.SchemeManaged)
// Check a no-op patch succeeds.
@@ -181,4 +182,34 @@ func TestPatchRole(t *testing.T) {
received, resp = th.Client.PatchRole(role.Id, patch)
CheckForbiddenStatus(t, resp)
+
+ // Check a change that the license would not allow.
+ patch = &model.RolePatch{
+ Permissions: &[]string{"manage_system", "manage_webhooks"},
+ }
+
+ received, resp = th.SystemAdminClient.PatchRole(role.Id, patch)
+ CheckNotImplementedStatus(t, resp)
+
+ // Add a license.
+ isLicensed := utils.IsLicensed()
+ license := utils.License()
+ defer func() {
+ utils.SetIsLicensed(isLicensed)
+ utils.SetLicense(license)
+ }()
+ utils.SetIsLicensed(true)
+ utils.SetLicense(&model.License{Features: &model.Features{}})
+ utils.License().Features.SetDefaults()
+
+ // Try again, should succeed
+ received, resp = th.SystemAdminClient.PatchRole(role.Id, patch)
+ CheckNoError(t, resp)
+
+ assert.Equal(t, received.Id, role.Id)
+ assert.Equal(t, received.Name, role.Name)
+ assert.Equal(t, received.DisplayName, role.DisplayName)
+ assert.Equal(t, received.Description, role.Description)
+ assert.EqualValues(t, received.Permissions, []string{"manage_system", "manage_webhooks"})
+ assert.Equal(t, received.SchemeManaged, role.SchemeManaged)
}