From 8fb070fecfbb91f22c6f540ecf0b77fb8be42ab2 Mon Sep 17 00:00:00 2001 From: George Goldberg Date: Tue, 22 May 2018 19:06:14 +0100 Subject: MM-10352: Add locking incoming webhooks to a single channel. (#8835) --- web/webhook_test.go | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'web') diff --git a/web/webhook_test.go b/web/webhook_test.go index 48e0a2744..64ce7bf25 100644 --- a/web/webhook_test.go +++ b/web/webhook_test.go @@ -182,6 +182,29 @@ func TestIncomingWebhook(t *testing.T) { assert.True(t, resp.StatusCode == http.StatusOK) }) + t.Run("ChannelLockedWebhook", func(t *testing.T) { + channel, err := th.App.CreateChannel(&model.Channel{TeamId: th.BasicTeam.Id, Name: model.NewId(), DisplayName: model.NewId(), Type: model.CHANNEL_OPEN, CreatorId: th.BasicUser.Id}, true) + require.Nil(t, err) + + hook, err := th.App.CreateIncomingWebhookForChannel(th.BasicUser.Id, th.BasicChannel, &model.IncomingWebhook{ChannelId: th.BasicChannel.Id, ChannelLocked: true}) + require.Nil(t, err) + + url := ApiClient.Url + "/hooks/" + hook.Id + + payload := "payload={\"text\": \"test text\"}" + resp, err2 := http.Post(url, "application/x-www-form-urlencoded", strings.NewReader(payload)) + require.Nil(t, err2) + assert.True(t, resp.StatusCode == http.StatusOK) + + resp, err2 = http.Post(url, "application/json", strings.NewReader(fmt.Sprintf("{\"text\":\"this is a test\", \"channel\":\"%s\"}", th.BasicChannel.Name))) + require.Nil(t, err2) + assert.True(t, resp.StatusCode == http.StatusOK) + + resp, err2 = http.Post(url, "application/json", strings.NewReader(fmt.Sprintf("{\"text\":\"this is a test\", \"channel\":\"%s\"}", channel.Name))) + require.Nil(t, err2) + assert.True(t, resp.StatusCode == http.StatusForbidden) + }) + t.Run("DisableWebhooks", func(t *testing.T) { th.App.UpdateConfig(func(cfg *model.Config) { cfg.ServiceSettings.EnableIncomingWebhooks = false }) resp, err := http.Post(url, "application/json", strings.NewReader("{\"text\":\"this is a test\"}")) -- cgit v1.2.3-1-g7c22