diff --git a/api4/emoji_test.go b/api4/emoji_test.go index 6762d090e2..ac8395c26e 100644 --- a/api4/emoji_test.go +++ b/api4/emoji_test.go @@ -7,6 +7,7 @@ import ( "bytes" "image" _ "image/gif" + "io/ioutil" "os" "path/filepath" "testing" @@ -92,6 +93,20 @@ func TestCreateEmoji(t *testing.T) { require.Equal(t, newEmoji.Name, emoji.Name, "create with wrong name") checkEmojiFile(newEmoji.Id, "gif") + // try to create a valid webp emoji + emoji = &model.Emoji{ + CreatorId: th.BasicUser.Id, + Name: model.NewId(), + } + + path, _ := fileutils.FindDir("tests") + bytes, err := ioutil.ReadFile(filepath.Join(path, "testwebp.webp")) + require.NoError(t, err) + newEmoji, _, err = client.CreateEmoji(emoji, bytes, "image.webp") + require.NoError(t, err) + require.Equal(t, newEmoji.Name, emoji.Name, "create with wrong name") + checkEmojiFile(newEmoji.Id, "png") // emoji must be converted from webp to png + // try to create a valid jpeg emoji emoji = &model.Emoji{ CreatorId: th.BasicUser.Id, diff --git a/api4/file_test.go b/api4/file_test.go index 769a0153ef..276dfb4cef 100644 --- a/api4/file_test.go +++ b/api4/file_test.go @@ -453,6 +453,17 @@ func TestUploadFiles(t *testing.T) { expectedImageMiniPreview: []bool{false}, expectedCreatorId: th.BasicUser.Id, }, + // Webp image test + { + title: "Webp image", + names: []string{"testwebp.webp"}, + expectImage: true, + expectedImageWidths: []int{128}, + expectedImageHeights: []int{256}, + expectedImageHasPreview: []bool{true}, + expectedCreatorId: th.BasicUser.Id, + expectedImageMiniPreview: []bool{true}, + }, // Error cases { title: "Error channel_id does not exist", diff --git a/app/emoji.go b/app/emoji.go index f319e26bb7..360619ab3c 100644 --- a/app/emoji.go +++ b/app/emoji.go @@ -21,6 +21,7 @@ import ( "path" "github.com/disintegration/imaging" + _ "golang.org/x/image/webp" "github.com/mattermost/mattermost-server/v6/model" "github.com/mattermost/mattermost-server/v6/shared/mlog" diff --git a/tests/testwebp.webp b/tests/testwebp.webp new file mode 100644 index 0000000000..ac4182b897 Binary files /dev/null and b/tests/testwebp.webp differ