func TestValidSignature(t *testing.T) { body := "{}" r, _ := http.NewRequest("POST", "/path", strings.NewReader(body)) r.Header.Add("x-hub-signature", signature(body)) r.Header.Add("x-github-event", "bogus event") r.Header.Add("x-github-delivery", "bogus id") if _, err := githubhook.Parse([]byte(testSecret), r); err != nil { t.Error(fmt.Sprintf("Unexpected error '%s'", err)) } }
func (s *WebhookServer) handle(w http.ResponseWriter, r *http.Request) { body, err := githubhook.Parse([]byte(s.secret), r) if err != nil { log.Println("Webhook parsing failed", err) http.Error(w, err.Error(), 400) return } go func() { switch body.Event { case "pull_request": go HandlePullRequestEvent(parsePullRequestEvent(body)) default: log.Printf("Saw unknown event '%s' and waved as it went by.", body.Event) } }() w.Write([]byte(OK_RESPONSE)) }
func expectParseError(t *testing.T, msg string, r *http.Request) { _, err := githubhook.Parse([]byte(testSecret), r) expectErrorMessage(t, msg, err) }