Merge pull request #239 from Rested/master
Fixes handling of invalid urls in webhooks
This commit is contained in:
commit
8015d4b24e
|
|
@ -72,10 +72,10 @@ func (w *Webhook) Send(hash string) {
|
||||||
|
|
||||||
func (w *Webhook) Do(hash string) error {
|
func (w *Webhook) Do(hash string) error {
|
||||||
req, err := http.NewRequest(w.Method, w.URL, nil)
|
req, err := http.NewRequest(w.Method, w.URL, nil)
|
||||||
req.Header.Set("Gitsync-Hash", hash)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
req.Header.Set("Gitsync-Hash", hash)
|
||||||
|
|
||||||
ctx, cancel := context.WithTimeout(context.Background(), w.Timeout)
|
ctx, cancel := context.WithTimeout(context.Background(), w.Timeout)
|
||||||
defer cancel()
|
defer cancel()
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@ package main
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"testing"
|
"testing"
|
||||||
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
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")
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue