Merge pull request #239 from Rested/master

Fixes handling of invalid urls in webhooks
This commit is contained in:
Kubernetes Prow Robot 2020-03-19 08:25:23 -07:00 committed by GitHub
commit 8015d4b24e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 1 deletions

View File

@ -72,10 +72,10 @@ func (w *Webhook) Send(hash string) {
func (w *Webhook) Do(hash string) error {
req, err := http.NewRequest(w.Method, w.URL, nil)
req.Header.Set("Gitsync-Hash", hash)
if err != nil {
return err
}
req.Header.Set("Gitsync-Hash", hash)
ctx, cancel := context.WithTimeout(context.Background(), w.Timeout)
defer cancel()

View File

@ -3,6 +3,7 @@ package main
import (
"fmt"
"testing"
"time"
)
const (
@ -62,3 +63,20 @@ func TestWebhookData(t *testing.T) {
}
})
}
func TestDo(t *testing.T) {
t.Run("test invalid urls are handled", func(t *testing.T) {
wh := Webhook{
URL: ":http://localhost:601426/hooks/webhook",
Method: "POST",
Success: 200,
Timeout: time.Second,
Backoff: time.Second * 3,
Data: NewWebhookData(),
}
err := wh.Do("hash")
if err == nil {
t.Fatalf("expected error for invalid url but got none")
}
})
}