From cb1b8fc3337f2e7611b342d077573312a62d5619 Mon Sep 17 00:00:00 2001 From: Carlos Tadeu Panato Junior Date: Mon, 12 Mar 2018 12:40:11 +0100 Subject: [MM-9725] Slack compatibility code in webhooks captures incorrect text (#8428) --- app/webhook_test.go | 58 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) (limited to 'app/webhook_test.go') diff --git a/app/webhook_test.go b/app/webhook_test.go index 850e74efc..4d2bc58fa 100644 --- a/app/webhook_test.go +++ b/app/webhook_test.go @@ -317,6 +317,64 @@ func TestCreateWebhookPost(t *testing.T) { if err == nil { t.Fatal("should have failed - bad post type") } + + expectedText := "`<>|<>|`" + post, err = th.App.CreateWebhookPost(hook.UserId, th.BasicChannel, expectedText, "user", "http://iconurl", model.StringInterface{ + "attachments": []*model.SlackAttachment{ + { + Text: "text", + }, + }, + "webhook_display_name": hook.DisplayName, + }, model.POST_SLACK_ATTACHMENT, "") + if err != nil { + t.Fatal(err.Error()) + } + assert.Equal(t, expectedText, post.Message) + + expectedText = "< | \n|\n>" + post, err = th.App.CreateWebhookPost(hook.UserId, th.BasicChannel, expectedText, "user", "http://iconurl", model.StringInterface{ + "attachments": []*model.SlackAttachment{ + { + Text: "text", + }, + }, + "webhook_display_name": hook.DisplayName, + }, model.POST_SLACK_ATTACHMENT, "") + if err != nil { + t.Fatal(err.Error()) + } + assert.Equal(t, expectedText, post.Message) + + expectedText = `commit bc95839e4a430ace453e8b209a3723c000c1729a +Author: foo +Date: Thu Mar 1 19:46:54 2018 +0300 + + commit message 2 + + test | 1 + + 1 file changed, 1 insertion(+) + +commit 5df78b7139b543997838071cd912e375d8bd69b2 +Author: foo +Date: Thu Mar 1 19:46:48 2018 +0300 + + commit message 1 + + test | 3 +++ + 1 file changed, 3 insertions(+)` + post, err = th.App.CreateWebhookPost(hook.UserId, th.BasicChannel, expectedText, "user", "http://iconurl", model.StringInterface{ + "attachments": []*model.SlackAttachment{ + { + Text: "text", + }, + }, + "webhook_display_name": hook.DisplayName, + }, model.POST_SLACK_ATTACHMENT, "") + if err != nil { + t.Fatal(err.Error()) + } + assert.Equal(t, expectedText, post.Message) } func TestSplitWebhookPost(t *testing.T) { -- cgit v1.2.3-1-g7c22