2019-11-29 06:59:40 -05:00
|
|
|
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
|
|
|
|
// See LICENSE.txt for license information.
|
2017-08-03 19:25:47 -04:00
|
|
|
|
|
|
|
|
package app
|
|
|
|
|
|
|
|
|
|
import (
|
2023-02-03 03:56:47 -05:00
|
|
|
"bytes"
|
2019-01-09 17:07:08 -05:00
|
|
|
"encoding/json"
|
2024-02-09 14:49:49 -05:00
|
|
|
"fmt"
|
2019-01-09 17:07:08 -05:00
|
|
|
"io"
|
2018-07-25 08:31:41 -04:00
|
|
|
"net/http"
|
|
|
|
|
"net/http/httptest"
|
2019-01-09 17:07:08 -05:00
|
|
|
"net/url"
|
|
|
|
|
"strings"
|
|
|
|
|
"testing"
|
2018-07-25 08:31:41 -04:00
|
|
|
"time"
|
2018-11-06 03:28:55 -05:00
|
|
|
|
2019-01-09 17:07:08 -05:00
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
|
"github.com/stretchr/testify/require"
|
2021-01-07 12:12:43 -05:00
|
|
|
|
2023-06-11 01:24:35 -04:00
|
|
|
"github.com/mattermost/mattermost/server/public/model"
|
|
|
|
|
"github.com/mattermost/mattermost/server/v8/channels/testlib"
|
2017-08-03 19:25:47 -04:00
|
|
|
)
|
|
|
|
|
|
2018-01-02 11:41:23 -05:00
|
|
|
func TestCreateIncomingWebhookForChannel(t *testing.T) {
|
2025-05-30 07:58:26 -04:00
|
|
|
mainHelper.Parallel(t)
|
2025-11-12 07:00:51 -05:00
|
|
|
th := Setup(t).InitBasic(t)
|
2018-01-02 11:41:23 -05:00
|
|
|
|
|
|
|
|
type TestCase struct {
|
|
|
|
|
EnableIncomingHooks bool
|
|
|
|
|
EnablePostUsernameOverride bool
|
|
|
|
|
EnablePostIconOverride bool
|
|
|
|
|
IncomingWebhook model.IncomingWebhook
|
|
|
|
|
|
|
|
|
|
ExpectedError bool
|
|
|
|
|
ExpectedIncomingWebhook *model.IncomingWebhook
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for name, tc := range map[string]TestCase{
|
|
|
|
|
"webhooks not enabled": {
|
|
|
|
|
EnableIncomingHooks: false,
|
|
|
|
|
EnablePostUsernameOverride: false,
|
|
|
|
|
EnablePostIconOverride: false,
|
|
|
|
|
IncomingWebhook: model.IncomingWebhook{
|
|
|
|
|
DisplayName: "title",
|
|
|
|
|
Description: "description",
|
|
|
|
|
ChannelId: th.BasicChannel.Id,
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
ExpectedError: true,
|
|
|
|
|
ExpectedIncomingWebhook: nil,
|
|
|
|
|
},
|
|
|
|
|
"valid: username and post icon url ignored, since override not enabled": {
|
|
|
|
|
EnableIncomingHooks: true,
|
|
|
|
|
EnablePostUsernameOverride: false,
|
|
|
|
|
EnablePostIconOverride: false,
|
|
|
|
|
IncomingWebhook: model.IncomingWebhook{
|
2018-01-03 10:35:36 -05:00
|
|
|
DisplayName: "title",
|
|
|
|
|
Description: "description",
|
|
|
|
|
ChannelId: th.BasicChannel.Id,
|
|
|
|
|
Username: ":invalid and ignored:",
|
|
|
|
|
IconURL: "ignored",
|
2018-01-02 11:41:23 -05:00
|
|
|
},
|
|
|
|
|
|
|
|
|
|
ExpectedError: false,
|
|
|
|
|
ExpectedIncomingWebhook: &model.IncomingWebhook{
|
|
|
|
|
DisplayName: "title",
|
|
|
|
|
Description: "description",
|
|
|
|
|
ChannelId: th.BasicChannel.Id,
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
"invalid username, override enabled": {
|
|
|
|
|
EnableIncomingHooks: true,
|
|
|
|
|
EnablePostUsernameOverride: true,
|
|
|
|
|
EnablePostIconOverride: false,
|
|
|
|
|
IncomingWebhook: model.IncomingWebhook{
|
2018-01-03 10:35:36 -05:00
|
|
|
DisplayName: "title",
|
|
|
|
|
Description: "description",
|
|
|
|
|
ChannelId: th.BasicChannel.Id,
|
|
|
|
|
Username: ":invalid:",
|
2018-01-02 11:41:23 -05:00
|
|
|
},
|
|
|
|
|
|
|
|
|
|
ExpectedError: true,
|
|
|
|
|
ExpectedIncomingWebhook: nil,
|
|
|
|
|
},
|
|
|
|
|
"valid, no username or post icon url provided": {
|
|
|
|
|
EnableIncomingHooks: true,
|
|
|
|
|
EnablePostUsernameOverride: true,
|
|
|
|
|
EnablePostIconOverride: true,
|
|
|
|
|
IncomingWebhook: model.IncomingWebhook{
|
|
|
|
|
DisplayName: "title",
|
|
|
|
|
Description: "description",
|
|
|
|
|
ChannelId: th.BasicChannel.Id,
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
ExpectedError: false,
|
|
|
|
|
ExpectedIncomingWebhook: &model.IncomingWebhook{
|
|
|
|
|
DisplayName: "title",
|
|
|
|
|
Description: "description",
|
|
|
|
|
ChannelId: th.BasicChannel.Id,
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
"valid, with username and post icon": {
|
|
|
|
|
EnableIncomingHooks: true,
|
|
|
|
|
EnablePostUsernameOverride: true,
|
|
|
|
|
EnablePostIconOverride: true,
|
|
|
|
|
IncomingWebhook: model.IncomingWebhook{
|
2018-01-03 10:35:36 -05:00
|
|
|
DisplayName: "title",
|
|
|
|
|
Description: "description",
|
|
|
|
|
ChannelId: th.BasicChannel.Id,
|
|
|
|
|
Username: "valid",
|
|
|
|
|
IconURL: "http://example.com/icon",
|
2018-01-02 11:41:23 -05:00
|
|
|
},
|
|
|
|
|
|
|
|
|
|
ExpectedError: false,
|
|
|
|
|
ExpectedIncomingWebhook: &model.IncomingWebhook{
|
2018-01-03 10:35:36 -05:00
|
|
|
DisplayName: "title",
|
|
|
|
|
Description: "description",
|
|
|
|
|
ChannelId: th.BasicChannel.Id,
|
|
|
|
|
Username: "valid",
|
|
|
|
|
IconURL: "http://example.com/icon",
|
2018-01-02 11:41:23 -05:00
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
} {
|
|
|
|
|
t.Run(name, func(t *testing.T) {
|
2019-01-31 08:12:01 -05:00
|
|
|
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableIncomingWebhooks = tc.EnableIncomingHooks })
|
2018-01-02 11:41:23 -05:00
|
|
|
th.App.UpdateConfig(func(cfg *model.Config) {
|
2019-01-31 08:12:01 -05:00
|
|
|
*cfg.ServiceSettings.EnablePostUsernameOverride = tc.EnablePostUsernameOverride
|
2018-01-02 11:41:23 -05:00
|
|
|
})
|
2019-01-31 08:12:01 -05:00
|
|
|
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnablePostIconOverride = tc.EnablePostIconOverride })
|
2018-01-02 11:41:23 -05:00
|
|
|
|
2025-04-15 03:50:22 -04:00
|
|
|
createdHook, appErr := th.App.CreateIncomingWebhookForChannel(th.BasicUser.Id, th.BasicChannel, &tc.IncomingWebhook)
|
2019-09-06 06:52:51 -04:00
|
|
|
if tc.ExpectedError {
|
2025-04-15 03:50:22 -04:00
|
|
|
require.NotNil(t, appErr, "should have failed")
|
2019-09-06 06:52:51 -04:00
|
|
|
} else {
|
2025-04-15 03:50:22 -04:00
|
|
|
require.Nil(t, appErr, "should not have failed")
|
2018-01-02 11:41:23 -05:00
|
|
|
}
|
|
|
|
|
if createdHook != nil {
|
2025-04-15 03:50:22 -04:00
|
|
|
defer func() {
|
|
|
|
|
appErr := th.App.DeleteIncomingWebhook(createdHook.Id)
|
|
|
|
|
require.Nil(t, appErr, "Error cleaning up webhook")
|
|
|
|
|
}()
|
2018-01-02 11:41:23 -05:00
|
|
|
}
|
|
|
|
|
if tc.ExpectedIncomingWebhook == nil {
|
2019-09-06 06:52:51 -04:00
|
|
|
assert.Nil(t, createdHook, "expected nil webhook")
|
|
|
|
|
} else if assert.NotNil(t, createdHook, "expected non-nil webhook") {
|
|
|
|
|
assert.Equal(t, tc.ExpectedIncomingWebhook.DisplayName, createdHook.DisplayName)
|
|
|
|
|
assert.Equal(t, tc.ExpectedIncomingWebhook.Description, createdHook.Description)
|
|
|
|
|
assert.Equal(t, tc.ExpectedIncomingWebhook.ChannelId, createdHook.ChannelId)
|
|
|
|
|
assert.Equal(t, tc.ExpectedIncomingWebhook.Username, createdHook.Username)
|
|
|
|
|
assert.Equal(t, tc.ExpectedIncomingWebhook.IconURL, createdHook.IconURL)
|
2018-01-02 11:41:23 -05:00
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestUpdateIncomingWebhook(t *testing.T) {
|
2025-05-30 07:58:26 -04:00
|
|
|
mainHelper.Parallel(t)
|
2025-11-12 07:00:51 -05:00
|
|
|
th := Setup(t).InitBasic(t)
|
2018-01-02 11:41:23 -05:00
|
|
|
|
|
|
|
|
type TestCase struct {
|
|
|
|
|
EnableIncomingHooks bool
|
|
|
|
|
EnablePostUsernameOverride bool
|
|
|
|
|
EnablePostIconOverride bool
|
|
|
|
|
IncomingWebhook model.IncomingWebhook
|
|
|
|
|
|
|
|
|
|
ExpectedError bool
|
|
|
|
|
ExpectedIncomingWebhook *model.IncomingWebhook
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for name, tc := range map[string]TestCase{
|
|
|
|
|
"webhooks not enabled": {
|
|
|
|
|
EnableIncomingHooks: false,
|
|
|
|
|
EnablePostUsernameOverride: false,
|
|
|
|
|
EnablePostIconOverride: false,
|
|
|
|
|
IncomingWebhook: model.IncomingWebhook{
|
|
|
|
|
DisplayName: "title",
|
|
|
|
|
Description: "description",
|
|
|
|
|
ChannelId: th.BasicChannel.Id,
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
ExpectedError: true,
|
|
|
|
|
ExpectedIncomingWebhook: nil,
|
|
|
|
|
},
|
|
|
|
|
"valid: username and post icon url ignored, since override not enabled": {
|
|
|
|
|
EnableIncomingHooks: true,
|
|
|
|
|
EnablePostUsernameOverride: false,
|
|
|
|
|
EnablePostIconOverride: false,
|
|
|
|
|
IncomingWebhook: model.IncomingWebhook{
|
2018-01-03 10:35:36 -05:00
|
|
|
DisplayName: "title",
|
|
|
|
|
Description: "description",
|
|
|
|
|
ChannelId: th.BasicChannel.Id,
|
|
|
|
|
Username: ":invalid and ignored:",
|
|
|
|
|
IconURL: "ignored",
|
2018-01-02 11:41:23 -05:00
|
|
|
},
|
|
|
|
|
|
|
|
|
|
ExpectedError: false,
|
|
|
|
|
ExpectedIncomingWebhook: &model.IncomingWebhook{
|
|
|
|
|
DisplayName: "title",
|
|
|
|
|
Description: "description",
|
|
|
|
|
ChannelId: th.BasicChannel.Id,
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
"invalid username, override enabled": {
|
|
|
|
|
EnableIncomingHooks: true,
|
|
|
|
|
EnablePostUsernameOverride: true,
|
|
|
|
|
EnablePostIconOverride: false,
|
|
|
|
|
IncomingWebhook: model.IncomingWebhook{
|
2018-01-03 10:35:36 -05:00
|
|
|
DisplayName: "title",
|
|
|
|
|
Description: "description",
|
|
|
|
|
ChannelId: th.BasicChannel.Id,
|
|
|
|
|
Username: ":invalid:",
|
2018-01-02 11:41:23 -05:00
|
|
|
},
|
|
|
|
|
|
|
|
|
|
ExpectedError: true,
|
|
|
|
|
ExpectedIncomingWebhook: nil,
|
|
|
|
|
},
|
|
|
|
|
"valid, no username or post icon url provided": {
|
|
|
|
|
EnableIncomingHooks: true,
|
|
|
|
|
EnablePostUsernameOverride: true,
|
|
|
|
|
EnablePostIconOverride: true,
|
|
|
|
|
IncomingWebhook: model.IncomingWebhook{
|
|
|
|
|
DisplayName: "title",
|
|
|
|
|
Description: "description",
|
|
|
|
|
ChannelId: th.BasicChannel.Id,
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
ExpectedError: false,
|
|
|
|
|
ExpectedIncomingWebhook: &model.IncomingWebhook{
|
|
|
|
|
DisplayName: "title",
|
|
|
|
|
Description: "description",
|
|
|
|
|
ChannelId: th.BasicChannel.Id,
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
"valid, with username and post icon": {
|
|
|
|
|
EnableIncomingHooks: true,
|
|
|
|
|
EnablePostUsernameOverride: true,
|
|
|
|
|
EnablePostIconOverride: true,
|
|
|
|
|
IncomingWebhook: model.IncomingWebhook{
|
2018-01-03 10:35:36 -05:00
|
|
|
DisplayName: "title",
|
|
|
|
|
Description: "description",
|
|
|
|
|
ChannelId: th.BasicChannel.Id,
|
|
|
|
|
Username: "valid",
|
|
|
|
|
IconURL: "http://example.com/icon",
|
2018-01-02 11:41:23 -05:00
|
|
|
},
|
|
|
|
|
|
|
|
|
|
ExpectedError: false,
|
|
|
|
|
ExpectedIncomingWebhook: &model.IncomingWebhook{
|
2018-01-03 10:35:36 -05:00
|
|
|
DisplayName: "title",
|
|
|
|
|
Description: "description",
|
|
|
|
|
ChannelId: th.BasicChannel.Id,
|
|
|
|
|
Username: "valid",
|
|
|
|
|
IconURL: "http://example.com/icon",
|
2018-01-02 11:41:23 -05:00
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
} {
|
|
|
|
|
t.Run(name, func(t *testing.T) {
|
2019-01-31 08:12:01 -05:00
|
|
|
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableIncomingWebhooks = true })
|
2018-01-02 11:41:23 -05:00
|
|
|
|
2025-04-15 03:50:22 -04:00
|
|
|
hook, appErr := th.App.CreateIncomingWebhookForChannel(th.BasicUser.Id, th.BasicChannel, &model.IncomingWebhook{
|
2018-01-02 11:41:23 -05:00
|
|
|
ChannelId: th.BasicChannel.Id,
|
|
|
|
|
})
|
2025-04-15 03:50:22 -04:00
|
|
|
require.Nil(t, appErr)
|
|
|
|
|
defer func() {
|
|
|
|
|
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableIncomingWebhooks = true })
|
|
|
|
|
appErr = th.App.DeleteIncomingWebhook(hook.Id)
|
|
|
|
|
require.Nil(t, appErr, "Error cleaning up webhook")
|
|
|
|
|
}()
|
2018-01-02 11:41:23 -05:00
|
|
|
|
2019-01-31 08:12:01 -05:00
|
|
|
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableIncomingWebhooks = tc.EnableIncomingHooks })
|
2018-01-02 11:41:23 -05:00
|
|
|
th.App.UpdateConfig(func(cfg *model.Config) {
|
2019-01-31 08:12:01 -05:00
|
|
|
*cfg.ServiceSettings.EnablePostUsernameOverride = tc.EnablePostUsernameOverride
|
2018-01-02 11:41:23 -05:00
|
|
|
})
|
2019-01-31 08:12:01 -05:00
|
|
|
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnablePostIconOverride = tc.EnablePostIconOverride })
|
2018-01-02 11:41:23 -05:00
|
|
|
|
2025-04-15 03:50:22 -04:00
|
|
|
updatedHook, appErr := th.App.UpdateIncomingWebhook(hook, &tc.IncomingWebhook)
|
2019-09-06 06:52:51 -04:00
|
|
|
if tc.ExpectedError {
|
2025-04-15 03:50:22 -04:00
|
|
|
require.NotNil(t, appErr, "should have failed")
|
2019-09-06 06:52:51 -04:00
|
|
|
} else {
|
2025-04-15 03:50:22 -04:00
|
|
|
require.Nil(t, appErr, "should not have failed")
|
2018-01-02 11:41:23 -05:00
|
|
|
}
|
|
|
|
|
if tc.ExpectedIncomingWebhook == nil {
|
2019-09-06 06:52:51 -04:00
|
|
|
assert.Nil(t, updatedHook, "expected nil webhook")
|
|
|
|
|
} else if assert.NotNil(t, updatedHook, "expected non-nil webhook") {
|
|
|
|
|
assert.Equal(t, tc.ExpectedIncomingWebhook.DisplayName, updatedHook.DisplayName)
|
|
|
|
|
assert.Equal(t, tc.ExpectedIncomingWebhook.Description, updatedHook.Description)
|
|
|
|
|
assert.Equal(t, tc.ExpectedIncomingWebhook.ChannelId, updatedHook.ChannelId)
|
|
|
|
|
assert.Equal(t, tc.ExpectedIncomingWebhook.Username, updatedHook.Username)
|
|
|
|
|
assert.Equal(t, tc.ExpectedIncomingWebhook.IconURL, updatedHook.IconURL)
|
2018-01-02 11:41:23 -05:00
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-08-03 19:25:47 -04:00
|
|
|
func TestCreateWebhookPost(t *testing.T) {
|
2025-05-30 07:58:26 -04:00
|
|
|
mainHelper.Parallel(t)
|
2024-03-07 00:25:28 -05:00
|
|
|
testCluster := &testlib.FakeClusterInterface{}
|
2025-11-12 07:00:51 -05:00
|
|
|
th := SetupWithClusterMock(t, testCluster).InitBasic(t)
|
2017-08-03 19:25:47 -04:00
|
|
|
|
2019-01-31 08:12:01 -05:00
|
|
|
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableIncomingWebhooks = true })
|
2017-08-03 19:25:47 -04:00
|
|
|
|
2025-04-15 03:50:22 -04:00
|
|
|
hook, appErr := th.App.CreateIncomingWebhookForChannel(th.BasicUser.Id, th.BasicChannel, &model.IncomingWebhook{ChannelId: th.BasicChannel.Id})
|
|
|
|
|
require.Nil(t, appErr)
|
|
|
|
|
defer func() {
|
|
|
|
|
appErr = th.App.DeleteIncomingWebhook(hook.Id)
|
|
|
|
|
require.Nil(t, appErr, "Error cleaning up webhook")
|
|
|
|
|
}()
|
2017-08-03 19:25:47 -04:00
|
|
|
|
2025-04-15 03:50:22 -04:00
|
|
|
post, appErr := th.App.CreateWebhookPost(th.Context, hook.UserId, th.BasicChannel, "foo", "user", "http://iconurl", "",
|
2024-04-17 07:32:32 -04:00
|
|
|
model.StringInterface{
|
2026-03-10 11:37:21 -04:00
|
|
|
model.PostPropsAttachments: []*model.MessageAttachment{
|
2024-04-17 07:32:32 -04:00
|
|
|
{
|
|
|
|
|
Text: "text",
|
|
|
|
|
},
|
2017-08-03 19:25:47 -04:00
|
|
|
},
|
2025-03-20 07:53:50 -04:00
|
|
|
model.PostPropsWebhookDisplayName: hook.DisplayName,
|
2017-08-03 19:25:47 -04:00
|
|
|
},
|
2026-03-10 11:37:21 -04:00
|
|
|
model.PostTypeMessageAttachment,
|
2024-04-17 07:32:32 -04:00
|
|
|
"", nil)
|
2025-04-15 03:50:22 -04:00
|
|
|
require.Nil(t, appErr)
|
2017-08-03 19:25:47 -04:00
|
|
|
|
2025-03-20 07:53:50 -04:00
|
|
|
assert.Contains(t, post.GetProps(), model.PostPropsFromWebhook, "missing from_webhook prop")
|
|
|
|
|
assert.Contains(t, post.GetProps(), model.PostPropsAttachments, "missing attachments prop")
|
|
|
|
|
assert.Contains(t, post.GetProps(), model.PostPropsWebhookDisplayName, "missing webhook_display_name prop")
|
2017-10-09 13:30:48 -04:00
|
|
|
|
2025-04-15 03:50:22 -04:00
|
|
|
_, appErr = th.App.CreateWebhookPost(th.Context, hook.UserId, th.BasicChannel, "foo", "user", "http://iconurl", "", nil, model.PostTypeSystemGeneric, "", nil)
|
|
|
|
|
require.NotNil(t, appErr, "Should have failed - bad post type")
|
2018-03-12 07:40:11 -04:00
|
|
|
|
|
|
|
|
expectedText := "`<>|<>|`"
|
2025-04-15 03:50:22 -04:00
|
|
|
post, appErr = th.App.CreateWebhookPost(th.Context, hook.UserId, th.BasicChannel, expectedText, "user", "http://iconurl", "", model.StringInterface{
|
2026-03-10 11:37:21 -04:00
|
|
|
model.PostPropsAttachments: []*model.MessageAttachment{
|
2018-03-12 07:40:11 -04:00
|
|
|
{
|
|
|
|
|
Text: "text",
|
|
|
|
|
},
|
|
|
|
|
},
|
2025-03-20 07:53:50 -04:00
|
|
|
model.PostPropsWebhookDisplayName: hook.DisplayName,
|
2026-03-10 11:37:21 -04:00
|
|
|
}, model.PostTypeMessageAttachment, "", nil)
|
2025-04-15 03:50:22 -04:00
|
|
|
require.Nil(t, appErr)
|
2018-03-12 07:40:11 -04:00
|
|
|
assert.Equal(t, expectedText, post.Message)
|
|
|
|
|
|
|
|
|
|
expectedText = "< | \n|\n>"
|
2025-04-15 03:50:22 -04:00
|
|
|
post, appErr = th.App.CreateWebhookPost(th.Context, hook.UserId, th.BasicChannel, expectedText, "user", "http://iconurl", "", model.StringInterface{
|
2026-03-10 11:37:21 -04:00
|
|
|
model.PostPropsAttachments: []*model.MessageAttachment{
|
2018-03-12 07:40:11 -04:00
|
|
|
{
|
|
|
|
|
Text: "text",
|
|
|
|
|
},
|
|
|
|
|
},
|
2025-03-20 07:53:50 -04:00
|
|
|
model.PostPropsWebhookDisplayName: hook.DisplayName,
|
2026-03-10 11:37:21 -04:00
|
|
|
}, model.PostTypeMessageAttachment, "", nil)
|
2025-04-15 03:50:22 -04:00
|
|
|
require.Nil(t, appErr)
|
2018-03-12 07:40:11 -04:00
|
|
|
assert.Equal(t, expectedText, post.Message)
|
|
|
|
|
|
|
|
|
|
expectedText = `commit bc95839e4a430ace453e8b209a3723c000c1729a
|
|
|
|
|
Author: foo <foo@example.org>
|
|
|
|
|
Date: Thu Mar 1 19:46:54 2018 +0300
|
|
|
|
|
|
|
|
|
|
commit message 2
|
|
|
|
|
|
|
|
|
|
test | 1 +
|
|
|
|
|
1 file changed, 1 insertion(+)
|
|
|
|
|
|
|
|
|
|
commit 5df78b7139b543997838071cd912e375d8bd69b2
|
|
|
|
|
Author: foo <foo@example.org>
|
|
|
|
|
Date: Thu Mar 1 19:46:48 2018 +0300
|
|
|
|
|
|
|
|
|
|
commit message 1
|
|
|
|
|
|
|
|
|
|
test | 3 +++
|
|
|
|
|
1 file changed, 3 insertions(+)`
|
2025-04-15 03:50:22 -04:00
|
|
|
post, appErr = th.App.CreateWebhookPost(th.Context, hook.UserId, th.BasicChannel, expectedText, "user", "http://iconurl", "", model.StringInterface{
|
2026-03-10 11:37:21 -04:00
|
|
|
model.PostPropsAttachments: []*model.MessageAttachment{
|
2018-03-12 07:40:11 -04:00
|
|
|
{
|
|
|
|
|
Text: "text",
|
|
|
|
|
},
|
|
|
|
|
},
|
2025-03-20 07:53:50 -04:00
|
|
|
model.PostPropsWebhookDisplayName: hook.DisplayName,
|
2026-03-10 11:37:21 -04:00
|
|
|
}, model.PostTypeMessageAttachment, "", nil)
|
2025-04-15 03:50:22 -04:00
|
|
|
require.Nil(t, appErr)
|
2018-03-12 07:40:11 -04:00
|
|
|
assert.Equal(t, expectedText, post.Message)
|
2023-02-03 03:56:47 -05:00
|
|
|
|
|
|
|
|
t.Run("should set webhook creator status to online", func(t *testing.T) {
|
|
|
|
|
testCluster.ClearMessages()
|
2024-04-17 07:32:32 -04:00
|
|
|
_, appErr := th.App.CreateWebhookPost(th.Context, hook.UserId, th.BasicChannel, "text", "", "", "", model.StringInterface{}, model.PostTypeDefault, "", nil)
|
2023-02-03 03:56:47 -05:00
|
|
|
require.Nil(t, appErr)
|
|
|
|
|
|
2024-03-07 00:25:28 -05:00
|
|
|
msgs := testCluster.SelectMessages(func(msg *model.ClusterMessage) bool {
|
|
|
|
|
event, err := model.WebSocketEventFromJSON(bytes.NewReader(msg.Data))
|
|
|
|
|
return err == nil && event.EventType() == model.WebsocketEventPosted
|
|
|
|
|
})
|
|
|
|
|
require.Len(t, msgs, 1)
|
|
|
|
|
// We know there will be no error from the filter condition.
|
|
|
|
|
event, _ := model.WebSocketEventFromJSON(bytes.NewReader(msgs[0].Data))
|
|
|
|
|
assert.Equal(t, false, event.GetData()["set_online"])
|
2023-02-03 03:56:47 -05:00
|
|
|
})
|
2017-08-03 19:25:47 -04:00
|
|
|
}
|
2017-10-24 19:36:31 -04:00
|
|
|
|
2025-05-28 18:54:06 -04:00
|
|
|
func TestCreateWebhookPostWithOverriddenIcon(t *testing.T) {
|
2025-11-12 07:00:51 -05:00
|
|
|
th := Setup(t).InitBasic(t)
|
2025-05-28 18:54:06 -04:00
|
|
|
|
|
|
|
|
th.App.UpdateConfig(func(cfg *model.Config) {
|
|
|
|
|
*cfg.ServiceSettings.EnableIncomingWebhooks = true
|
|
|
|
|
*cfg.ServiceSettings.EnablePostIconOverride = true
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
hook, appErr := th.App.CreateIncomingWebhookForChannel(th.BasicUser.Id, th.BasicChannel, &model.IncomingWebhook{ChannelId: th.BasicChannel.Id})
|
|
|
|
|
require.Nil(t, appErr)
|
|
|
|
|
|
|
|
|
|
t.Run("should set props based on icon_url", func(t *testing.T) {
|
|
|
|
|
post, appErr := th.App.CreateWebhookPost(
|
|
|
|
|
th.Context,
|
|
|
|
|
hook.UserId,
|
|
|
|
|
th.BasicChannel,
|
|
|
|
|
"test post",
|
|
|
|
|
"",
|
|
|
|
|
"https://example.com/icon.png",
|
|
|
|
|
"",
|
|
|
|
|
nil,
|
|
|
|
|
"",
|
|
|
|
|
"",
|
|
|
|
|
nil,
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
require.Nil(t, appErr)
|
|
|
|
|
assert.Equal(t, "https://example.com/icon.png", post.GetProp(model.PostPropsOverrideIconURL))
|
|
|
|
|
|
2025-10-02 10:54:29 -04:00
|
|
|
clientPost := th.App.PreparePostForClient(th.Context, post, &model.PreparePostForClientOpts{IsNewPost: true})
|
2025-05-28 18:54:06 -04:00
|
|
|
|
|
|
|
|
assert.Equal(t, "https://example.com/icon.png", clientPost.GetProp(model.PostPropsOverrideIconURL))
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
t.Run("should set props based on icon_emoji", func(t *testing.T) {
|
|
|
|
|
post, appErr := th.App.CreateWebhookPost(
|
|
|
|
|
th.Context,
|
|
|
|
|
hook.UserId,
|
|
|
|
|
th.BasicChannel,
|
|
|
|
|
"test post",
|
|
|
|
|
"",
|
|
|
|
|
"",
|
|
|
|
|
"smile",
|
|
|
|
|
nil,
|
|
|
|
|
"",
|
|
|
|
|
"",
|
|
|
|
|
nil,
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
require.Nil(t, appErr)
|
|
|
|
|
assert.Equal(t, "smile", post.GetProp(model.PostPropsOverrideIconEmoji))
|
|
|
|
|
|
2025-10-02 10:54:29 -04:00
|
|
|
clientPost := th.App.PreparePostForClient(th.Context, post, &model.PreparePostForClientOpts{IsNewPost: true})
|
2025-05-28 18:54:06 -04:00
|
|
|
|
|
|
|
|
assert.Equal(t, "/static/emoji/1f604.png", clientPost.GetProp(model.PostPropsOverrideIconURL))
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
t.Run("should set props based on icon_emoji (using a custom emoji)", func(t *testing.T) {
|
2025-11-12 07:00:51 -05:00
|
|
|
emoji := th.CreateEmoji(t)
|
2025-05-28 18:54:06 -04:00
|
|
|
|
|
|
|
|
post, appErr := th.App.CreateWebhookPost(
|
|
|
|
|
th.Context,
|
|
|
|
|
hook.UserId,
|
|
|
|
|
th.BasicChannel,
|
|
|
|
|
"test post",
|
|
|
|
|
"",
|
|
|
|
|
"",
|
|
|
|
|
emoji.Name,
|
|
|
|
|
nil,
|
|
|
|
|
"",
|
|
|
|
|
"",
|
|
|
|
|
nil,
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
require.Nil(t, appErr)
|
|
|
|
|
assert.Equal(t, emoji.Name, post.GetProp(model.PostPropsOverrideIconEmoji))
|
|
|
|
|
|
2025-10-02 10:54:29 -04:00
|
|
|
clientPost := th.App.PreparePostForClient(th.Context, post, &model.PreparePostForClientOpts{IsNewPost: true})
|
2025-05-28 18:54:06 -04:00
|
|
|
|
|
|
|
|
assert.Equal(t, fmt.Sprintf("/api/v4/emoji/%s/image", emoji.Id), clientPost.GetProp(model.PostPropsOverrideIconURL))
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
t.Run("should set props based on icon_emoji (with colons around emoji name)", func(t *testing.T) {
|
|
|
|
|
post, appErr := th.App.CreateWebhookPost(
|
|
|
|
|
th.Context,
|
|
|
|
|
hook.UserId,
|
|
|
|
|
th.BasicChannel,
|
|
|
|
|
"test post",
|
|
|
|
|
"",
|
|
|
|
|
"",
|
|
|
|
|
":smile:",
|
|
|
|
|
nil,
|
|
|
|
|
"",
|
|
|
|
|
"",
|
|
|
|
|
nil,
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
require.Nil(t, appErr)
|
|
|
|
|
assert.Equal(t, ":smile:", post.GetProp(model.PostPropsOverrideIconEmoji))
|
|
|
|
|
|
2025-10-02 10:54:29 -04:00
|
|
|
clientPost := th.App.PreparePostForClient(th.Context, post, &model.PreparePostForClientOpts{IsNewPost: true})
|
2025-05-28 18:54:06 -04:00
|
|
|
|
|
|
|
|
assert.Equal(t, "/static/emoji/1f604.png", clientPost.GetProp(model.PostPropsOverrideIconURL))
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
2024-04-17 07:32:32 -04:00
|
|
|
func TestCreateWebhookPostWithPriority(t *testing.T) {
|
2025-05-30 07:58:26 -04:00
|
|
|
mainHelper.Parallel(t)
|
2024-04-17 07:32:32 -04:00
|
|
|
testCluster := &testlib.FakeClusterInterface{}
|
2025-11-12 07:00:51 -05:00
|
|
|
th := SetupWithClusterMock(t, testCluster).InitBasic(t)
|
2024-04-17 07:32:32 -04:00
|
|
|
|
|
|
|
|
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableIncomingWebhooks = true })
|
|
|
|
|
|
2025-04-15 03:50:22 -04:00
|
|
|
hook, appErr := th.App.CreateIncomingWebhookForChannel(th.BasicUser.Id, th.BasicChannel, &model.IncomingWebhook{ChannelId: th.BasicChannel.Id})
|
|
|
|
|
require.Nil(t, appErr)
|
|
|
|
|
defer func() {
|
|
|
|
|
appErr := th.App.DeleteIncomingWebhook(hook.Id)
|
|
|
|
|
require.Nil(t, appErr, "Error cleaning up webhook")
|
|
|
|
|
}()
|
2024-04-17 07:32:32 -04:00
|
|
|
|
|
|
|
|
testConditions := []model.PostPriority{
|
|
|
|
|
{
|
2024-08-05 23:45:00 -04:00
|
|
|
Priority: model.NewPointer("high"),
|
|
|
|
|
RequestedAck: model.NewPointer(true),
|
|
|
|
|
PersistentNotifications: model.NewPointer(false),
|
2024-04-17 07:32:32 -04:00
|
|
|
},
|
|
|
|
|
{
|
2024-08-05 23:45:00 -04:00
|
|
|
Priority: model.NewPointer(""),
|
|
|
|
|
RequestedAck: model.NewPointer(true),
|
|
|
|
|
PersistentNotifications: model.NewPointer(false),
|
2024-04-17 07:32:32 -04:00
|
|
|
},
|
|
|
|
|
{
|
2024-08-05 23:45:00 -04:00
|
|
|
Priority: model.NewPointer("urgent"),
|
|
|
|
|
RequestedAck: model.NewPointer(false),
|
|
|
|
|
PersistentNotifications: model.NewPointer(true),
|
2024-04-17 07:32:32 -04:00
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for _, conditions := range testConditions {
|
2025-04-15 03:50:22 -04:00
|
|
|
post, appErr := th.App.CreateWebhookPost(th.Context, hook.UserId, th.BasicChannel, "foo @"+th.BasicUser.Username, "user", "http://iconurl", "",
|
2025-03-20 07:53:50 -04:00
|
|
|
model.StringInterface{model.PostPropsWebhookDisplayName: hook.DisplayName},
|
2026-03-10 11:37:21 -04:00
|
|
|
model.PostTypeMessageAttachment,
|
2024-04-17 07:32:32 -04:00
|
|
|
"",
|
|
|
|
|
&conditions,
|
|
|
|
|
)
|
|
|
|
|
|
2025-04-15 03:50:22 -04:00
|
|
|
require.Nil(t, appErr)
|
2024-04-17 07:32:32 -04:00
|
|
|
|
|
|
|
|
assert.Equal(t, post.Message, "foo @"+th.BasicUser.Username)
|
2025-03-20 07:53:50 -04:00
|
|
|
assert.Contains(t, post.GetProps(), model.PostPropsFromWebhook, "missing from_webhook prop")
|
2024-04-17 07:32:32 -04:00
|
|
|
assert.Equal(t, *conditions.Priority, *post.GetPriority().Priority)
|
|
|
|
|
assert.Equal(t, *conditions.RequestedAck, *post.GetPriority().RequestedAck)
|
|
|
|
|
assert.Equal(t, *conditions.PersistentNotifications, *post.GetPriority().PersistentNotifications)
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-12-12 14:15:38 -05:00
|
|
|
|
2023-12-06 14:12:31 -05:00
|
|
|
func TestCreateWebhookPostLinks(t *testing.T) {
|
2025-05-30 07:58:26 -04:00
|
|
|
mainHelper.Parallel(t)
|
2025-11-12 07:00:51 -05:00
|
|
|
th := Setup(t).InitBasic(t)
|
2023-12-06 14:12:31 -05:00
|
|
|
|
|
|
|
|
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableIncomingWebhooks = true })
|
|
|
|
|
|
2025-04-15 03:50:22 -04:00
|
|
|
hook, appErr := th.App.CreateIncomingWebhookForChannel(th.BasicUser.Id, th.BasicChannel, &model.IncomingWebhook{ChannelId: th.BasicChannel.Id})
|
|
|
|
|
require.Nil(t, appErr)
|
|
|
|
|
defer func() {
|
|
|
|
|
appErr := th.App.DeleteIncomingWebhook(hook.Id)
|
|
|
|
|
require.Nil(t, appErr, "Error cleaning up webhook")
|
|
|
|
|
}()
|
2023-12-06 14:12:31 -05:00
|
|
|
|
|
|
|
|
for name, tc := range map[string]struct {
|
|
|
|
|
input string
|
|
|
|
|
expectedOutput string
|
|
|
|
|
}{
|
|
|
|
|
"if statement": {
|
|
|
|
|
input: "`if(status_int < QUERY_UNKNOWN || status_int >= QUERY_STATUS_MAX)`",
|
|
|
|
|
expectedOutput: "`if(status_int < QUERY_UNKNOWN || status_int >= QUERY_STATUS_MAX)`",
|
|
|
|
|
},
|
|
|
|
|
"angle bracket link": {
|
|
|
|
|
input: "<https://mattermost.com|Mattermost>",
|
|
|
|
|
expectedOutput: "[Mattermost](https://mattermost.com)",
|
|
|
|
|
},
|
|
|
|
|
} {
|
|
|
|
|
t.Run(name, func(t *testing.T) {
|
2025-04-15 03:50:22 -04:00
|
|
|
post, appErr := th.App.CreateWebhookPost(th.Context, hook.UserId, th.BasicChannel, tc.input, "", "", "", model.StringInterface{}, "", "", nil)
|
|
|
|
|
require.Nil(t, appErr)
|
2023-12-06 14:12:31 -05:00
|
|
|
require.Equal(t, tc.expectedOutput, post.Message)
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-10-24 19:36:31 -04:00
|
|
|
func TestSplitWebhookPost(t *testing.T) {
|
2025-05-30 07:58:26 -04:00
|
|
|
mainHelper.Parallel(t)
|
2017-10-24 19:36:31 -04:00
|
|
|
type TestCase struct {
|
|
|
|
|
Post *model.Post
|
|
|
|
|
Expected []*model.Post
|
|
|
|
|
}
|
|
|
|
|
|
Relax 4k post message limit (#8478)
* MM-9661: rename POST_MESSAGE_MAX_RUNES to \0_v1
* MM-9661: s/4000/POST_MESSAGE_MAX_RUNES_V1/ in tests
* MM-9661: introduce POST_MESSAGE_MAX_RUNES_V2
* MM-9661: migrate Postgres Posts.Message column to TEXT from VARCHAR(4000)
This is safe to do in a production instance since the underyling type is
not changing. We explicitly don't do this automatically for MySQL, but
also don't need to since the ORM would have already created a TEXT column
for MySQL in that case.
* MM-9661: emit MaxPostSize in client config
This value remains unconfigurable at this time, but exposes the current
limit to the client. The limit remains at 4k in this commit.
* MM-9661: introduce and use SqlPostStore.GetMaxPostSize
Enforce a byte limitation in the database, and use 1/4 of that value as
the rune count limitation (assuming a worst case UTF-8 representation).
* move maxPostSizeCached, lastPostsCache and lastPostTimeCache out of the global context and onto the SqlPostStore
* address feedback from code review:
* ensure sqlstore unit tests are actually being run
* move global caches into SqlPostStore
* leverage sync.Once to address a race condition
* modify upgrade semantics to match new db semantics
gorp's behaviour on creating columns with a maximum length on Postgres
differs from MySQL:
* Postgres
* gorp uses TEXT for string columns without a maximum length
* gorp uses VARCHAR(N) for string columns with a maximum length of N
* MySQL
* gorp uses TEXT for string columns with a maximum length >= 256
* gorp uses VARCHAR(N) for string columns with a maximum length of N
* gorp defaults to a maximum length of 255, implying VARCHAR(255)
So the Message column has been TEXT on MySQL but VARCHAR(4000) on
Postgres. With the new, longer limits of 65535, and without changes to
gorp, the expected behaviour is TEXT on MySQL and VARCHAR(65535) on
Postgres. This commit makes the upgrade semantics match the new database
semantics.
Ideally, we'd revisit the gorp behaviour at a later time.
* allow TestMaxPostSize test cases to actually run in parallel
* default maxPostSizeCached to POST_MESSAGE_MAX_RUNES_V1 in case the once initializer panics
* fix casting error
* MM-9661: skip the schema migration for Postgres
It turns out resizing VARCHAR requires a rewrite in some versions of
Postgres, but migrating VARCHAR to TEXT does not. Given the increasing
complexity, let's defer the migration to the enduser instead.
2018-03-26 17:55:35 -04:00
|
|
|
maxPostSize := 10000
|
|
|
|
|
|
2017-10-24 19:36:31 -04:00
|
|
|
for name, tc := range map[string]TestCase{
|
|
|
|
|
"LongPost": {
|
|
|
|
|
Post: &model.Post{
|
Relax 4k post message limit (#8478)
* MM-9661: rename POST_MESSAGE_MAX_RUNES to \0_v1
* MM-9661: s/4000/POST_MESSAGE_MAX_RUNES_V1/ in tests
* MM-9661: introduce POST_MESSAGE_MAX_RUNES_V2
* MM-9661: migrate Postgres Posts.Message column to TEXT from VARCHAR(4000)
This is safe to do in a production instance since the underyling type is
not changing. We explicitly don't do this automatically for MySQL, but
also don't need to since the ORM would have already created a TEXT column
for MySQL in that case.
* MM-9661: emit MaxPostSize in client config
This value remains unconfigurable at this time, but exposes the current
limit to the client. The limit remains at 4k in this commit.
* MM-9661: introduce and use SqlPostStore.GetMaxPostSize
Enforce a byte limitation in the database, and use 1/4 of that value as
the rune count limitation (assuming a worst case UTF-8 representation).
* move maxPostSizeCached, lastPostsCache and lastPostTimeCache out of the global context and onto the SqlPostStore
* address feedback from code review:
* ensure sqlstore unit tests are actually being run
* move global caches into SqlPostStore
* leverage sync.Once to address a race condition
* modify upgrade semantics to match new db semantics
gorp's behaviour on creating columns with a maximum length on Postgres
differs from MySQL:
* Postgres
* gorp uses TEXT for string columns without a maximum length
* gorp uses VARCHAR(N) for string columns with a maximum length of N
* MySQL
* gorp uses TEXT for string columns with a maximum length >= 256
* gorp uses VARCHAR(N) for string columns with a maximum length of N
* gorp defaults to a maximum length of 255, implying VARCHAR(255)
So the Message column has been TEXT on MySQL but VARCHAR(4000) on
Postgres. With the new, longer limits of 65535, and without changes to
gorp, the expected behaviour is TEXT on MySQL and VARCHAR(65535) on
Postgres. This commit makes the upgrade semantics match the new database
semantics.
Ideally, we'd revisit the gorp behaviour at a later time.
* allow TestMaxPostSize test cases to actually run in parallel
* default maxPostSizeCached to POST_MESSAGE_MAX_RUNES_V1 in case the once initializer panics
* fix casting error
* MM-9661: skip the schema migration for Postgres
It turns out resizing VARCHAR requires a rewrite in some versions of
Postgres, but migrating VARCHAR to TEXT does not. Given the increasing
complexity, let's defer the migration to the enduser instead.
2018-03-26 17:55:35 -04:00
|
|
|
Message: strings.Repeat("本", maxPostSize*3/2),
|
2017-10-24 19:36:31 -04:00
|
|
|
},
|
|
|
|
|
Expected: []*model.Post{
|
|
|
|
|
{
|
Relax 4k post message limit (#8478)
* MM-9661: rename POST_MESSAGE_MAX_RUNES to \0_v1
* MM-9661: s/4000/POST_MESSAGE_MAX_RUNES_V1/ in tests
* MM-9661: introduce POST_MESSAGE_MAX_RUNES_V2
* MM-9661: migrate Postgres Posts.Message column to TEXT from VARCHAR(4000)
This is safe to do in a production instance since the underyling type is
not changing. We explicitly don't do this automatically for MySQL, but
also don't need to since the ORM would have already created a TEXT column
for MySQL in that case.
* MM-9661: emit MaxPostSize in client config
This value remains unconfigurable at this time, but exposes the current
limit to the client. The limit remains at 4k in this commit.
* MM-9661: introduce and use SqlPostStore.GetMaxPostSize
Enforce a byte limitation in the database, and use 1/4 of that value as
the rune count limitation (assuming a worst case UTF-8 representation).
* move maxPostSizeCached, lastPostsCache and lastPostTimeCache out of the global context and onto the SqlPostStore
* address feedback from code review:
* ensure sqlstore unit tests are actually being run
* move global caches into SqlPostStore
* leverage sync.Once to address a race condition
* modify upgrade semantics to match new db semantics
gorp's behaviour on creating columns with a maximum length on Postgres
differs from MySQL:
* Postgres
* gorp uses TEXT for string columns without a maximum length
* gorp uses VARCHAR(N) for string columns with a maximum length of N
* MySQL
* gorp uses TEXT for string columns with a maximum length >= 256
* gorp uses VARCHAR(N) for string columns with a maximum length of N
* gorp defaults to a maximum length of 255, implying VARCHAR(255)
So the Message column has been TEXT on MySQL but VARCHAR(4000) on
Postgres. With the new, longer limits of 65535, and without changes to
gorp, the expected behaviour is TEXT on MySQL and VARCHAR(65535) on
Postgres. This commit makes the upgrade semantics match the new database
semantics.
Ideally, we'd revisit the gorp behaviour at a later time.
* allow TestMaxPostSize test cases to actually run in parallel
* default maxPostSizeCached to POST_MESSAGE_MAX_RUNES_V1 in case the once initializer panics
* fix casting error
* MM-9661: skip the schema migration for Postgres
It turns out resizing VARCHAR requires a rewrite in some versions of
Postgres, but migrating VARCHAR to TEXT does not. Given the increasing
complexity, let's defer the migration to the enduser instead.
2018-03-26 17:55:35 -04:00
|
|
|
Message: strings.Repeat("本", maxPostSize),
|
2017-10-24 19:36:31 -04:00
|
|
|
},
|
|
|
|
|
{
|
Relax 4k post message limit (#8478)
* MM-9661: rename POST_MESSAGE_MAX_RUNES to \0_v1
* MM-9661: s/4000/POST_MESSAGE_MAX_RUNES_V1/ in tests
* MM-9661: introduce POST_MESSAGE_MAX_RUNES_V2
* MM-9661: migrate Postgres Posts.Message column to TEXT from VARCHAR(4000)
This is safe to do in a production instance since the underyling type is
not changing. We explicitly don't do this automatically for MySQL, but
also don't need to since the ORM would have already created a TEXT column
for MySQL in that case.
* MM-9661: emit MaxPostSize in client config
This value remains unconfigurable at this time, but exposes the current
limit to the client. The limit remains at 4k in this commit.
* MM-9661: introduce and use SqlPostStore.GetMaxPostSize
Enforce a byte limitation in the database, and use 1/4 of that value as
the rune count limitation (assuming a worst case UTF-8 representation).
* move maxPostSizeCached, lastPostsCache and lastPostTimeCache out of the global context and onto the SqlPostStore
* address feedback from code review:
* ensure sqlstore unit tests are actually being run
* move global caches into SqlPostStore
* leverage sync.Once to address a race condition
* modify upgrade semantics to match new db semantics
gorp's behaviour on creating columns with a maximum length on Postgres
differs from MySQL:
* Postgres
* gorp uses TEXT for string columns without a maximum length
* gorp uses VARCHAR(N) for string columns with a maximum length of N
* MySQL
* gorp uses TEXT for string columns with a maximum length >= 256
* gorp uses VARCHAR(N) for string columns with a maximum length of N
* gorp defaults to a maximum length of 255, implying VARCHAR(255)
So the Message column has been TEXT on MySQL but VARCHAR(4000) on
Postgres. With the new, longer limits of 65535, and without changes to
gorp, the expected behaviour is TEXT on MySQL and VARCHAR(65535) on
Postgres. This commit makes the upgrade semantics match the new database
semantics.
Ideally, we'd revisit the gorp behaviour at a later time.
* allow TestMaxPostSize test cases to actually run in parallel
* default maxPostSizeCached to POST_MESSAGE_MAX_RUNES_V1 in case the once initializer panics
* fix casting error
* MM-9661: skip the schema migration for Postgres
It turns out resizing VARCHAR requires a rewrite in some versions of
Postgres, but migrating VARCHAR to TEXT does not. Given the increasing
complexity, let's defer the migration to the enduser instead.
2018-03-26 17:55:35 -04:00
|
|
|
Message: strings.Repeat("本", maxPostSize/2),
|
2017-10-24 19:36:31 -04:00
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
"LongPostAndMultipleAttachments": {
|
|
|
|
|
Post: &model.Post{
|
Relax 4k post message limit (#8478)
* MM-9661: rename POST_MESSAGE_MAX_RUNES to \0_v1
* MM-9661: s/4000/POST_MESSAGE_MAX_RUNES_V1/ in tests
* MM-9661: introduce POST_MESSAGE_MAX_RUNES_V2
* MM-9661: migrate Postgres Posts.Message column to TEXT from VARCHAR(4000)
This is safe to do in a production instance since the underyling type is
not changing. We explicitly don't do this automatically for MySQL, but
also don't need to since the ORM would have already created a TEXT column
for MySQL in that case.
* MM-9661: emit MaxPostSize in client config
This value remains unconfigurable at this time, but exposes the current
limit to the client. The limit remains at 4k in this commit.
* MM-9661: introduce and use SqlPostStore.GetMaxPostSize
Enforce a byte limitation in the database, and use 1/4 of that value as
the rune count limitation (assuming a worst case UTF-8 representation).
* move maxPostSizeCached, lastPostsCache and lastPostTimeCache out of the global context and onto the SqlPostStore
* address feedback from code review:
* ensure sqlstore unit tests are actually being run
* move global caches into SqlPostStore
* leverage sync.Once to address a race condition
* modify upgrade semantics to match new db semantics
gorp's behaviour on creating columns with a maximum length on Postgres
differs from MySQL:
* Postgres
* gorp uses TEXT for string columns without a maximum length
* gorp uses VARCHAR(N) for string columns with a maximum length of N
* MySQL
* gorp uses TEXT for string columns with a maximum length >= 256
* gorp uses VARCHAR(N) for string columns with a maximum length of N
* gorp defaults to a maximum length of 255, implying VARCHAR(255)
So the Message column has been TEXT on MySQL but VARCHAR(4000) on
Postgres. With the new, longer limits of 65535, and without changes to
gorp, the expected behaviour is TEXT on MySQL and VARCHAR(65535) on
Postgres. This commit makes the upgrade semantics match the new database
semantics.
Ideally, we'd revisit the gorp behaviour at a later time.
* allow TestMaxPostSize test cases to actually run in parallel
* default maxPostSizeCached to POST_MESSAGE_MAX_RUNES_V1 in case the once initializer panics
* fix casting error
* MM-9661: skip the schema migration for Postgres
It turns out resizing VARCHAR requires a rewrite in some versions of
Postgres, but migrating VARCHAR to TEXT does not. Given the increasing
complexity, let's defer the migration to the enduser instead.
2018-03-26 17:55:35 -04:00
|
|
|
Message: strings.Repeat("本", maxPostSize*3/2),
|
2022-07-05 02:46:50 -04:00
|
|
|
Props: map[string]any{
|
2026-03-10 11:37:21 -04:00
|
|
|
model.PostPropsAttachments: []*model.MessageAttachment{
|
2019-10-28 09:08:08 -04:00
|
|
|
{
|
2017-10-24 19:36:31 -04:00
|
|
|
Text: strings.Repeat("本", 1000),
|
|
|
|
|
},
|
2019-10-28 09:08:08 -04:00
|
|
|
{
|
2017-10-24 19:36:31 -04:00
|
|
|
Text: strings.Repeat("本", 2000),
|
|
|
|
|
},
|
2019-10-28 09:08:08 -04:00
|
|
|
{
|
2021-07-12 14:05:36 -04:00
|
|
|
Text: strings.Repeat("本", model.PostPropsMaxUserRunes-1000),
|
2017-10-24 19:36:31 -04:00
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
Expected: []*model.Post{
|
|
|
|
|
{
|
Relax 4k post message limit (#8478)
* MM-9661: rename POST_MESSAGE_MAX_RUNES to \0_v1
* MM-9661: s/4000/POST_MESSAGE_MAX_RUNES_V1/ in tests
* MM-9661: introduce POST_MESSAGE_MAX_RUNES_V2
* MM-9661: migrate Postgres Posts.Message column to TEXT from VARCHAR(4000)
This is safe to do in a production instance since the underyling type is
not changing. We explicitly don't do this automatically for MySQL, but
also don't need to since the ORM would have already created a TEXT column
for MySQL in that case.
* MM-9661: emit MaxPostSize in client config
This value remains unconfigurable at this time, but exposes the current
limit to the client. The limit remains at 4k in this commit.
* MM-9661: introduce and use SqlPostStore.GetMaxPostSize
Enforce a byte limitation in the database, and use 1/4 of that value as
the rune count limitation (assuming a worst case UTF-8 representation).
* move maxPostSizeCached, lastPostsCache and lastPostTimeCache out of the global context and onto the SqlPostStore
* address feedback from code review:
* ensure sqlstore unit tests are actually being run
* move global caches into SqlPostStore
* leverage sync.Once to address a race condition
* modify upgrade semantics to match new db semantics
gorp's behaviour on creating columns with a maximum length on Postgres
differs from MySQL:
* Postgres
* gorp uses TEXT for string columns without a maximum length
* gorp uses VARCHAR(N) for string columns with a maximum length of N
* MySQL
* gorp uses TEXT for string columns with a maximum length >= 256
* gorp uses VARCHAR(N) for string columns with a maximum length of N
* gorp defaults to a maximum length of 255, implying VARCHAR(255)
So the Message column has been TEXT on MySQL but VARCHAR(4000) on
Postgres. With the new, longer limits of 65535, and without changes to
gorp, the expected behaviour is TEXT on MySQL and VARCHAR(65535) on
Postgres. This commit makes the upgrade semantics match the new database
semantics.
Ideally, we'd revisit the gorp behaviour at a later time.
* allow TestMaxPostSize test cases to actually run in parallel
* default maxPostSizeCached to POST_MESSAGE_MAX_RUNES_V1 in case the once initializer panics
* fix casting error
* MM-9661: skip the schema migration for Postgres
It turns out resizing VARCHAR requires a rewrite in some versions of
Postgres, but migrating VARCHAR to TEXT does not. Given the increasing
complexity, let's defer the migration to the enduser instead.
2018-03-26 17:55:35 -04:00
|
|
|
Message: strings.Repeat("本", maxPostSize),
|
2017-10-24 19:36:31 -04:00
|
|
|
},
|
|
|
|
|
{
|
Relax 4k post message limit (#8478)
* MM-9661: rename POST_MESSAGE_MAX_RUNES to \0_v1
* MM-9661: s/4000/POST_MESSAGE_MAX_RUNES_V1/ in tests
* MM-9661: introduce POST_MESSAGE_MAX_RUNES_V2
* MM-9661: migrate Postgres Posts.Message column to TEXT from VARCHAR(4000)
This is safe to do in a production instance since the underyling type is
not changing. We explicitly don't do this automatically for MySQL, but
also don't need to since the ORM would have already created a TEXT column
for MySQL in that case.
* MM-9661: emit MaxPostSize in client config
This value remains unconfigurable at this time, but exposes the current
limit to the client. The limit remains at 4k in this commit.
* MM-9661: introduce and use SqlPostStore.GetMaxPostSize
Enforce a byte limitation in the database, and use 1/4 of that value as
the rune count limitation (assuming a worst case UTF-8 representation).
* move maxPostSizeCached, lastPostsCache and lastPostTimeCache out of the global context and onto the SqlPostStore
* address feedback from code review:
* ensure sqlstore unit tests are actually being run
* move global caches into SqlPostStore
* leverage sync.Once to address a race condition
* modify upgrade semantics to match new db semantics
gorp's behaviour on creating columns with a maximum length on Postgres
differs from MySQL:
* Postgres
* gorp uses TEXT for string columns without a maximum length
* gorp uses VARCHAR(N) for string columns with a maximum length of N
* MySQL
* gorp uses TEXT for string columns with a maximum length >= 256
* gorp uses VARCHAR(N) for string columns with a maximum length of N
* gorp defaults to a maximum length of 255, implying VARCHAR(255)
So the Message column has been TEXT on MySQL but VARCHAR(4000) on
Postgres. With the new, longer limits of 65535, and without changes to
gorp, the expected behaviour is TEXT on MySQL and VARCHAR(65535) on
Postgres. This commit makes the upgrade semantics match the new database
semantics.
Ideally, we'd revisit the gorp behaviour at a later time.
* allow TestMaxPostSize test cases to actually run in parallel
* default maxPostSizeCached to POST_MESSAGE_MAX_RUNES_V1 in case the once initializer panics
* fix casting error
* MM-9661: skip the schema migration for Postgres
It turns out resizing VARCHAR requires a rewrite in some versions of
Postgres, but migrating VARCHAR to TEXT does not. Given the increasing
complexity, let's defer the migration to the enduser instead.
2018-03-26 17:55:35 -04:00
|
|
|
Message: strings.Repeat("本", maxPostSize/2),
|
2022-07-05 02:46:50 -04:00
|
|
|
Props: map[string]any{
|
2026-03-10 11:37:21 -04:00
|
|
|
model.PostPropsAttachments: []*model.MessageAttachment{
|
2019-10-28 09:08:08 -04:00
|
|
|
{
|
2017-10-24 19:36:31 -04:00
|
|
|
Text: strings.Repeat("本", 1000),
|
|
|
|
|
},
|
2019-10-28 09:08:08 -04:00
|
|
|
{
|
2017-10-24 19:36:31 -04:00
|
|
|
Text: strings.Repeat("本", 2000),
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
{
|
2022-07-05 02:46:50 -04:00
|
|
|
Props: map[string]any{
|
2026-03-10 11:37:21 -04:00
|
|
|
model.PostPropsAttachments: []*model.MessageAttachment{
|
2019-10-28 09:08:08 -04:00
|
|
|
{
|
2021-07-12 14:05:36 -04:00
|
|
|
Text: strings.Repeat("本", model.PostPropsMaxUserRunes-1000),
|
2017-10-24 19:36:31 -04:00
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
"UnsplittableProps": {
|
|
|
|
|
Post: &model.Post{
|
|
|
|
|
Message: "foo",
|
2022-07-05 02:46:50 -04:00
|
|
|
Props: map[string]any{
|
2021-07-12 14:05:36 -04:00
|
|
|
"foo": strings.Repeat("x", model.PostPropsMaxUserRunes*2),
|
2017-10-24 19:36:31 -04:00
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
} {
|
|
|
|
|
t.Run(name, func(t *testing.T) {
|
2024-12-12 14:15:38 -05:00
|
|
|
splits, err := splitWebhookPost(tc.Post, maxPostSize)
|
2017-10-24 19:36:31 -04:00
|
|
|
if tc.Expected == nil {
|
|
|
|
|
require.NotNil(t, err)
|
|
|
|
|
} else {
|
|
|
|
|
require.Nil(t, err)
|
|
|
|
|
}
|
|
|
|
|
assert.Equal(t, len(tc.Expected), len(splits))
|
|
|
|
|
for i, split := range splits {
|
|
|
|
|
if i < len(tc.Expected) {
|
|
|
|
|
assert.Equal(t, tc.Expected[i].Message, split.Message)
|
2025-03-20 07:53:50 -04:00
|
|
|
assert.Equal(t, tc.Expected[i].GetProp(model.PostPropsAttachments), split.GetProp(model.PostPropsAttachments))
|
2017-10-24 19:36:31 -04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
}
|
2018-07-25 08:31:41 -04:00
|
|
|
|
2020-05-12 09:58:19 -04:00
|
|
|
func makePost(message int, attachments []int) *model.Post {
|
|
|
|
|
var props model.StringInterface
|
|
|
|
|
if len(attachments) > 0 {
|
2026-03-10 11:37:21 -04:00
|
|
|
sa := make([]*model.MessageAttachment, 0, len(attachments))
|
2020-05-12 09:58:19 -04:00
|
|
|
for _, a := range attachments {
|
2026-03-10 11:37:21 -04:00
|
|
|
attach := &model.MessageAttachment{
|
2020-05-12 09:58:19 -04:00
|
|
|
Text: strings.Repeat("那", a),
|
|
|
|
|
}
|
|
|
|
|
sa = append(sa, attach)
|
|
|
|
|
}
|
2025-03-20 07:53:50 -04:00
|
|
|
props = map[string]any{model.PostPropsAttachments: sa}
|
2020-05-12 09:58:19 -04:00
|
|
|
}
|
|
|
|
|
post := &model.Post{
|
|
|
|
|
Message: strings.Repeat("那", message),
|
|
|
|
|
Props: props,
|
|
|
|
|
}
|
|
|
|
|
return post
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestSplitWebhookPostAttachments(t *testing.T) {
|
2025-05-30 07:58:26 -04:00
|
|
|
mainHelper.Parallel(t)
|
2020-05-12 09:58:19 -04:00
|
|
|
maxPostSize := 10000
|
|
|
|
|
testCases := []struct {
|
|
|
|
|
name string
|
|
|
|
|
post *model.Post
|
|
|
|
|
expected []*model.Post
|
|
|
|
|
}{
|
|
|
|
|
{
|
|
|
|
|
// makePost(messageLength, []int{attachmentLength, ...})
|
|
|
|
|
name: "no split",
|
|
|
|
|
post: makePost(10, []int{100, 150, 200}),
|
|
|
|
|
expected: []*model.Post{makePost(10, []int{100, 150, 200})},
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: "split into 2",
|
2021-07-12 14:05:36 -04:00
|
|
|
post: makePost(maxPostSize-1, []int{model.PostPropsMaxUserRunes * 3 / 4, model.PostPropsMaxUserRunes * 1 / 4}),
|
2020-05-12 09:58:19 -04:00
|
|
|
expected: []*model.Post{
|
2021-07-12 14:05:36 -04:00
|
|
|
makePost(maxPostSize-1, []int{model.PostPropsMaxUserRunes * 3 / 4}),
|
|
|
|
|
makePost(0, []int{model.PostPropsMaxUserRunes * 1 / 4}),
|
2020-05-12 09:58:19 -04:00
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: "split into 3",
|
2021-07-12 14:05:36 -04:00
|
|
|
post: makePost(maxPostSize*3/2, []int{1000, 2000, model.PostPropsMaxUserRunes - 1000}),
|
2020-05-12 09:58:19 -04:00
|
|
|
expected: []*model.Post{
|
|
|
|
|
makePost(maxPostSize, nil),
|
|
|
|
|
makePost(maxPostSize/2, []int{1000, 2000}),
|
2021-07-12 14:05:36 -04:00
|
|
|
makePost(0, []int{model.PostPropsMaxUserRunes - 1000}),
|
2020-05-12 09:58:19 -04:00
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: "MM-24644 split into 3",
|
2021-07-12 14:05:36 -04:00
|
|
|
post: makePost(maxPostSize*3/2, []int{5150, 2000, model.PostPropsMaxUserRunes - 1000}),
|
2020-05-12 09:58:19 -04:00
|
|
|
expected: []*model.Post{
|
|
|
|
|
makePost(maxPostSize, nil),
|
2021-09-13 08:23:50 -04:00
|
|
|
makePost(maxPostSize/2, []int{5150, 2000}),
|
2021-07-12 14:05:36 -04:00
|
|
|
makePost(0, []int{model.PostPropsMaxUserRunes - 1000}),
|
2020-05-12 09:58:19 -04:00
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for _, tc := range testCases {
|
|
|
|
|
t.Run(tc.name, func(t *testing.T) {
|
2024-12-12 14:15:38 -05:00
|
|
|
splits, err := splitWebhookPost(tc.post, maxPostSize)
|
2020-05-12 09:58:19 -04:00
|
|
|
if tc.expected == nil {
|
|
|
|
|
require.NotNil(t, err)
|
|
|
|
|
} else {
|
|
|
|
|
require.Nil(t, err)
|
|
|
|
|
}
|
|
|
|
|
assert.Equal(t, len(tc.expected), len(splits))
|
|
|
|
|
for i, split := range splits {
|
|
|
|
|
if i < len(tc.expected) {
|
|
|
|
|
assert.Equal(t, tc.expected[i].Message, split.Message, i)
|
2025-03-20 07:53:50 -04:00
|
|
|
assert.Equal(t, tc.expected[i].GetProp(model.PostPropsAttachments), split.GetProp(model.PostPropsAttachments), i)
|
2020-05-12 09:58:19 -04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-07-25 08:31:41 -04:00
|
|
|
func TestCreateOutGoingWebhookWithUsernameAndIconURL(t *testing.T) {
|
2025-05-30 07:58:26 -04:00
|
|
|
mainHelper.Parallel(t)
|
2025-11-12 07:00:51 -05:00
|
|
|
th := Setup(t).InitBasic(t)
|
2018-07-25 08:31:41 -04:00
|
|
|
|
|
|
|
|
outgoingWebhook := model.OutgoingWebhook{
|
|
|
|
|
ChannelId: th.BasicChannel.Id,
|
|
|
|
|
TeamId: th.BasicChannel.TeamId,
|
|
|
|
|
CallbackURLs: []string{"http://nowhere.com"},
|
|
|
|
|
Username: "some-user-name",
|
|
|
|
|
IconURL: "http://some-icon/",
|
|
|
|
|
DisplayName: "some-display-name",
|
|
|
|
|
Description: "some-description",
|
|
|
|
|
CreatorId: th.BasicUser.Id,
|
|
|
|
|
}
|
|
|
|
|
|
2019-01-31 08:12:01 -05:00
|
|
|
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableOutgoingWebhooks = true })
|
2018-07-25 08:31:41 -04:00
|
|
|
|
|
|
|
|
createdHook, err := th.App.CreateOutgoingWebhook(&outgoingWebhook)
|
2019-09-06 06:52:51 -04:00
|
|
|
require.Nil(t, err)
|
2018-07-25 08:31:41 -04:00
|
|
|
|
|
|
|
|
assert.NotNil(t, createdHook, "should not be null")
|
|
|
|
|
|
|
|
|
|
assert.Equal(t, createdHook.ChannelId, outgoingWebhook.ChannelId)
|
|
|
|
|
assert.Equal(t, createdHook.TeamId, outgoingWebhook.TeamId)
|
|
|
|
|
assert.Equal(t, createdHook.CallbackURLs, outgoingWebhook.CallbackURLs)
|
|
|
|
|
assert.Equal(t, createdHook.Username, outgoingWebhook.Username)
|
|
|
|
|
assert.Equal(t, createdHook.IconURL, outgoingWebhook.IconURL)
|
|
|
|
|
assert.Equal(t, createdHook.DisplayName, outgoingWebhook.DisplayName)
|
|
|
|
|
assert.Equal(t, createdHook.Description, outgoingWebhook.Description)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestTriggerOutGoingWebhookWithUsernameAndIconURL(t *testing.T) {
|
2025-05-30 07:58:26 -04:00
|
|
|
mainHelper.Parallel(t)
|
2018-07-25 08:31:41 -04:00
|
|
|
getPayload := func(hook *model.OutgoingWebhook, th *TestHelper, channel *model.Channel) *model.OutgoingWebhookPayload {
|
|
|
|
|
return &model.OutgoingWebhookPayload{
|
|
|
|
|
Token: hook.Token,
|
|
|
|
|
TeamId: hook.TeamId,
|
|
|
|
|
TeamDomain: th.BasicTeam.Name,
|
|
|
|
|
ChannelId: channel.Id,
|
|
|
|
|
ChannelName: channel.Name,
|
|
|
|
|
Timestamp: th.BasicPost.CreateAt,
|
|
|
|
|
UserId: th.BasicPost.UserId,
|
|
|
|
|
UserName: th.BasicUser.Username,
|
|
|
|
|
PostId: th.BasicPost.Id,
|
|
|
|
|
Text: th.BasicPost.Message,
|
|
|
|
|
TriggerWord: "Abracadabra",
|
|
|
|
|
FileIds: strings.Join(th.BasicPost.FileIds, ","),
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-02-28 04:31:00 -05:00
|
|
|
waitUntilWebhookResponseIsCreatedAsPost := func(channel *model.Channel, th *TestHelper, createdPost chan *model.Post) {
|
2018-07-25 08:31:41 -04:00
|
|
|
go func() {
|
2025-07-18 06:54:51 -04:00
|
|
|
for range 5 {
|
2018-07-25 08:31:41 -04:00
|
|
|
time.Sleep(time.Second)
|
2025-09-18 10:14:24 -04:00
|
|
|
posts, _ := th.App.GetPosts(th.Context, channel.Id, 0, 5)
|
2018-07-25 08:31:41 -04:00
|
|
|
if len(posts.Posts) > 0 {
|
|
|
|
|
for _, post := range posts.Posts {
|
|
|
|
|
createdPost <- post
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type TestCaseOutgoing struct {
|
|
|
|
|
EnablePostUsernameOverride bool
|
|
|
|
|
EnablePostIconOverride bool
|
|
|
|
|
ExpectedUsername string
|
2021-02-05 05:22:27 -05:00
|
|
|
ExpectedIconURL string
|
2018-07-25 08:31:41 -04:00
|
|
|
WebhookResponse *model.OutgoingWebhookResponse
|
|
|
|
|
}
|
|
|
|
|
|
2021-08-16 13:46:44 -04:00
|
|
|
createOutgoingWebhook := func(channel *model.Channel, testCallBackURL string, th *TestHelper) (*model.OutgoingWebhook, *model.AppError) {
|
2018-07-25 08:31:41 -04:00
|
|
|
outgoingWebhook := model.OutgoingWebhook{
|
|
|
|
|
ChannelId: channel.Id,
|
|
|
|
|
TeamId: channel.TeamId,
|
2021-08-16 13:46:44 -04:00
|
|
|
CallbackURLs: []string{testCallBackURL},
|
2018-07-25 08:31:41 -04:00
|
|
|
Username: "some-user-name",
|
|
|
|
|
IconURL: "http://some-icon/",
|
|
|
|
|
DisplayName: "some-display-name",
|
|
|
|
|
Description: "some-description",
|
|
|
|
|
CreatorId: th.BasicUser.Id,
|
|
|
|
|
TriggerWords: []string{"Abracadabra"},
|
|
|
|
|
ContentType: "application/json",
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return th.App.CreateOutgoingWebhook(&outgoingWebhook)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
getTestCases := func() map[string]TestCaseOutgoing {
|
|
|
|
|
webHookResponse := "sample response text from test server"
|
|
|
|
|
testCasesOutgoing := map[string]TestCaseOutgoing{
|
|
|
|
|
"Should override username and Icon": {
|
|
|
|
|
EnablePostUsernameOverride: true,
|
|
|
|
|
EnablePostIconOverride: true,
|
|
|
|
|
ExpectedUsername: "some-user-name",
|
2021-02-05 05:22:27 -05:00
|
|
|
ExpectedIconURL: "http://some-icon/",
|
2018-07-25 08:31:41 -04:00
|
|
|
},
|
|
|
|
|
"Should not override username and Icon": {
|
|
|
|
|
EnablePostUsernameOverride: false,
|
|
|
|
|
EnablePostIconOverride: false,
|
|
|
|
|
},
|
|
|
|
|
"Should not override username and Icon if the webhook response already has it": {
|
|
|
|
|
EnablePostUsernameOverride: true,
|
|
|
|
|
EnablePostIconOverride: true,
|
|
|
|
|
ExpectedUsername: "webhookuser",
|
2022-02-28 04:31:00 -05:00
|
|
|
ExpectedIconURL: "http://webhook/icon",
|
|
|
|
|
WebhookResponse: &model.OutgoingWebhookResponse{Text: &webHookResponse, Username: "webhookuser", IconURL: "http://webhook/icon"},
|
2018-07-25 08:31:41 -04:00
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
return testCasesOutgoing
|
|
|
|
|
}
|
|
|
|
|
|
2025-11-12 07:00:51 -05:00
|
|
|
th := Setup(t).InitBasic(t)
|
2018-07-25 08:31:41 -04:00
|
|
|
|
|
|
|
|
th.App.UpdateConfig(func(cfg *model.Config) {
|
2019-07-17 10:04:09 -04:00
|
|
|
*cfg.ServiceSettings.AllowedUntrustedInternalConnections = "localhost,127.0.0.1"
|
2018-07-25 08:31:41 -04:00
|
|
|
})
|
|
|
|
|
createdPost := make(chan *model.Post)
|
|
|
|
|
|
|
|
|
|
for name, testCase := range getTestCases() {
|
|
|
|
|
t.Run(name, func(t *testing.T) {
|
|
|
|
|
th.App.UpdateConfig(func(cfg *model.Config) {
|
2019-01-31 08:12:01 -05:00
|
|
|
*cfg.ServiceSettings.EnableOutgoingWebhooks = true
|
|
|
|
|
*cfg.ServiceSettings.EnablePostUsernameOverride = testCase.EnablePostUsernameOverride
|
|
|
|
|
*cfg.ServiceSettings.EnablePostIconOverride = testCase.EnablePostIconOverride
|
2018-07-25 08:31:41 -04:00
|
|
|
})
|
|
|
|
|
|
|
|
|
|
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
|
|
|
if testCase.WebhookResponse != nil {
|
2021-09-01 08:43:12 -04:00
|
|
|
js, jsonErr := json.Marshal(testCase.WebhookResponse)
|
|
|
|
|
require.NoError(t, jsonErr)
|
2025-04-15 03:50:22 -04:00
|
|
|
_, err := w.Write(js)
|
|
|
|
|
require.NoError(t, err)
|
2018-07-25 08:31:41 -04:00
|
|
|
} else {
|
2025-04-15 03:50:22 -04:00
|
|
|
_, err := w.Write([]byte(`{"text": "sample response text from test server"}`))
|
|
|
|
|
require.NoError(t, err)
|
2018-07-25 08:31:41 -04:00
|
|
|
}
|
|
|
|
|
}))
|
|
|
|
|
defer ts.Close()
|
|
|
|
|
|
2025-11-12 07:00:51 -05:00
|
|
|
channel := th.CreateChannel(t, th.BasicTeam)
|
2018-07-25 08:31:41 -04:00
|
|
|
hook, _ := createOutgoingWebhook(channel, ts.URL, th)
|
|
|
|
|
payload := getPayload(hook, th, channel)
|
|
|
|
|
|
2021-05-11 06:00:44 -04:00
|
|
|
th.App.TriggerWebhook(th.Context, payload, hook, th.BasicPost, channel)
|
2018-07-25 08:31:41 -04:00
|
|
|
|
2022-02-28 04:31:00 -05:00
|
|
|
waitUntilWebhookResponseIsCreatedAsPost(channel, th, createdPost)
|
2018-07-25 08:31:41 -04:00
|
|
|
|
|
|
|
|
select {
|
|
|
|
|
case webhookPost := <-createdPost:
|
|
|
|
|
assert.Equal(t, webhookPost.Message, "sample response text from test server")
|
2025-03-20 07:53:50 -04:00
|
|
|
assert.Equal(t, webhookPost.GetProp(model.PostPropsFromWebhook), "true")
|
2021-02-05 05:22:27 -05:00
|
|
|
if testCase.ExpectedIconURL != "" {
|
2025-03-20 07:53:50 -04:00
|
|
|
assert.Equal(t, webhookPost.GetProp(model.PostPropsOverrideIconURL), testCase.ExpectedIconURL)
|
2018-07-25 08:31:41 -04:00
|
|
|
} else {
|
2025-03-20 07:53:50 -04:00
|
|
|
assert.Nil(t, webhookPost.GetProp(model.PostPropsOverrideIconURL))
|
2018-07-25 08:31:41 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if testCase.ExpectedUsername != "" {
|
2025-03-20 07:53:50 -04:00
|
|
|
assert.Equal(t, webhookPost.GetProp(model.PostPropsOverrideUsername), testCase.ExpectedUsername)
|
2018-07-25 08:31:41 -04:00
|
|
|
} else {
|
2025-03-20 07:53:50 -04:00
|
|
|
assert.Nil(t, webhookPost.GetProp(model.PostPropsOverrideUsername))
|
2018-07-25 08:31:41 -04:00
|
|
|
}
|
|
|
|
|
case <-time.After(5 * time.Second):
|
2020-02-13 11:53:23 -05:00
|
|
|
require.Fail(t, "Timeout, webhook response not created as post")
|
2018-07-25 08:31:41 -04:00
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-01-09 17:07:08 -05:00
|
|
|
|
2024-04-08 05:25:03 -04:00
|
|
|
func TestTriggerOutGoingWebhookWithMultipleURLs(t *testing.T) {
|
2025-05-30 07:58:26 -04:00
|
|
|
mainHelper.Parallel(t)
|
2024-04-08 05:25:03 -04:00
|
|
|
getPayload := func(hook *model.OutgoingWebhook, th *TestHelper, channel *model.Channel) *model.OutgoingWebhookPayload {
|
|
|
|
|
return &model.OutgoingWebhookPayload{
|
|
|
|
|
Token: hook.Token,
|
|
|
|
|
TeamId: hook.TeamId,
|
|
|
|
|
TeamDomain: th.BasicTeam.Name,
|
|
|
|
|
ChannelId: channel.Id,
|
|
|
|
|
ChannelName: channel.Name,
|
|
|
|
|
Timestamp: th.BasicPost.CreateAt,
|
|
|
|
|
UserId: th.BasicPost.UserId,
|
|
|
|
|
UserName: th.BasicUser.Username,
|
|
|
|
|
PostId: th.BasicPost.Id,
|
|
|
|
|
Text: th.BasicPost.Message,
|
|
|
|
|
TriggerWord: "Abracadabra",
|
|
|
|
|
FileIds: strings.Join(th.BasicPost.FileIds, ","),
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
createOutgoingWebhook := func(channel *model.Channel, testCallBackURLs []string, th *TestHelper) (*model.OutgoingWebhook, *model.AppError) {
|
|
|
|
|
outgoingWebhook := model.OutgoingWebhook{
|
|
|
|
|
ChannelId: channel.Id,
|
|
|
|
|
TeamId: channel.TeamId,
|
|
|
|
|
CallbackURLs: testCallBackURLs,
|
|
|
|
|
Username: "some-user-name",
|
|
|
|
|
IconURL: "http://some-website.com/assets/some-icon.png",
|
|
|
|
|
DisplayName: "some-display-name",
|
|
|
|
|
Description: "some-description",
|
|
|
|
|
CreatorId: th.BasicUser.Id,
|
|
|
|
|
TriggerWords: []string{"Abracadabra"},
|
|
|
|
|
ContentType: "application/json",
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return th.App.CreateOutgoingWebhook(&outgoingWebhook)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
chanTs1 := make(chan string, 1)
|
|
|
|
|
ts1 := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
|
|
|
chanTs1 <- "webhook received!"
|
|
|
|
|
}))
|
|
|
|
|
defer ts1.Close()
|
|
|
|
|
|
|
|
|
|
chanTs2 := make(chan string, 1)
|
|
|
|
|
ts2 := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
|
|
|
chanTs2 <- "webhook received!"
|
|
|
|
|
}))
|
|
|
|
|
defer ts2.Close()
|
|
|
|
|
|
2025-11-12 07:00:51 -05:00
|
|
|
th := Setup(t).InitBasic(t)
|
2024-04-08 05:25:03 -04:00
|
|
|
|
|
|
|
|
th.App.UpdateConfig(func(cfg *model.Config) {
|
|
|
|
|
*cfg.ServiceSettings.AllowedUntrustedInternalConnections = "localhost,127.0.0.1"
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
for name, testCase := range map[string]struct {
|
|
|
|
|
CallBackURLs []string
|
|
|
|
|
}{
|
|
|
|
|
"One WebhookURL": {
|
|
|
|
|
CallBackURLs: []string{ts1.URL},
|
|
|
|
|
},
|
|
|
|
|
"Two WebhookURLs": {
|
|
|
|
|
CallBackURLs: []string{ts1.URL, ts2.URL},
|
|
|
|
|
},
|
|
|
|
|
} {
|
|
|
|
|
t.Run(name, func(t *testing.T) {
|
|
|
|
|
th.App.UpdateConfig(func(cfg *model.Config) {
|
|
|
|
|
*cfg.ServiceSettings.EnableOutgoingWebhooks = true
|
|
|
|
|
})
|
2025-11-12 07:00:51 -05:00
|
|
|
channel := th.CreateChannel(t, th.BasicTeam)
|
2024-04-08 05:25:03 -04:00
|
|
|
hook, _ := createOutgoingWebhook(channel, testCase.CallBackURLs, th)
|
|
|
|
|
payload := getPayload(hook, th, channel)
|
|
|
|
|
|
|
|
|
|
th.App.TriggerWebhook(th.Context, payload, hook, th.BasicPost, channel)
|
|
|
|
|
|
|
|
|
|
select {
|
|
|
|
|
case webhookResponse := <-chanTs1:
|
|
|
|
|
require.Equal(t, "webhook received!", webhookResponse)
|
|
|
|
|
|
|
|
|
|
case <-time.After(5 * time.Second):
|
|
|
|
|
require.Fail(t, "Timeout, webhook URL 1 response not received")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if len(testCase.CallBackURLs) > 1 {
|
|
|
|
|
select {
|
|
|
|
|
case webhookResponse := <-chanTs2:
|
|
|
|
|
require.Equal(t, "webhook received!", webhookResponse)
|
|
|
|
|
|
|
|
|
|
case <-time.After(5 * time.Second):
|
|
|
|
|
require.Fail(t, "Timeout, webhook URL 2 response not received")
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-01-09 17:07:08 -05:00
|
|
|
type InfiniteReader struct {
|
|
|
|
|
Prefix string
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (r InfiniteReader) Read(p []byte) (n int, err error) {
|
|
|
|
|
for i := range p {
|
|
|
|
|
p[i] = 'a'
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return len(p), nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestDoOutgoingWebhookRequest(t *testing.T) {
|
2025-05-30 07:58:26 -04:00
|
|
|
mainHelper.Parallel(t)
|
2020-07-13 13:34:05 -04:00
|
|
|
th := Setup(t)
|
2019-01-09 17:07:08 -05:00
|
|
|
|
|
|
|
|
th.App.UpdateConfig(func(cfg *model.Config) {
|
2024-08-05 23:45:00 -04:00
|
|
|
cfg.ServiceSettings.AllowedUntrustedInternalConnections = model.NewPointer("127.0.0.1")
|
2019-01-31 08:12:01 -05:00
|
|
|
*cfg.ServiceSettings.EnableOutgoingWebhooks = true
|
2019-01-09 17:07:08 -05:00
|
|
|
})
|
|
|
|
|
|
|
|
|
|
t.Run("with a valid response", func(t *testing.T) {
|
|
|
|
|
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
2025-04-15 03:50:22 -04:00
|
|
|
_, err := io.Copy(w, strings.NewReader(`{"text": "Hello, World!"}`))
|
|
|
|
|
require.NoError(t, err)
|
2019-01-09 17:07:08 -05:00
|
|
|
}))
|
|
|
|
|
defer server.Close()
|
|
|
|
|
|
2024-02-09 14:49:49 -05:00
|
|
|
resp, err := th.App.doOutgoingWebhookRequest(server.URL, strings.NewReader(""), "application/json", nil)
|
2021-02-16 06:00:01 -05:00
|
|
|
require.NoError(t, err)
|
2019-01-09 17:07:08 -05:00
|
|
|
|
2023-12-18 10:07:00 -05:00
|
|
|
require.NotNil(t, resp)
|
2019-01-09 17:07:08 -05:00
|
|
|
assert.NotNil(t, resp.Text)
|
|
|
|
|
assert.Equal(t, "Hello, World!", *resp.Text)
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
t.Run("with an invalid response", func(t *testing.T) {
|
|
|
|
|
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
2025-04-15 03:50:22 -04:00
|
|
|
_, err := io.Copy(w, strings.NewReader("aaaaaaaa"))
|
|
|
|
|
require.NoError(t, err)
|
2019-01-09 17:07:08 -05:00
|
|
|
}))
|
|
|
|
|
defer server.Close()
|
|
|
|
|
|
2024-02-09 14:49:49 -05:00
|
|
|
_, err := th.App.doOutgoingWebhookRequest(server.URL, strings.NewReader(""), "application/json", nil)
|
2021-02-16 06:00:01 -05:00
|
|
|
require.Error(t, err)
|
2021-09-01 08:43:12 -04:00
|
|
|
require.Equal(t, "api.unmarshal_error", err.(*model.AppError).Id)
|
2019-01-09 17:07:08 -05:00
|
|
|
})
|
|
|
|
|
|
|
|
|
|
t.Run("with a large, valid response", func(t *testing.T) {
|
|
|
|
|
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
2025-04-15 03:50:22 -04:00
|
|
|
// Don't check the error here as the client may disconnect after hitting
|
|
|
|
|
// the response size limit, causing a broken pipe error that we can't avoid
|
|
|
|
|
_, _ = io.Copy(w, io.MultiReader(strings.NewReader(`{"text": "`), InfiniteReader{}, strings.NewReader(`"}`)))
|
2019-01-09 17:07:08 -05:00
|
|
|
}))
|
|
|
|
|
defer server.Close()
|
|
|
|
|
|
2024-02-09 14:49:49 -05:00
|
|
|
_, err := th.App.doOutgoingWebhookRequest(server.URL, strings.NewReader(""), "application/json", nil)
|
2021-02-16 06:00:01 -05:00
|
|
|
require.Error(t, err)
|
2021-09-01 08:43:12 -04:00
|
|
|
require.Equal(t, "api.unmarshal_error", err.(*model.AppError).Id)
|
2019-01-09 17:07:08 -05:00
|
|
|
})
|
|
|
|
|
|
|
|
|
|
t.Run("with a large, invalid response", func(t *testing.T) {
|
|
|
|
|
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
2025-04-15 03:50:22 -04:00
|
|
|
// Don't check the error here as the client may disconnect after hitting
|
|
|
|
|
// the response size limit, causing a broken pipe error that we can't avoid
|
|
|
|
|
_, _ = io.Copy(w, InfiniteReader{})
|
2019-01-09 17:07:08 -05:00
|
|
|
}))
|
|
|
|
|
defer server.Close()
|
|
|
|
|
|
2024-02-09 14:49:49 -05:00
|
|
|
_, err := th.App.doOutgoingWebhookRequest(server.URL, strings.NewReader(""), "application/json", nil)
|
2021-02-16 06:00:01 -05:00
|
|
|
require.Error(t, err)
|
2021-09-01 08:43:12 -04:00
|
|
|
require.Equal(t, "api.unmarshal_error", err.(*model.AppError).Id)
|
2019-01-09 17:07:08 -05:00
|
|
|
})
|
|
|
|
|
|
|
|
|
|
t.Run("with a slow response", func(t *testing.T) {
|
2022-07-05 02:46:50 -04:00
|
|
|
releaseHandler := make(chan any)
|
2019-01-09 17:07:08 -05:00
|
|
|
|
|
|
|
|
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
2019-07-31 13:25:17 -04:00
|
|
|
// Don't actually handle the response, allowing the app to timeout.
|
|
|
|
|
<-releaseHandler
|
2019-01-09 17:07:08 -05:00
|
|
|
}))
|
|
|
|
|
defer server.Close()
|
2019-07-31 13:25:17 -04:00
|
|
|
defer close(releaseHandler)
|
2019-01-09 17:07:08 -05:00
|
|
|
|
2023-12-18 10:07:00 -05:00
|
|
|
th.App.UpdateConfig(func(cfg *model.Config) {
|
2024-08-05 23:45:00 -04:00
|
|
|
cfg.ServiceSettings.OutgoingIntegrationRequestsTimeout = model.NewPointer(int64(1))
|
2023-12-18 10:07:00 -05:00
|
|
|
})
|
2019-01-09 17:07:08 -05:00
|
|
|
|
2024-02-09 14:49:49 -05:00
|
|
|
_, err := th.App.doOutgoingWebhookRequest(server.URL, strings.NewReader(""), "application/json", nil)
|
2021-02-16 06:00:01 -05:00
|
|
|
require.Error(t, err)
|
2019-01-09 17:07:08 -05:00
|
|
|
require.IsType(t, &url.Error{}, err)
|
|
|
|
|
})
|
2020-07-09 12:25:23 -04:00
|
|
|
|
2023-12-18 10:07:00 -05:00
|
|
|
t.Run("with a slow response, long timeout configured", func(t *testing.T) {
|
|
|
|
|
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
|
|
|
time.Sleep(1 * time.Second)
|
|
|
|
|
|
2025-04-15 03:50:22 -04:00
|
|
|
_, err := io.Copy(w, strings.NewReader(`{"text": "Hello, World!"}`))
|
|
|
|
|
require.NoError(t, err)
|
2023-12-18 10:07:00 -05:00
|
|
|
}))
|
|
|
|
|
defer server.Close()
|
|
|
|
|
|
|
|
|
|
th.App.UpdateConfig(func(cfg *model.Config) {
|
2024-08-05 23:45:00 -04:00
|
|
|
cfg.ServiceSettings.OutgoingIntegrationRequestsTimeout = model.NewPointer(int64(2))
|
2023-12-18 10:07:00 -05:00
|
|
|
})
|
|
|
|
|
|
2024-02-09 14:49:49 -05:00
|
|
|
resp, err := th.App.doOutgoingWebhookRequest(server.URL, strings.NewReader(""), "application/json", nil)
|
2023-12-18 10:07:00 -05:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
require.NotNil(t, resp)
|
|
|
|
|
assert.NotNil(t, resp.Text)
|
|
|
|
|
assert.Equal(t, "Hello, World!", *resp.Text)
|
|
|
|
|
})
|
|
|
|
|
|
2020-07-09 12:25:23 -04:00
|
|
|
t.Run("without response", func(t *testing.T) {
|
|
|
|
|
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
|
|
|
}))
|
|
|
|
|
defer server.Close()
|
|
|
|
|
|
2024-02-09 14:49:49 -05:00
|
|
|
resp, err := th.App.doOutgoingWebhookRequest(server.URL, strings.NewReader(""), "application/json", nil)
|
2021-02-16 06:00:01 -05:00
|
|
|
require.NoError(t, err)
|
2020-07-09 12:25:23 -04:00
|
|
|
require.Nil(t, resp)
|
|
|
|
|
})
|
2024-02-09 14:49:49 -05:00
|
|
|
|
|
|
|
|
t.Run("with auth token", func(t *testing.T) {
|
|
|
|
|
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
2025-04-15 03:50:22 -04:00
|
|
|
_, err := io.Copy(w, strings.NewReader(fmt.Sprintf(`{"text":"%s"}`, r.Header.Get("Authorization"))))
|
|
|
|
|
require.NoError(t, err)
|
2024-02-09 14:49:49 -05:00
|
|
|
}))
|
|
|
|
|
defer server.Close()
|
|
|
|
|
|
|
|
|
|
resp, err := th.App.doOutgoingWebhookRequest(server.URL, strings.NewReader(""), "application/json", &model.OutgoingOAuthConnectionToken{
|
|
|
|
|
AccessToken: "test",
|
|
|
|
|
TokenType: "Bearer",
|
|
|
|
|
})
|
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
require.Equal(t, `Bearer test`, *resp.Text)
|
|
|
|
|
})
|
2019-01-09 17:07:08 -05:00
|
|
|
}
|