Add Coverage Tests to GitHub webhooks

This commit is contained in:
joeybloggs
2015-10-30 12:19:06 -04:00
parent 3def7b0883
commit 9af9035c2b
2 changed files with 3774 additions and 28 deletions
+3 -9
View File
@@ -103,8 +103,8 @@ func (hook Webhook) ParsePayload(w http.ResponseWriter, r *http.Request) {
} }
payload, err := ioutil.ReadAll(r.Body) payload, err := ioutil.ReadAll(r.Body)
if err != nil { if err != nil || len(payload) == 0 {
http.Error(w, err.Error(), http.StatusInternalServerError) http.Error(w, "Error reading Body", http.StatusInternalServerError)
return return
} }
@@ -119,11 +119,7 @@ func (hook Webhook) ParsePayload(w http.ResponseWriter, r *http.Request) {
} }
mac := hmac.New(sha1.New, []byte(hook.secret)) mac := hmac.New(sha1.New, []byte(hook.secret))
_, err := mac.Write(payload) mac.Write(payload)
if err != nil {
http.Error(w, "400 Bad Request - HMAC verification failed with body parsing", http.StatusBadRequest)
return
}
expectedMAC := hex.EncodeToString(mac.Sum(nil)) expectedMAC := hex.EncodeToString(mac.Sum(nil))
@@ -218,8 +214,6 @@ func (hook Webhook) ParsePayload(w http.ResponseWriter, r *http.Request) {
var w WatchPayload var w WatchPayload
json.Unmarshal([]byte(payload), &w) json.Unmarshal([]byte(payload), &w)
hook.runProcessPayloadFunc(fn, w) hook.runProcessPayloadFunc(fn, w)
default:
http.Error(w, "400 Bad Request - Unknown Event "+event, http.StatusBadRequest)
} }
} }
+3771 -19
View File
File diff suppressed because it is too large Load Diff