MM-41728: Validate emoji size in app while importing (#20325)
* MM-41728: Validate emoji size in app on import * use NotNil instead of Error for AppErr Co-authored-by: Mattermod <mattermod@users.noreply.github.com>
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
c975fdc982
Коммит
1f6e2fe846
@@ -1867,7 +1867,8 @@ func (a *App) importEmoji(data *EmojiImportData, dryRun bool) *model.AppError {
|
||||
}
|
||||
defer file.Close()
|
||||
|
||||
if _, err := a.WriteFile(file, getEmojiImagePath(emoji.Id)); err != nil {
|
||||
reader := utils.NewLimitedReaderWithError(file, MaxEmojiFileSize)
|
||||
if _, err := a.WriteFile(reader, getEmojiImagePath(emoji.Id)); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
|
||||
@@ -19,6 +19,7 @@ import (
|
||||
"github.com/mattermost/mattermost-server/v6/shared/mlog"
|
||||
"github.com/mattermost/mattermost-server/v6/store"
|
||||
"github.com/mattermost/mattermost-server/v6/testlib"
|
||||
"github.com/mattermost/mattermost-server/v6/utils"
|
||||
"github.com/mattermost/mattermost-server/v6/utils/fileutils"
|
||||
)
|
||||
|
||||
@@ -4178,6 +4179,12 @@ func TestImportImportEmoji(t *testing.T) {
|
||||
data = EmojiImportData{Name: ptrStr("smiley"), Image: ptrStr(testImage)}
|
||||
err = th.App.importEmoji(&data, false)
|
||||
assert.Nil(t, err, "System emoji should not fail")
|
||||
|
||||
largeImage := filepath.Join(testsDir, "large_image_file.jpg")
|
||||
data = EmojiImportData{Name: ptrStr(model.NewId()), Image: ptrStr(largeImage)}
|
||||
err = th.App.importEmoji(&data, false)
|
||||
require.NotNil(t, err)
|
||||
require.Contains(t, err.DetailedError, utils.SizeLimitExceeded.Error())
|
||||
}
|
||||
|
||||
func TestImportAttachment(t *testing.T) {
|
||||
|
||||
Двоичные данные
tests/large_image_file.jpg
Обычный файл
Двоичные данные
tests/large_image_file.jpg
Обычный файл
Двоичный файл не отображается.
|
После Ширина: | Высота: | Размер: 2.6 MiB |
Ссылка в новой задаче
Block a user