github.com/gigforks/mattermost-server@v4.9.1-0.20180619094218-800d97fa55d0+incompatible/app/authorization_test.go (about) 1 // Copyright (c) 2016-present Mattermost, Inc. All Rights Reserved. 2 // See License.txt for license information. 3 4 package app 5 6 import ( 7 "testing" 8 9 "github.com/mattermost/mattermost-server/model" 10 ) 11 12 func TestCheckIfRolesGrantPermission(t *testing.T) { 13 th := Setup().InitBasic() 14 defer th.TearDown() 15 16 cases := []struct { 17 roles []string 18 permissionId string 19 shouldGrant bool 20 }{ 21 {[]string{model.SYSTEM_ADMIN_ROLE_ID}, model.PERMISSION_MANAGE_SYSTEM.Id, true}, 22 {[]string{model.SYSTEM_ADMIN_ROLE_ID}, "non-existent-permission", false}, 23 {[]string{model.CHANNEL_USER_ROLE_ID}, model.PERMISSION_READ_CHANNEL.Id, true}, 24 {[]string{model.CHANNEL_USER_ROLE_ID}, model.PERMISSION_MANAGE_SYSTEM.Id, false}, 25 {[]string{model.SYSTEM_ADMIN_ROLE_ID, model.CHANNEL_USER_ROLE_ID}, model.PERMISSION_MANAGE_SYSTEM.Id, true}, 26 {[]string{model.CHANNEL_USER_ROLE_ID, model.SYSTEM_ADMIN_ROLE_ID}, model.PERMISSION_MANAGE_SYSTEM.Id, true}, 27 {[]string{model.TEAM_USER_ROLE_ID, model.TEAM_ADMIN_ROLE_ID}, model.PERMISSION_MANAGE_SLASH_COMMANDS.Id, true}, 28 {[]string{model.TEAM_ADMIN_ROLE_ID, model.TEAM_USER_ROLE_ID}, model.PERMISSION_MANAGE_SLASH_COMMANDS.Id, true}, 29 } 30 31 for testnum, testcase := range cases { 32 if th.App.RolesGrantPermission(testcase.roles, testcase.permissionId) != testcase.shouldGrant { 33 t.Fatal("Failed test case ", testnum) 34 } 35 } 36 37 }