MM-13932 Fix image metadata for invalid image links (#10217)
Этот коммит содержится в:
коммит произвёл
Carlos Tadeu Panato Junior
родитель
a2f46c0466
Коммит
46b05499cc
@@ -192,7 +192,7 @@ func (a *App) getImagesForPost(post *model.Post, imageURLs []string, isNewPost b
|
|||||||
if _, image, err := a.getLinkMetadata(imageURL, post.CreateAt, isNewPost); err != nil {
|
if _, image, err := a.getLinkMetadata(imageURL, post.CreateAt, isNewPost); err != nil {
|
||||||
mlog.Warn("Failed to get dimensions of an image in a post",
|
mlog.Warn("Failed to get dimensions of an image in a post",
|
||||||
mlog.String("post_id", post.Id), mlog.String("image_url", imageURL), mlog.Any("err", err))
|
mlog.String("post_id", post.Id), mlog.String("image_url", imageURL), mlog.Any("err", err))
|
||||||
} else {
|
} else if image != nil {
|
||||||
images[imageURL] = image
|
images[imageURL] = image
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -496,6 +496,61 @@ func testProxyOpenGraphImage(t *testing.T, th *TestHelper, shouldProxy bool) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestGetImagesForPost(t *testing.T) {
|
||||||
|
t.Run("with an image link", func(t *testing.T) {
|
||||||
|
th := Setup()
|
||||||
|
defer th.TearDown()
|
||||||
|
|
||||||
|
th.App.UpdateConfig(func(cfg *model.Config) {
|
||||||
|
*cfg.ServiceSettings.AllowedUntrustedInternalConnections = "127.0.0.1"
|
||||||
|
})
|
||||||
|
|
||||||
|
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
file, err := testutils.ReadTestFile("test.png")
|
||||||
|
require.Nil(t, err)
|
||||||
|
|
||||||
|
w.Header().Set("Content-Type", "image/png")
|
||||||
|
w.Write(file)
|
||||||
|
}))
|
||||||
|
|
||||||
|
post := &model.Post{
|
||||||
|
Metadata: &model.PostMetadata{},
|
||||||
|
}
|
||||||
|
imageURL := server.URL + "/image.png"
|
||||||
|
|
||||||
|
images := th.App.getImagesForPost(post, []string{imageURL}, false)
|
||||||
|
|
||||||
|
assert.Equal(t, images, map[string]*model.PostImage{
|
||||||
|
imageURL: {
|
||||||
|
Width: 408,
|
||||||
|
Height: 336,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
t.Run("with an invalid image link", func(t *testing.T) {
|
||||||
|
th := Setup()
|
||||||
|
defer th.TearDown()
|
||||||
|
|
||||||
|
th.App.UpdateConfig(func(cfg *model.Config) {
|
||||||
|
*cfg.ServiceSettings.AllowedUntrustedInternalConnections = "127.0.0.1"
|
||||||
|
})
|
||||||
|
|
||||||
|
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
w.WriteHeader(http.StatusInternalServerError)
|
||||||
|
}))
|
||||||
|
|
||||||
|
post := &model.Post{
|
||||||
|
Metadata: &model.PostMetadata{},
|
||||||
|
}
|
||||||
|
imageURL := server.URL + "/bad_image.png"
|
||||||
|
|
||||||
|
images := th.App.getImagesForPost(post, []string{imageURL}, false)
|
||||||
|
|
||||||
|
assert.Equal(t, images, map[string]*model.PostImage{})
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
func TestGetEmojiNamesForString(t *testing.T) {
|
func TestGetEmojiNamesForString(t *testing.T) {
|
||||||
testCases := []struct {
|
testCases := []struct {
|
||||||
Description string
|
Description string
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user