From 887ef0b5e1b4a9f358bd1e576bb64932cd7bb3d6 Mon Sep 17 00:00:00 2001 From: Nick Misasi Date: Tue, 17 Nov 2020 12:56:17 -0500 Subject: [PATCH] [MM-29515] Don't allow slack imports in cloud installations (#16271) * Don't allow slack imports in cloud installations * Update api4/team.go Co-authored-by: Maria A Nunez * Add a test case for when the import is restricted in cloud * Update api4/team_test.go Co-authored-by: Maria A Nunez * Check for cloud license instead of restrictsystemadmin * fix tests Co-authored-by: Maria A Nunez Co-authored-by: Mattermod --- api4/team.go | 5 +++++ api4/team_test.go | 14 ++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/api4/team.go b/api4/team.go index 5fbf8a66b3..6faa0f14f0 100644 --- a/api4/team.go +++ b/api4/team.go @@ -1079,6 +1079,11 @@ func teamExists(c *Context, w http.ResponseWriter, r *http.Request) { } func importTeam(c *Context, w http.ResponseWriter, r *http.Request) { + if c.App.Srv().License() != nil && *c.App.Srv().License().Features.Cloud { + c.Err = model.NewAppError("importTeam", "api.restricted_system_admin", nil, "", http.StatusForbidden) + return + } + c.RequireTeamId() if c.Err != nil { return diff --git a/api4/team_test.go b/api4/team_test.go index ca60d6ac75..cf5a9dd9fb 100644 --- a/api4/team_test.go +++ b/api4/team_test.go @@ -2709,6 +2709,20 @@ func TestImportTeam(t *testing.T) { require.Equal(t, posts.Posts[posts.Order[3]].Message, "This is a test post to test the import process", "missing posts in the import process") }) + t.Run("Cloud Forbidden", func(t *testing.T) { + var data []byte + var err error + data, err = testutils.ReadTestFile("Fake_Team_Import.zip") + + require.False(t, err != nil && len(data) == 0, "Error while reading the test file.") + th.App.Srv().SetLicense(model.NewTestLicense("cloud")) + + // Import the channels/users/posts + _, resp := th.SystemAdminClient.ImportTeam(data, binary.Size(data), "slack", "Fake_Team_Import.zip", th.BasicTeam.Id) + CheckForbiddenStatus(t, resp) + th.App.Srv().SetLicense(nil) + }) + t.Run("MissingFile", func(t *testing.T) { _, resp := th.SystemAdminClient.ImportTeam(nil, 4343, "slack", "Fake_Team_Import.zip", th.BasicTeam.Id) CheckBadRequestStatus(t, resp)