diff options
Diffstat (limited to 'api4')
-rw-r--r-- | api4/api.go | 6 | ||||
-rw-r--r-- | api4/apitestlib.go | 2 | ||||
-rw-r--r-- | api4/channel.go | 9 | ||||
-rw-r--r-- | api4/channel_test.go | 150 | ||||
-rw-r--r-- | api4/command_test.go | 3 | ||||
-rw-r--r-- | api4/context.go | 4 | ||||
-rw-r--r-- | api4/job_test.go | 2 | ||||
-rw-r--r-- | api4/openGraph_test.go | 3 | ||||
-rw-r--r-- | api4/post_test.go | 31 | ||||
-rw-r--r-- | api4/system.go | 2 | ||||
-rw-r--r-- | api4/team_test.go | 56 | ||||
-rw-r--r-- | api4/user.go | 3 | ||||
-rw-r--r-- | api4/user_test.go | 30 | ||||
-rw-r--r-- | api4/webhook_test.go | 40 |
14 files changed, 190 insertions, 151 deletions
diff --git a/api4/api.go b/api4/api.go index be957d63b..6e9534d40 100644 --- a/api4/api.go +++ b/api4/api.go @@ -55,9 +55,8 @@ type Routes struct { PublicFile *mux.Router // 'files/{file_id:[A-Za-z0-9]+}/public' - Commands *mux.Router // 'api/v4/commands' - Command *mux.Router // 'api/v4/commands/{command_id:[A-Za-z0-9]+}' - CommandsForTeam *mux.Router // 'api/v4/teams/{team_id:[A-Za-z0-9]+}/commands' + Commands *mux.Router // 'api/v4/commands' + Command *mux.Router // 'api/v4/commands/{command_id:[A-Za-z0-9]+}' Hooks *mux.Router // 'api/v4/hooks' IncomingHooks *mux.Router // 'api/v4/hooks/incoming' @@ -149,7 +148,6 @@ func InitApi(full bool) { BaseRoutes.Commands = BaseRoutes.ApiRoot.PathPrefix("/commands").Subrouter() BaseRoutes.Command = BaseRoutes.Commands.PathPrefix("/{command_id:[A-Za-z0-9]+}").Subrouter() - BaseRoutes.CommandsForTeam = BaseRoutes.Team.PathPrefix("/commands").Subrouter() BaseRoutes.Hooks = BaseRoutes.ApiRoot.PathPrefix("/hooks").Subrouter() BaseRoutes.IncomingHooks = BaseRoutes.Hooks.PathPrefix("/incoming").Subrouter() diff --git a/api4/apitestlib.go b/api4/apitestlib.go index 7f69b3690..b10e639e3 100644 --- a/api4/apitestlib.go +++ b/api4/apitestlib.go @@ -55,7 +55,7 @@ func SetupEnterprise() *TestHelper { utils.Cfg.EmailSettings.SMTPPort = "2500" utils.Cfg.EmailSettings.FeedbackEmail = "test@example.com" utils.DisableDebugLogForTest() - utils.License.Features.SetDefaults() + utils.License().Features.SetDefaults() app.NewServer() app.InitStores() InitRouter() diff --git a/api4/channel.go b/api4/channel.go index 604c47464..281fb6ac4 100644 --- a/api4/channel.go +++ b/api4/channel.go @@ -534,19 +534,12 @@ func deleteChannel(c *Context, w http.ResponseWriter, r *http.Request) { return } - var memberCount int64 - if memberCount, err = app.GetChannelMemberCount(c.Params.ChannelId); err != nil { - c.Err = err - return - } - if channel.Type == model.CHANNEL_OPEN && !app.SessionHasPermissionToChannel(c.Session, channel.Id, model.PERMISSION_DELETE_PUBLIC_CHANNEL) { c.SetPermissionError(model.PERMISSION_DELETE_PUBLIC_CHANNEL) return } - // Allow delete if there's only one member left in a private channel - if memberCount > 1 && channel.Type == model.CHANNEL_PRIVATE && !app.SessionHasPermissionToChannel(c.Session, channel.Id, model.PERMISSION_DELETE_PRIVATE_CHANNEL) { + if channel.Type == model.CHANNEL_PRIVATE && !app.SessionHasPermissionToChannel(c.Session, channel.Id, model.PERMISSION_DELETE_PRIVATE_CHANNEL) { c.SetPermissionError(model.PERMISSION_DELETE_PRIVATE_CHANNEL) return } diff --git a/api4/channel_test.go b/api4/channel_test.go index a1c5d2ad8..1747d79b9 100644 --- a/api4/channel_test.go +++ b/api4/channel_test.go @@ -82,22 +82,22 @@ func TestCreateChannel(t *testing.T) { th.LoginBasic() // Check permissions with policy config changes - isLicensed := utils.IsLicensed - license := utils.License + isLicensed := utils.IsLicensed() + license := utils.License() restrictPublicChannel := *utils.Cfg.TeamSettings.RestrictPublicChannelCreation restrictPrivateChannel := *utils.Cfg.TeamSettings.RestrictPrivateChannelCreation defer func() { *utils.Cfg.TeamSettings.RestrictPublicChannelCreation = restrictPublicChannel *utils.Cfg.TeamSettings.RestrictPrivateChannelCreation = restrictPrivateChannel - utils.IsLicensed = isLicensed - utils.License = license + utils.SetIsLicensed(isLicensed) + utils.SetLicense(license) utils.SetDefaultRolesBasedOnConfig() }() *utils.Cfg.TeamSettings.RestrictPublicChannelCreation = model.PERMISSIONS_ALL *utils.Cfg.TeamSettings.RestrictPrivateChannelCreation = model.PERMISSIONS_ALL - utils.IsLicensed = true - utils.License = &model.License{Features: &model.Features{}} - utils.License.Features.SetDefaults() + utils.SetIsLicensed(true) + utils.SetLicense(&model.License{Features: &model.Features{}}) + utils.License().Features.SetDefaults() utils.SetDefaultRolesBasedOnConfig() channel.Name = GenerateTestChannelName() @@ -165,8 +165,8 @@ func TestCreateChannel(t *testing.T) { CheckNoError(t, resp) // Check that if unlicensed the policy restriction is not enforced. - utils.IsLicensed = false - utils.License = nil + utils.SetIsLicensed(false) + utils.SetLicense(nil) utils.SetDefaultRolesBasedOnConfig() channel.Name = GenerateTestChannelName() @@ -879,22 +879,22 @@ func TestDeleteChannel(t *testing.T) { _, resp = th.SystemAdminClient.DeleteChannel(publicChannel5.Id) CheckNoError(t, resp) - isLicensed := utils.IsLicensed - license := utils.License + isLicensed := utils.IsLicensed() + license := utils.License() restrictPublicChannel := *utils.Cfg.TeamSettings.RestrictPublicChannelManagement restrictPrivateChannel := *utils.Cfg.TeamSettings.RestrictPrivateChannelManagement defer func() { *utils.Cfg.TeamSettings.RestrictPublicChannelManagement = restrictPublicChannel *utils.Cfg.TeamSettings.RestrictPrivateChannelManagement = restrictPrivateChannel - utils.IsLicensed = isLicensed - utils.License = license + utils.SetIsLicensed(isLicensed) + utils.SetLicense(license) utils.SetDefaultRolesBasedOnConfig() }() *utils.Cfg.TeamSettings.RestrictPublicChannelManagement = model.PERMISSIONS_ALL *utils.Cfg.TeamSettings.RestrictPrivateChannelManagement = model.PERMISSIONS_ALL - utils.IsLicensed = true - utils.License = &model.License{Features: &model.Features{}} - utils.License.Features.SetDefaults() + utils.SetIsLicensed(true) + utils.SetLicense(&model.License{Features: &model.Features{}}) + utils.License().Features.SetDefaults() utils.SetDefaultRolesBasedOnConfig() th = Setup().InitBasic().InitSystemAdmin() @@ -956,9 +956,9 @@ func TestDeleteChannel(t *testing.T) { // successful delete by team admin UpdateUserToTeamAdmin(user, team) app.InvalidateAllCaches() - utils.IsLicensed = true - utils.License = &model.License{Features: &model.Features{}} - utils.License.Features.SetDefaults() + utils.SetIsLicensed(true) + utils.SetLicense(&model.License{Features: &model.Features{}}) + utils.License().Features.SetDefaults() _, resp = Client.DeleteChannel(publicChannel6.Id) CheckNoError(t, resp) @@ -971,9 +971,9 @@ func TestDeleteChannel(t *testing.T) { utils.SetDefaultRolesBasedOnConfig() UpdateUserToNonTeamAdmin(user, team) app.InvalidateAllCaches() - utils.IsLicensed = true - utils.License = &model.License{Features: &model.Features{}} - utils.License.Features.SetDefaults() + utils.SetIsLicensed(true) + utils.SetLicense(&model.License{Features: &model.Features{}}) + utils.License().Features.SetDefaults() // channels created by SystemAdmin publicChannel6 = th.CreateChannelWithClient(th.SystemAdminClient, model.CHANNEL_OPEN) @@ -1003,9 +1003,9 @@ func TestDeleteChannel(t *testing.T) { // successful delete by team admin UpdateUserToTeamAdmin(th.BasicUser, team) app.InvalidateAllCaches() - utils.IsLicensed = true - utils.License = &model.License{Features: &model.Features{}} - utils.License.Features.SetDefaults() + utils.SetIsLicensed(true) + utils.SetLicense(&model.License{Features: &model.Features{}}) + utils.License().Features.SetDefaults() _, resp = Client.DeleteChannel(publicChannel6.Id) CheckNoError(t, resp) @@ -1045,9 +1045,9 @@ func TestDeleteChannel(t *testing.T) { // cannot delete by team admin UpdateUserToTeamAdmin(th.BasicUser, team) app.InvalidateAllCaches() - utils.IsLicensed = true - utils.License = &model.License{Features: &model.Features{}} - utils.License.Features.SetDefaults() + utils.SetIsLicensed(true) + utils.SetLicense(&model.License{Features: &model.Features{}}) + utils.License().Features.SetDefaults() _, resp = Client.DeleteChannel(publicChannel6.Id) CheckForbiddenStatus(t, resp) @@ -1064,15 +1064,13 @@ func TestDeleteChannel(t *testing.T) { // last member of a public channel should have required permission to delete publicChannel6 = th.CreateChannelWithClient(th.Client, model.CHANNEL_OPEN) - _, resp = Client.DeleteChannel(publicChannel6.Id) CheckForbiddenStatus(t, resp) - // last member of a private channel should be able to delete it regardless of required permissions + // last member of a private channel should not be able to delete it if they don't have required permissions privateChannel7 = th.CreateChannelWithClient(th.Client, model.CHANNEL_PRIVATE) - _, resp = Client.DeleteChannel(privateChannel7.Id) - CheckNoError(t, resp) + CheckForbiddenStatus(t, resp) } func TestRestoreChannel(t *testing.T) { @@ -1798,17 +1796,17 @@ func TestAddChannelMember(t *testing.T) { Client.Logout() // Add a license - isLicensed := utils.IsLicensed - license := utils.License + isLicensed := utils.IsLicensed() + license := utils.License() defer func() { - utils.IsLicensed = isLicensed - utils.License = license + utils.SetIsLicensed(isLicensed) + utils.SetLicense(license) utils.SetDefaultRolesBasedOnConfig() }() *utils.Cfg.TeamSettings.RestrictPrivateChannelManageMembers = model.PERMISSIONS_ALL - utils.IsLicensed = true - utils.License = &model.License{Features: &model.Features{}} - utils.License.Features.SetDefaults() + utils.SetIsLicensed(true) + utils.SetLicense(&model.License{Features: &model.Features{}}) + utils.License().Features.SetDefaults() utils.SetDefaultRolesBasedOnConfig() // Check that a regular channel user can add other users. @@ -1825,9 +1823,9 @@ func TestAddChannelMember(t *testing.T) { // Test with CHANNEL_ADMIN level permission. *utils.Cfg.TeamSettings.RestrictPrivateChannelManageMembers = model.PERMISSIONS_CHANNEL_ADMIN - utils.IsLicensed = true - utils.License = &model.License{Features: &model.Features{}} - utils.License.Features.SetDefaults() + utils.SetIsLicensed(true) + utils.SetLicense(&model.License{Features: &model.Features{}}) + utils.License().Features.SetDefaults() utils.SetDefaultRolesBasedOnConfig() Client.Login(user2.Username, user2.Password) @@ -1843,9 +1841,9 @@ func TestAddChannelMember(t *testing.T) { MakeUserChannelAdmin(user, privateChannel) app.InvalidateAllCaches() - utils.IsLicensed = true - utils.License = &model.License{Features: &model.Features{}} - utils.License.Features.SetDefaults() + utils.SetIsLicensed(true) + utils.SetLicense(&model.License{Features: &model.Features{}}) + utils.License().Features.SetDefaults() utils.SetDefaultRolesBasedOnConfig() Client.Login(user.Username, user.Password) @@ -1855,9 +1853,9 @@ func TestAddChannelMember(t *testing.T) { // Test with TEAM_ADMIN level permission. *utils.Cfg.TeamSettings.RestrictPrivateChannelManageMembers = model.PERMISSIONS_TEAM_ADMIN - utils.IsLicensed = true - utils.License = &model.License{Features: &model.Features{}} - utils.License.Features.SetDefaults() + utils.SetIsLicensed(true) + utils.SetLicense(&model.License{Features: &model.Features{}}) + utils.License().Features.SetDefaults() utils.SetDefaultRolesBasedOnConfig() Client.Login(user2.Username, user2.Password) @@ -1873,9 +1871,9 @@ func TestAddChannelMember(t *testing.T) { UpdateUserToTeamAdmin(user, team) app.InvalidateAllCaches() - utils.IsLicensed = true - utils.License = &model.License{Features: &model.Features{}} - utils.License.Features.SetDefaults() + utils.SetIsLicensed(true) + utils.SetLicense(&model.License{Features: &model.Features{}}) + utils.License().Features.SetDefaults() utils.SetDefaultRolesBasedOnConfig() Client.Login(user.Username, user.Password) @@ -1885,9 +1883,9 @@ func TestAddChannelMember(t *testing.T) { // Test with SYSTEM_ADMIN level permission. *utils.Cfg.TeamSettings.RestrictPrivateChannelManageMembers = model.PERMISSIONS_SYSTEM_ADMIN - utils.IsLicensed = true - utils.License = &model.License{Features: &model.Features{}} - utils.License.Features.SetDefaults() + utils.SetIsLicensed(true) + utils.SetLicense(&model.License{Features: &model.Features{}}) + utils.License().Features.SetDefaults() utils.SetDefaultRolesBasedOnConfig() Client.Login(user2.Username, user2.Password) @@ -1982,17 +1980,17 @@ func TestRemoveChannelMember(t *testing.T) { CheckNoError(t, resp) // Add a license - isLicensed := utils.IsLicensed - license := utils.License + isLicensed := utils.IsLicensed() + license := utils.License() defer func() { - utils.IsLicensed = isLicensed - utils.License = license + utils.SetIsLicensed(isLicensed) + utils.SetLicense(license) utils.SetDefaultRolesBasedOnConfig() }() *utils.Cfg.TeamSettings.RestrictPrivateChannelManageMembers = model.PERMISSIONS_ALL - utils.IsLicensed = true - utils.License = &model.License{Features: &model.Features{}} - utils.License.Features.SetDefaults() + utils.SetIsLicensed(true) + utils.SetLicense(&model.License{Features: &model.Features{}}) + utils.License().Features.SetDefaults() utils.SetDefaultRolesBasedOnConfig() // Check that a regular channel user can remove other users. @@ -2007,9 +2005,9 @@ func TestRemoveChannelMember(t *testing.T) { // Test with CHANNEL_ADMIN level permission. *utils.Cfg.TeamSettings.RestrictPrivateChannelManageMembers = model.PERMISSIONS_CHANNEL_ADMIN - utils.IsLicensed = true - utils.License = &model.License{Features: &model.Features{}} - utils.License.Features.SetDefaults() + utils.SetIsLicensed(true) + utils.SetLicense(&model.License{Features: &model.Features{}}) + utils.License().Features.SetDefaults() utils.SetDefaultRolesBasedOnConfig() privateChannel = th.CreateChannelWithClient(th.SystemAdminClient, model.CHANNEL_PRIVATE) @@ -2023,18 +2021,18 @@ func TestRemoveChannelMember(t *testing.T) { MakeUserChannelAdmin(user1, privateChannel) app.InvalidateAllCaches() - utils.IsLicensed = true - utils.License = &model.License{Features: &model.Features{}} - utils.License.Features.SetDefaults() + utils.SetIsLicensed(true) + utils.SetLicense(&model.License{Features: &model.Features{}}) + utils.License().Features.SetDefaults() _, resp = Client.RemoveUserFromChannel(privateChannel.Id, user2.Id) CheckNoError(t, resp) // Test with TEAM_ADMIN level permission. *utils.Cfg.TeamSettings.RestrictPrivateChannelManageMembers = model.PERMISSIONS_TEAM_ADMIN - utils.IsLicensed = true - utils.License = &model.License{Features: &model.Features{}} - utils.License.Features.SetDefaults() + utils.SetIsLicensed(true) + utils.SetLicense(&model.License{Features: &model.Features{}}) + utils.License().Features.SetDefaults() utils.SetDefaultRolesBasedOnConfig() privateChannel = th.CreateChannelWithClient(th.SystemAdminClient, model.CHANNEL_PRIVATE) @@ -2048,18 +2046,18 @@ func TestRemoveChannelMember(t *testing.T) { UpdateUserToTeamAdmin(user1, team) app.InvalidateAllCaches() - utils.IsLicensed = true - utils.License = &model.License{Features: &model.Features{}} - utils.License.Features.SetDefaults() + utils.SetIsLicensed(true) + utils.SetLicense(&model.License{Features: &model.Features{}}) + utils.License().Features.SetDefaults() _, resp = Client.RemoveUserFromChannel(privateChannel.Id, user2.Id) CheckNoError(t, resp) // Test with SYSTEM_ADMIN level permission. *utils.Cfg.TeamSettings.RestrictPrivateChannelManageMembers = model.PERMISSIONS_SYSTEM_ADMIN - utils.IsLicensed = true - utils.License = &model.License{Features: &model.Features{}} - utils.License.Features.SetDefaults() + utils.SetIsLicensed(true) + utils.SetLicense(&model.License{Features: &model.Features{}}) + utils.License().Features.SetDefaults() utils.SetDefaultRolesBasedOnConfig() privateChannel = th.CreateChannelWithClient(th.SystemAdminClient, model.CHANNEL_PRIVATE) diff --git a/api4/command_test.go b/api4/command_test.go index 467d45955..b0d5f4baa 100644 --- a/api4/command_test.go +++ b/api4/command_test.go @@ -388,10 +388,13 @@ func TestExecuteCommand(t *testing.T) { channel := th.BasicChannel enableCommands := *utils.Cfg.ServiceSettings.EnableCommands + allowedInternalConnections := *utils.Cfg.ServiceSettings.AllowedUntrustedInternalConnections defer func() { utils.Cfg.ServiceSettings.EnableCommands = &enableCommands + utils.Cfg.ServiceSettings.AllowedUntrustedInternalConnections = &allowedInternalConnections }() *utils.Cfg.ServiceSettings.EnableCommands = true + *utils.Cfg.ServiceSettings.AllowedUntrustedInternalConnections = "localhost" postCmd := &model.Command{ CreatorId: th.BasicUser.Id, diff --git a/api4/context.go b/api4/context.go index d72b3593d..69351a098 100644 --- a/api4/context.go +++ b/api4/context.go @@ -129,7 +129,7 @@ func (h handler) ServeHTTP(w http.ResponseWriter, r *http.Request) { c.SetSiteURLHeader(app.GetProtocol(r) + "://" + r.Host) w.Header().Set(model.HEADER_REQUEST_ID, c.RequestId) - w.Header().Set(model.HEADER_VERSION_ID, fmt.Sprintf("%v.%v.%v.%v", model.CurrentVersion, model.BuildNumber, utils.ClientCfgHash, utils.IsLicensed)) + w.Header().Set(model.HEADER_VERSION_ID, fmt.Sprintf("%v.%v.%v.%v", model.CurrentVersion, model.BuildNumber, utils.ClientCfgHash, utils.IsLicensed())) w.Header().Set("Content-Type", "application/json") @@ -252,7 +252,7 @@ func (c *Context) SessionRequired() { func (c *Context) MfaRequired() { // Must be licensed for MFA and have it configured for enforcement - if !utils.IsLicensed || !*utils.License.Features.MFA || !*utils.Cfg.ServiceSettings.EnableMultifactorAuthentication || !*utils.Cfg.ServiceSettings.EnforceMultifactorAuthentication { + if !utils.IsLicensed() || !*utils.License().Features.MFA || !*utils.Cfg.ServiceSettings.EnableMultifactorAuthentication || !*utils.Cfg.ServiceSettings.EnforceMultifactorAuthentication { return } diff --git a/api4/job_test.go b/api4/job_test.go index 3dcdbe58b..511386810 100644 --- a/api4/job_test.go +++ b/api4/job_test.go @@ -18,7 +18,7 @@ func TestCreateJob(t *testing.T) { job := &model.Job{ Type: model.JOB_TYPE_DATA_RETENTION, - Data: map[string]interface{}{ + Data: map[string]string{ "thing": "stuff", }, } diff --git a/api4/openGraph_test.go b/api4/openGraph_test.go index 958abf604..df1af66fc 100644 --- a/api4/openGraph_test.go +++ b/api4/openGraph_test.go @@ -19,10 +19,13 @@ func TestGetOpenGraphMetadata(t *testing.T) { Client := th.Client enableLinkPreviews := *utils.Cfg.ServiceSettings.EnableLinkPreviews + allowedInternalConnections := *utils.Cfg.ServiceSettings.AllowedUntrustedInternalConnections defer func() { *utils.Cfg.ServiceSettings.EnableLinkPreviews = enableLinkPreviews + utils.Cfg.ServiceSettings.AllowedUntrustedInternalConnections = &allowedInternalConnections }() *utils.Cfg.ServiceSettings.EnableLinkPreviews = true + *utils.Cfg.ServiceSettings.AllowedUntrustedInternalConnections = "localhost 127.0.0.1" ogDataCacheMissCount := 0 diff --git a/api4/post_test.go b/api4/post_test.go index f136ba676..c09cb77d1 100644 --- a/api4/post_test.go +++ b/api4/post_test.go @@ -119,14 +119,17 @@ func testCreatePostWithOutgoingHook( enableOutgoingHooks := utils.Cfg.ServiceSettings.EnableOutgoingWebhooks enableAdminOnlyHooks := utils.Cfg.ServiceSettings.EnableOnlyAdminIntegrations + allowedInternalConnections := *utils.Cfg.ServiceSettings.AllowedUntrustedInternalConnections defer func() { utils.Cfg.ServiceSettings.EnableOutgoingWebhooks = enableOutgoingHooks utils.Cfg.ServiceSettings.EnableOnlyAdminIntegrations = enableAdminOnlyHooks utils.SetDefaultRolesBasedOnConfig() + utils.Cfg.ServiceSettings.AllowedUntrustedInternalConnections = &allowedInternalConnections }() utils.Cfg.ServiceSettings.EnableOutgoingWebhooks = true *utils.Cfg.ServiceSettings.EnableOnlyAdminIntegrations = true utils.SetDefaultRolesBasedOnConfig() + *utils.Cfg.ServiceSettings.AllowedUntrustedInternalConnections = "localhost 127.0.0.1" var hook *model.OutgoingWebhook var post *model.Post @@ -363,18 +366,18 @@ func TestUpdatePost(t *testing.T) { Client := th.Client channel := th.BasicChannel - isLicensed := utils.IsLicensed - license := utils.License + isLicensed := utils.IsLicensed() + license := utils.License() allowEditPost := *utils.Cfg.ServiceSettings.AllowEditPost defer func() { - utils.IsLicensed = isLicensed - utils.License = license + utils.SetIsLicensed(isLicensed) + utils.SetLicense(license) *utils.Cfg.ServiceSettings.AllowEditPost = allowEditPost utils.SetDefaultRolesBasedOnConfig() }() - utils.IsLicensed = true - utils.License = &model.License{Features: &model.Features{}} - utils.License.Features.SetDefaults() + utils.SetIsLicensed(true) + utils.SetLicense(&model.License{Features: &model.Features{}}) + utils.License().Features.SetDefaults() *utils.Cfg.ServiceSettings.AllowEditPost = model.ALLOW_EDIT_POST_ALWAYS utils.SetDefaultRolesBasedOnConfig() @@ -442,18 +445,18 @@ func TestPatchPost(t *testing.T) { Client := th.Client channel := th.BasicChannel - isLicensed := utils.IsLicensed - license := utils.License + isLicensed := utils.IsLicensed() + license := utils.License() allowEditPost := *utils.Cfg.ServiceSettings.AllowEditPost defer func() { - utils.IsLicensed = isLicensed - utils.License = license + utils.SetIsLicensed(isLicensed) + utils.SetLicense(license) *utils.Cfg.ServiceSettings.AllowEditPost = allowEditPost utils.SetDefaultRolesBasedOnConfig() }() - utils.IsLicensed = true - utils.License = &model.License{Features: &model.Features{}} - utils.License.Features.SetDefaults() + utils.SetIsLicensed(true) + utils.SetLicense(&model.License{Features: &model.Features{}}) + utils.License().Features.SetDefaults() *utils.Cfg.ServiceSettings.AllowEditPost = model.ALLOW_EDIT_POST_ALWAYS utils.SetDefaultRolesBasedOnConfig() diff --git a/api4/system.go b/api4/system.go index ff3aab0d0..0c0fc7d12 100644 --- a/api4/system.go +++ b/api4/system.go @@ -258,7 +258,7 @@ func getClientLicense(c *Context, w http.ResponseWriter, r *http.Request) { var clientLicense map[string]string if app.SessionHasPermissionTo(c.Session, model.PERMISSION_MANAGE_SYSTEM) { - clientLicense = utils.ClientLicense + clientLicense = utils.ClientLicense() } else { clientLicense = utils.GetSanitizedClientLicense() } diff --git a/api4/team_test.go b/api4/team_test.go index 72c5dd6e6..21c842f65 100644 --- a/api4/team_test.go +++ b/api4/team_test.go @@ -848,12 +848,12 @@ func TestAddTeamMember(t *testing.T) { // Check effects of config and license changes. restrictTeamInvite := *utils.Cfg.TeamSettings.RestrictTeamInvite - isLicensed := utils.IsLicensed - license := utils.License + isLicensed := utils.IsLicensed() + license := utils.License() defer func() { *utils.Cfg.TeamSettings.RestrictTeamInvite = restrictTeamInvite - utils.IsLicensed = isLicensed - utils.License = license + utils.SetIsLicensed(isLicensed) + utils.SetLicense(license) utils.SetDefaultRolesBasedOnConfig() }() @@ -867,9 +867,9 @@ func TestAddTeamMember(t *testing.T) { CheckNoError(t, resp) // Add an EE license. - utils.IsLicensed = true - utils.License = &model.License{Features: &model.Features{}} - utils.License.Features.SetDefaults() + utils.SetIsLicensed(true) + utils.SetLicense(&model.License{Features: &model.Features{}}) + utils.License().Features.SetDefaults() utils.SetDefaultRolesBasedOnConfig() th.LoginBasic() @@ -881,9 +881,9 @@ func TestAddTeamMember(t *testing.T) { UpdateUserToTeamAdmin(th.BasicUser, th.BasicTeam) app.InvalidateAllCaches() *utils.Cfg.TeamSettings.RestrictTeamInvite = model.PERMISSIONS_TEAM_ADMIN - utils.IsLicensed = true - utils.License = &model.License{Features: &model.Features{}} - utils.License.Features.SetDefaults() + utils.SetIsLicensed(true) + utils.SetLicense(&model.License{Features: &model.Features{}}) + utils.License().Features.SetDefaults() utils.SetDefaultRolesBasedOnConfig() th.LoginBasic() @@ -907,9 +907,9 @@ func TestAddTeamMember(t *testing.T) { UpdateUserToNonTeamAdmin(th.BasicUser, th.BasicTeam) app.InvalidateAllCaches() *utils.Cfg.TeamSettings.RestrictTeamInvite = model.PERMISSIONS_ALL - utils.IsLicensed = true - utils.License = &model.License{Features: &model.Features{}} - utils.License.Features.SetDefaults() + utils.SetIsLicensed(true) + utils.SetLicense(&model.License{Features: &model.Features{}}) + utils.License().Features.SetDefaults() utils.SetDefaultRolesBasedOnConfig() th.LoginBasic() @@ -919,8 +919,8 @@ func TestAddTeamMember(t *testing.T) { // Reset config and license. *utils.Cfg.TeamSettings.RestrictTeamInvite = restrictTeamInvite - utils.IsLicensed = isLicensed - utils.License = license + utils.SetIsLicensed(isLicensed) + utils.SetLicense(license) utils.SetDefaultRolesBasedOnConfig() th.LoginBasic() @@ -1062,12 +1062,12 @@ func TestAddTeamMembers(t *testing.T) { // Check effects of config and license changes. restrictTeamInvite := *utils.Cfg.TeamSettings.RestrictTeamInvite - isLicensed := utils.IsLicensed - license := utils.License + isLicensed := utils.IsLicensed() + license := utils.License() defer func() { *utils.Cfg.TeamSettings.RestrictTeamInvite = restrictTeamInvite - utils.IsLicensed = isLicensed - utils.License = license + utils.SetIsLicensed(isLicensed) + utils.SetLicense(license) utils.SetDefaultRolesBasedOnConfig() }() @@ -1081,9 +1081,9 @@ func TestAddTeamMembers(t *testing.T) { CheckNoError(t, resp) // Add an EE license. - utils.IsLicensed = true - utils.License = &model.License{Features: &model.Features{}} - utils.License.Features.SetDefaults() + utils.SetIsLicensed(true) + utils.SetLicense(&model.License{Features: &model.Features{}}) + utils.License().Features.SetDefaults() utils.SetDefaultRolesBasedOnConfig() th.LoginBasic() @@ -1095,9 +1095,9 @@ func TestAddTeamMembers(t *testing.T) { UpdateUserToTeamAdmin(th.BasicUser, th.BasicTeam) app.InvalidateAllCaches() *utils.Cfg.TeamSettings.RestrictTeamInvite = model.PERMISSIONS_TEAM_ADMIN - utils.IsLicensed = true - utils.License = &model.License{Features: &model.Features{}} - utils.License.Features.SetDefaults() + utils.SetIsLicensed(true) + utils.SetLicense(&model.License{Features: &model.Features{}}) + utils.License().Features.SetDefaults() utils.SetDefaultRolesBasedOnConfig() th.LoginBasic() @@ -1121,9 +1121,9 @@ func TestAddTeamMembers(t *testing.T) { UpdateUserToNonTeamAdmin(th.BasicUser, th.BasicTeam) app.InvalidateAllCaches() *utils.Cfg.TeamSettings.RestrictTeamInvite = model.PERMISSIONS_ALL - utils.IsLicensed = true - utils.License = &model.License{Features: &model.Features{}} - utils.License.Features.SetDefaults() + utils.SetIsLicensed(true) + utils.SetLicense(&model.License{Features: &model.Features{}}) + utils.License().Features.SetDefaults() utils.SetDefaultRolesBasedOnConfig() th.LoginBasic() diff --git a/api4/user.go b/api4/user.go index 16c1f4a74..365248c0f 100644 --- a/api4/user.go +++ b/api4/user.go @@ -675,7 +675,7 @@ func checkUserMfa(c *Context, w http.ResponseWriter, r *http.Request) { resp := map[string]interface{}{} resp["mfa_required"] = false - if !utils.IsLicensed || !*utils.License.Features.MFA || !*utils.Cfg.ServiceSettings.EnableMultifactorAuthentication { + if !utils.IsLicensed() || !*utils.License().Features.MFA || !*utils.Cfg.ServiceSettings.EnableMultifactorAuthentication { w.Write([]byte(model.StringInterfaceToJson(resp))) return } @@ -926,6 +926,7 @@ func revokeSession(c *Context, w http.ResponseWriter, r *http.Request) { if sessionId == "" { c.SetInvalidParam("session_id") + return } if err := app.RevokeSessionById(sessionId); err != nil { diff --git a/api4/user_test.go b/api4/user_test.go index 37ecd660d..894187469 100644 --- a/api4/user_test.go +++ b/api4/user_test.go @@ -1513,17 +1513,17 @@ func TestGetUsersNotInChannel(t *testing.T) { defer TearDown() Client := th.Client - isLicensed := utils.IsLicensed - license := utils.License + isLicensed := utils.IsLicensed() + license := utils.License() enableMfa := *utils.Cfg.ServiceSettings.EnableMultifactorAuthentication defer func() { - utils.IsLicensed = isLicensed - utils.License = license + utils.SetIsLicensed(isLicensed) + utils.SetLicense(license) *utils.Cfg.ServiceSettings.EnableMultifactorAuthentication = enableMfa }() - utils.IsLicensed = true - utils.License = &model.License{Features: &model.Features{}} - utils.License.Features.SetDefaults() + utils.IsLicensed()= true + utils.SetLicense(&model.License{Features: &model.Features{}}) + utils.License().Features.SetDefaults() team := model.Team{DisplayName: "Name", Name: "z-z-" + model.NewId() + "a", Email: "test@nowhere.com", Type: model.TEAM_OPEN} rteam, _ := Client.CreateTeam(&team) @@ -1574,18 +1574,18 @@ func TestCheckUserMfa(t *testing.T) { t.Fatal("should be false - mfa not active") } - isLicensed := utils.IsLicensed - license := utils.License + isLicensed := utils.IsLicensed() + license := utils.License() enableMfa := *utils.Cfg.ServiceSettings.EnableMultifactorAuthentication defer func() { - utils.IsLicensed = isLicensed - utils.License = license + utils.SetIsLicensed(isLicensed) + utils.SetLicense(license) *utils.Cfg.ServiceSettings.EnableMultifactorAuthentication = enableMfa }() - utils.IsLicensed = true - utils.License = &model.License{Features: &model.Features{}} - utils.License.Features.SetDefaults() - *utils.License.Features.MFA = true + utils.SetIsLicensed(true) + utils.SetLicense(&model.License{Features: &model.Features{}}) + utils.License().Features.SetDefaults() + *utils.License().Features.MFA = true *utils.Cfg.ServiceSettings.EnableMultifactorAuthentication = true th.LoginBasic() diff --git a/api4/webhook_test.go b/api4/webhook_test.go index 96451f8a7..80328e373 100644 --- a/api4/webhook_test.go +++ b/api4/webhook_test.go @@ -4,8 +4,11 @@ package api4 import ( + "bytes" + "net/http" "testing" + "github.com/mattermost/platform/app" "github.com/mattermost/platform/model" "github.com/mattermost/platform/utils" ) @@ -893,3 +896,40 @@ func TestDeleteOutgoingHook(t *testing.T) { CheckForbiddenStatus(t, resp) }) } + +func TestCommandWebhooks(t *testing.T) { + th := Setup().InitBasic().InitSystemAdmin() + Client := th.SystemAdminClient + + cmd := &model.Command{ + CreatorId: th.BasicUser.Id, + TeamId: th.BasicTeam.Id, + URL: "http://nowhere.com", + Method: model.COMMAND_METHOD_POST, + Trigger: "delayed"} + + cmd, _ = Client.CreateCommand(cmd) + args := &model.CommandArgs{ + TeamId: th.BasicTeam.Id, + UserId: th.BasicUser.Id, + ChannelId: th.BasicChannel.Id, + } + hook, err := app.CreateCommandWebhook(cmd.Id, args) + if err != nil { + t.Fatal(err) + } + + if resp, _ := http.Post(Client.Url+"/hooks/commands/123123123123", "application/json", bytes.NewBufferString("{\"text\":\"this is a test\"}")); resp.StatusCode != http.StatusNotFound { + t.Fatal("expected not-found for non-existent hook") + } + + for i := 0; i < 5; i++ { + if _, err := http.Post(Client.Url+"/hooks/commands/"+hook.Id, "application/json", bytes.NewBufferString("{\"text\":\"this is a test\"}")); err != nil { + t.Fatal(err) + } + } + + if resp, _ := http.Post(Client.Url+"/hooks/commands/"+hook.Id, "application/json", bytes.NewBufferString("{\"text\":\"this is a test\"}")); resp.StatusCode != http.StatusBadRequest { + t.Fatal("expected error for sixth usage") + } +} |