Этот коммит содержится в:
Ben Schumacher
2025-01-13 20:23:09 +01:00
коммит произвёл GitHub
родитель 091d1bba8b
Коммит 8d4bf4bae0
50 изменённых файлов: 2429 добавлений и 745 удалений

Просмотреть файл

@@ -20,6 +20,7 @@ import (
"github.com/mattermost/mattermost/server/public/model"
"github.com/mattermost/mattermost/server/public/shared/mlog"
"github.com/mattermost/mattermost/server/public/utils"
"github.com/mattermost/mattermost/server/v8/channels/audit"
"github.com/mattermost/mattermost/server/v8/config"
"github.com/mattermost/mattermost/server/v8/platform/services/cache"
@@ -112,14 +113,10 @@ func generateSupportPacket(c *Context, w http.ResponseWriter, r *http.Request) {
fileDatas := c.App.GenerateSupportPacket(c.AppContext, supportPacketOptions)
// Constructing the ZIP file name as per spec (mattermost_support_packet_YYYY-MM-DD-HH-MM.zip)
// Note that this filename is also being checked at the webapp, please update the
// regex within the commercial_support_modal.tsx file if the naming convention ever changes.
now := time.Now()
outputZipFilename := fmt.Sprintf("mattermost_support_packet_%s.zip", now.Format("2006-01-02-03-04"))
outputZipFilename := supportPacketFileName(now, c.App.License().Customer.Company)
fileStorageBackend := c.App.FileBackend()
// We do this incase we get concurrent requests, we will always have a unique directory.
// This is to avoid the situation where we try to write to the same directory while we are trying to delete it (further down)
outputDirectoryToUse := OutputDirectory + "_" + model.NewId()
@@ -147,6 +144,13 @@ func generateSupportPacket(c *Context, w http.ResponseWriter, r *http.Request) {
web.WriteFileResponse(outputZipFilename, FileMime, 0, now, *c.App.Config().ServiceSettings.WebserverMode, fileBytesReader, true, w, r)
}
// supportPacketFileName returns the ZIP file name in the format mm_support_packet_$CUSTOMER_NAME_YYYY-MM-DDTHH-MM.zip.
// Note that this filename is also being checked at the webapp, please update the
// regex within the commercial_support_modal.tsx file if the naming convention ever changes.
func supportPacketFileName(now time.Time, customerName string) string {
return fmt.Sprintf("mm_support_packet_%s_%s.zip", utils.SanitizeFileName(customerName), now.Format("2006-01-02T15-04"))
}
func getSystemPing(c *Context, w http.ResponseWriter, r *http.Request) {
reqs := c.App.Config().ClientRequirements

Просмотреть файл

@@ -233,9 +233,14 @@ func TestGenerateSupportPacket(t *testing.T) {
th.App.Srv().SetLicense(l)
th.TestForSystemAdminAndLocal(t, func(t *testing.T, c *model.Client4) {
file, _, err := th.SystemAdminClient.GenerateSupportPacket(context.Background())
file, filename, _, err := th.SystemAdminClient.GenerateSupportPacket(context.Background())
require.NoError(t, err)
require.NotZero(t, len(file))
assert.Contains(t, filename, "mm_support_packet_My_awesome_Company_")
d, err := io.ReadAll(file)
require.NoError(t, err)
assert.NotZero(t, len(d))
})
})
@@ -249,20 +254,20 @@ func TestGenerateSupportPacket(t *testing.T) {
}()
th.TestForSystemAdminAndLocal(t, func(t *testing.T, c *model.Client4) {
_, resp, err := th.SystemAdminClient.GenerateSupportPacket(context.Background())
_, _, resp, err := th.SystemAdminClient.GenerateSupportPacket(context.Background())
require.Error(t, err)
CheckForbiddenStatus(t, resp)
})
})
t.Run("As a system role, not system admin", func(t *testing.T) {
_, resp, err := th.SystemManagerClient.GenerateSupportPacket(context.Background())
_, _, resp, err := th.SystemManagerClient.GenerateSupportPacket(context.Background())
require.Error(t, err)
CheckForbiddenStatus(t, resp)
})
t.Run("As a Regular User", func(t *testing.T) {
_, resp, err := th.Client.GenerateSupportPacket(context.Background())
_, _, resp, err := th.Client.GenerateSupportPacket(context.Background())
require.Error(t, err)
CheckForbiddenStatus(t, resp)
})
@@ -271,12 +276,43 @@ func TestGenerateSupportPacket(t *testing.T) {
_, err := th.SystemAdminClient.RemoveLicenseFile(context.Background())
require.NoError(t, err)
_, resp, err := th.SystemAdminClient.GenerateSupportPacket(context.Background())
_, _, resp, err := th.SystemAdminClient.GenerateSupportPacket(context.Background())
require.Error(t, err)
CheckForbiddenStatus(t, resp)
})
}
func TestSupportPacketFileName(t *testing.T) {
tests := map[string]struct {
now time.Time
customerName string
expected string
}{
"standard case": {
now: time.Date(2023, 11, 12, 13, 14, 15, 0, time.UTC),
customerName: "TestCustomer",
expected: "mm_support_packet_TestCustomer_2023-11-12T13-14.zip",
},
"customer name with special characters": {
now: time.Date(2023, 11, 12, 13, 14, 15, 0, time.UTC),
customerName: "Test/Customer:Name",
expected: "mm_support_packet_Test_Customer_Name_2023-11-12T13-14.zip",
},
"empty customer name": {
now: time.Date(2023, 10, 10, 10, 10, 10, 0, time.UTC),
customerName: "",
expected: "mm_support_packet__2023-10-10T10-10.zip",
},
}
for name, tt := range tests {
t.Run(name, func(t *testing.T) {
result := supportPacketFileName(tt.now, tt.customerName)
assert.Equal(t, tt.expected, result)
})
}
}
func TestSiteURLTest(t *testing.T) {
th := Setup(t)
defer th.TearDown()