Skip to content

Commit 9af9035

Browse files
joeybloggsjoeybloggs
authored andcommitted
Add Coverage Tests to GitHub webhooks
1 parent 3def7b0 commit 9af9035

File tree

2 files changed

+3771
-25
lines changed

2 files changed

+3771
-25
lines changed

github/github.go

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,8 @@ func (hook Webhook) ParsePayload(w http.ResponseWriter, r *http.Request) {
103103
}
104104

105105
payload, err := ioutil.ReadAll(r.Body)
106-
if err != nil {
107-
http.Error(w, err.Error(), http.StatusInternalServerError)
106+
if err != nil || len(payload) == 0 {
107+
http.Error(w, "Error reading Body", http.StatusInternalServerError)
108108
return
109109
}
110110

@@ -119,11 +119,7 @@ func (hook Webhook) ParsePayload(w http.ResponseWriter, r *http.Request) {
119119
}
120120

121121
mac := hmac.New(sha1.New, []byte(hook.secret))
122-
_, err := mac.Write(payload)
123-
if err != nil {
124-
http.Error(w, "400 Bad Request - HMAC verification failed with body parsing", http.StatusBadRequest)
125-
return
126-
}
122+
mac.Write(payload)
127123

128124
expectedMAC := hex.EncodeToString(mac.Sum(nil))
129125

@@ -218,8 +214,6 @@ func (hook Webhook) ParsePayload(w http.ResponseWriter, r *http.Request) {
218214
var w WatchPayload
219215
json.Unmarshal([]byte(payload), &w)
220216
hook.runProcessPayloadFunc(fn, w)
221-
default:
222-
http.Error(w, "400 Bad Request - Unknown Event "+event, http.StatusBadRequest)
223217
}
224218
}
225219

0 commit comments

Comments
 (0)