* Fix MM53643

* Add test

* Remove unneeded part of a test

---------

Co-authored-by: Mattermost Build <build@mattermost.com>
Этот коммит содержится в:
Daniel Espino García
2024-01-11 10:52:39 +01:00
коммит произвёл GitHub
родитель 1d879ed0f4
Коммит 539412b353
4 изменённых файлов: 69 добавлений и 38 удалений

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

@@ -395,6 +395,40 @@ func TestSendNotifications_MentionsFollowers(t *testing.T) {
assert.Nil(t, received2.GetBroadcast().BroadcastHooks)
assert.Nil(t, received2.GetBroadcast().BroadcastHookArgs)
})
t.Run("should sanitize the post if there is an error", func(t *testing.T) {
messages, closeWS1 := connectFakeWebSocket(t, th, th.BasicUser.Id, "")
defer closeWS1()
linkedPostId := "123456789"
postURL := fmt.Sprintf("%s/%s/pl/%s", th.App.GetSiteURL(), th.BasicTeam.Name, linkedPostId)
post := &model.Post{
UserId: sender.Id,
ChannelId: th.BasicChannel.Id,
Message: postURL,
Metadata: &model.PostMetadata{
Embeds: []*model.PostEmbed{
{
Type: model.PostEmbedPermalink,
URL: postURL,
Data: &model.Post{},
},
},
},
}
post.SetProps(model.StringInterface{model.PostPropsPreviewedPost: linkedPostId})
_, err := th.App.SendNotifications(th.Context, post, th.BasicTeam, th.BasicChannel, sender, nil, false)
require.NoError(t, err)
received := <-messages
require.Equal(t, model.WebsocketEventPosted, received.EventType())
receivedPost := &model.Post{}
err = json.Unmarshal([]byte(received.GetData()["post"].(string)), &receivedPost)
require.NoError(t, err)
assert.Equal(t, postURL, receivedPost.Message)
assert.Nil(t, receivedPost.Metadata.Embeds)
})
}
func assertUnmarshalsTo(t *testing.T, expected any, actual any) {