Exemple #1
0
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))
	}
}
Exemple #2
0
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))
}
Exemple #3
0
func expectParseError(t *testing.T, msg string, r *http.Request) {
	_, err := githubhook.Parse([]byte(testSecret), r)
	expectErrorMessage(t, msg, err)
}