Skip to content

Commit 76e197b

Browse files
committed
test: cover missing timestamp header in StandardWebhook
1 parent 45aec52 commit 76e197b

1 file changed

Lines changed: 21 additions & 0 deletions

File tree

standardwebhook_test.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,3 +223,24 @@ func TestStandardWebhookMultipleSignatures(t *testing.T) {
223223
t.Errorf("got %v, expected %v", err, nil)
224224
}
225225
}
226+
227+
func TestStandardWebhookMissingTimestamp(t *testing.T) {
228+
rawKey := []byte("supersecretkey")
229+
secret := "whsec_" + base64.StdEncoding.EncodeToString(rawKey)
230+
231+
id := "msg_123"
232+
ts := strconv.FormatInt(time.Now().Unix(), 10)
233+
body := []byte(`{"id":"evt_123"}`)
234+
235+
mac := hmac.New(sha256.New, rawKey)
236+
mac.Write([]byte(id + "." + ts + "." + string(body)))
237+
238+
headers := http.Header{}
239+
headers.Set("webhook-id", id)
240+
241+
err := Verify(StandardWebhook, body, headers, secret)
242+
243+
if !errors.Is(err, ErrMissingHeader) {
244+
t.Errorf("got %v, expected %v", err, ErrMissingHeader)
245+
}
246+
}

0 commit comments

Comments
 (0)