[MM-56792] Clarify large plugin upload error (#26271)
Co-authored-by: Ben Schumacher <ben.schumacher@mattermost.com>
Этот коммит содержится в:
@@ -20,7 +20,8 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
MaximumPluginFileSize = 50 * 1024 * 1024
|
// MaxPluginMemory is the maximum number of bytes to hold in memory when reading a plugin bundle.
|
||||||
|
MaxPluginMemory = 50 * 1024 * 1024
|
||||||
)
|
)
|
||||||
|
|
||||||
func (api *API) InitPlugin() {
|
func (api *API) InitPlugin() {
|
||||||
@@ -57,7 +58,11 @@ func uploadPlugin(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := r.ParseMultipartForm(MaximumPluginFileSize); err != nil {
|
if err := r.ParseMultipartForm(MaxPluginMemory); err != nil {
|
||||||
|
if err.Error() == "http: request body too large" {
|
||||||
|
c.Err = model.NewAppError("uploadPlugin", "api.plugin.upload.file_too_large.app_error", nil, "", http.StatusRequestEntityTooLarge)
|
||||||
|
return
|
||||||
|
}
|
||||||
http.Error(w, err.Error(), http.StatusBadRequest)
|
http.Error(w, err.Error(), http.StatusBadRequest)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -126,6 +126,23 @@ func TestPlugin(t *testing.T) {
|
|||||||
require.Error(t, err)
|
require.Error(t, err)
|
||||||
CheckBadRequestStatus(t, resp)
|
CheckBadRequestStatus(t, resp)
|
||||||
|
|
||||||
|
plugin_sz := int64(111 * 1024 * 1024)
|
||||||
|
fd, err := os.Create(filepath.Join(path, "big_testplugin.tar.gz"))
|
||||||
|
require.NoError(t, err)
|
||||||
|
_, err = fd.Seek(plugin_sz-1, 0)
|
||||||
|
require.NoError(t, err)
|
||||||
|
_, err = fd.Write([]byte{0})
|
||||||
|
require.NoError(t, err)
|
||||||
|
err = fd.Close()
|
||||||
|
require.NoError(t, err)
|
||||||
|
bigData, err := os.ReadFile(filepath.Join(path, "big_testplugin.tar.gz"))
|
||||||
|
require.NoError(t, err)
|
||||||
|
_, resp, err = client.UploadPlugin(context.Background(), bytes.NewReader(bigData))
|
||||||
|
require.Error(t, err)
|
||||||
|
CheckRequestEntityTooLargeStatus(t, resp)
|
||||||
|
err = os.Remove(filepath.Join(path, "big_testplugin.tar.gz"))
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.PluginSettings.Enable = false })
|
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.PluginSettings.Enable = false })
|
||||||
_, resp, err = client.UploadPlugin(context.Background(), bytes.NewReader(tarData))
|
_, resp, err = client.UploadPlugin(context.Background(), bytes.NewReader(tarData))
|
||||||
require.Error(t, err)
|
require.Error(t, err)
|
||||||
|
|||||||
@@ -83,6 +83,7 @@ func getTestResourcesToSetup() []testResourceDetails {
|
|||||||
{"templates", "templates", resourceTypeFolder, actionSymlink},
|
{"templates", "templates", resourceTypeFolder, actionSymlink},
|
||||||
{"tests", "tests", resourceTypeFolder, actionSymlink},
|
{"tests", "tests", resourceTypeFolder, actionSymlink},
|
||||||
{"fonts", "fonts", resourceTypeFolder, actionSymlink},
|
{"fonts", "fonts", resourceTypeFolder, actionSymlink},
|
||||||
|
{"channels/app/plugin_api_tests", "channels/app/plugin_api_tests", resourceTypeFolder, actionSymlink},
|
||||||
{"channels/utils/policies-roles-mapping.json", "channels/utils/policies-roles-mapping.json", resourceTypeFile, actionSymlink},
|
{"channels/utils/policies-roles-mapping.json", "channels/utils/policies-roles-mapping.json", resourceTypeFile, actionSymlink},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2448,6 +2448,10 @@
|
|||||||
"id": "api.plugin.upload.file.app_error",
|
"id": "api.plugin.upload.file.app_error",
|
||||||
"translation": "Unable to open file in multipart/form request."
|
"translation": "Unable to open file in multipart/form request."
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"id": "api.plugin.upload.file_too_large.app_error",
|
||||||
|
"translation": "Uploaded plugin size exceeds limit. This limit can be changed in the System Console via File Storage > Maximum File Size"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"id": "api.plugin.upload.no_file.app_error",
|
"id": "api.plugin.upload.no_file.app_error",
|
||||||
"translation": "Missing file in multipart/form request."
|
"translation": "Missing file in multipart/form request."
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user