summaryrefslogtreecommitdiffstats
path: root/web
diff options
context:
space:
mode:
authorGeorge Goldberg <george@gberg.me>2018-05-22 19:06:14 +0100
committerChristopher Speller <crspeller@gmail.com>2018-05-22 11:06:14 -0700
commit8fb070fecfbb91f22c6f540ecf0b77fb8be42ab2 (patch)
treea81061077e5b4241e0241b18f1badeba9c10266f /web
parent1af1bce6199597bb2d41ddcdc00ef0f28a73c83e (diff)
downloadchat-8fb070fecfbb91f22c6f540ecf0b77fb8be42ab2.tar.gz
chat-8fb070fecfbb91f22c6f540ecf0b77fb8be42ab2.tar.bz2
chat-8fb070fecfbb91f22c6f540ecf0b77fb8be42ab2.zip
MM-10352: Add locking incoming webhooks to a single channel. (#8835)
Diffstat (limited to 'web')
-rw-r--r--web/webhook_test.go23
1 files changed, 23 insertions, 0 deletions
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\"}"))