Merge pull request #80 from ryanoolala/fix-webhook-apikey

Fix: issue with api_key in webhook
pull/94/head
Hunter Long 2018-10-11 10:28:09 -07:00 committed by GitHub
commit 9498e86b54
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 5 additions and 2 deletions

View File

@ -130,8 +130,8 @@ func (w *webhooker) run(body string) (*http.Response, error) {
req.Header.Add(split[0], split[1]) req.Header.Add(split[0], split[1])
} }
} }
if w.ApiSecret != "" { if w.ApiKey != "" {
req.Header.Add("Content-Type", w.ApiSecret) req.Header.Add("Content-Type", w.ApiKey)
} }
resp, err := client.Do(req) resp, err := client.Do(req)
if err != nil { if err != nil {

View File

@ -25,6 +25,7 @@ import (
var ( var (
WEBHOOK_URL = "https://jsonplaceholder.typicode.com/posts" WEBHOOK_URL = "https://jsonplaceholder.typicode.com/posts"
webhookMessage = `{ "title": "%service.Id", "body": "%service.Name", "online": %service.Online, "userId": 19999 }` webhookMessage = `{ "title": "%service.Id", "body": "%service.Name", "online": %service.Online, "userId": 19999 }`
apiKey = "application/json"
fullMsg string fullMsg string
) )
@ -41,10 +42,12 @@ func TestWebhookNotifier(t *testing.T) {
t.Run("Load webhooker", func(t *testing.T) { t.Run("Load webhooker", func(t *testing.T) {
webhook.Host = WEBHOOK_URL webhook.Host = WEBHOOK_URL
webhook.Delay = time.Duration(100 * time.Millisecond) webhook.Delay = time.Duration(100 * time.Millisecond)
webhook.ApiKey = apiKey
err := notifier.AddNotifier(webhook) err := notifier.AddNotifier(webhook)
assert.Nil(t, err) assert.Nil(t, err)
assert.Equal(t, "Hunter Long", webhook.Author) assert.Equal(t, "Hunter Long", webhook.Author)
assert.Equal(t, WEBHOOK_URL, webhook.Host) assert.Equal(t, WEBHOOK_URL, webhook.Host)
assert.Equal(t, apiKey, webhook.ApiKey)
}) })
t.Run("Load webhooker Notifier", func(t *testing.T) { t.Run("Load webhooker Notifier", func(t *testing.T) {