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>
Этот коммит содержится в:
Ashish Bhate
2022-06-03 09:25:40 +05:30
коммит произвёл GitHub
родитель c975fdc982
Коммит 1f6e2fe846
3 изменённых файлов: 9 добавлений и 1 удалений

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

@@ -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) {