From 72fc43c8cfcce4929b399e627873b97049610aff Mon Sep 17 00:00:00 2001 From: Ryan Date: Thu, 11 Oct 2018 17:25:16 +0800 Subject: [PATCH] Fix: issue with api_key in webhook Fixed issue where api_key value, aka content type field in Webhook UI - Webhook is setting ApiSecret value into Content-Type header --- notifiers/webhook.go | 4 ++-- notifiers/webhook_test.go | 3 +++ 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/notifiers/webhook.go b/notifiers/webhook.go index fa5706e2..1216f1fc 100644 --- a/notifiers/webhook.go +++ b/notifiers/webhook.go @@ -130,8 +130,8 @@ func (w *webhooker) run(body string) (*http.Response, error) { req.Header.Add(split[0], split[1]) } } - if w.ApiSecret != "" { - req.Header.Add("Content-Type", w.ApiSecret) + if w.ApiKey != "" { + req.Header.Add("Content-Type", w.ApiKey) } resp, err := client.Do(req) if err != nil { diff --git a/notifiers/webhook_test.go b/notifiers/webhook_test.go index 022e4ac2..db3f1dd3 100644 --- a/notifiers/webhook_test.go +++ b/notifiers/webhook_test.go @@ -25,6 +25,7 @@ import ( var ( WEBHOOK_URL = "https://jsonplaceholder.typicode.com/posts" webhookMessage = `{ "title": "%service.Id", "body": "%service.Name", "online": %service.Online, "userId": 19999 }` + apiKey = "application/json" fullMsg string ) @@ -41,10 +42,12 @@ func TestWebhookNotifier(t *testing.T) { t.Run("Load webhooker", func(t *testing.T) { webhook.Host = WEBHOOK_URL webhook.Delay = time.Duration(100 * time.Millisecond) + webhook.ApiKey = apiKey err := notifier.AddNotifier(webhook) assert.Nil(t, err) assert.Equal(t, "Hunter Long", webhook.Author) assert.Equal(t, WEBHOOK_URL, webhook.Host) + assert.Equal(t, apiKey, webhook.ApiKey) }) t.Run("Load webhooker Notifier", func(t *testing.T) {