[release-10.11] MM-69010: Validate incoming webhook user membership (#36917)
Automatic Merge
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
beaa59db54
Коммит
f6d3a7827e
@@ -22,6 +22,37 @@ import (
|
||||
"github.com/mattermost/mattermost/server/v8/channels/testlib"
|
||||
)
|
||||
|
||||
func TestHandleIncomingWebhookDirectMessage(t *testing.T) {
|
||||
mainHelper.Parallel(t)
|
||||
th := Setup(t).InitBasic()
|
||||
defer th.TearDown()
|
||||
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableIncomingWebhooks = true })
|
||||
|
||||
hook, appErr := th.App.CreateIncomingWebhookForChannel(th.BasicUser.Id, th.BasicChannel, &model.IncomingWebhook{ChannelId: th.BasicChannel.Id, ChannelLocked: false})
|
||||
require.Nil(t, appErr)
|
||||
defer func() {
|
||||
require.Nil(t, th.App.DeleteIncomingWebhook(hook.Id))
|
||||
}()
|
||||
|
||||
t.Run("rejects DM to a user the owner shares no team with", func(t *testing.T) {
|
||||
stranger := th.CreateUser()
|
||||
err := th.App.HandleIncomingWebhook(th.Context, hook.Id, &model.IncomingWebhookRequest{
|
||||
Text: "out of team dm",
|
||||
ChannelName: "@" + stranger.Username,
|
||||
})
|
||||
require.NotNil(t, err)
|
||||
assert.Equal(t, http.StatusForbidden, err.StatusCode)
|
||||
})
|
||||
|
||||
t.Run("allows DM to a user the owner shares a team with", func(t *testing.T) {
|
||||
err := th.App.HandleIncomingWebhook(th.Context, hook.Id, &model.IncomingWebhookRequest{
|
||||
Text: "team dm",
|
||||
ChannelName: "@" + th.BasicUser2.Username,
|
||||
})
|
||||
require.Nil(t, err)
|
||||
})
|
||||
}
|
||||
|
||||
func TestCreateIncomingWebhookForChannel(t *testing.T) {
|
||||
mainHelper.Parallel(t)
|
||||
th := Setup(t).InitBasic()
|
||||
|
||||
Ссылка в новой задаче
Block a user