-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathwebhook_test.go
More file actions
41 lines (37 loc) · 1.54 KB
/
webhook_test.go
File metadata and controls
41 lines (37 loc) · 1.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
package imagekit_test
import (
"net/http"
"strconv"
"testing"
"time"
"github.com/imagekit-developer/imagekit-go/v2"
"github.com/imagekit-developer/imagekit-go/v2/option"
standardwebhooks "github.com/standard-webhooks/standard-webhooks/libraries/go"
)
func TestWebhookUnwrap(t *testing.T) {
client := imagekit.NewClient(
option.WithWebhookSecret("whsec_c2VjcmV0Cg=="),
option.WithPrivateKey("My Private Key"),
option.WithPassword("My Password"),
)
payload := []byte(`{"id":"id","type":"video.transformation.accepted","created_at":"2019-12-27T18:11:19.117Z","data":{"asset":{"url":"https://example.com"},"transformation":{"type":"video-transformation","options":{"audio_codec":"aac","auto_rotate":true,"format":"mp4","quality":0,"stream_protocol":"HLS","variants":["string"],"video_codec":"h264"}}},"request":{"url":"https://example.com","x_request_id":"x_request_id","user_agent":"user_agent"}}`)
wh, err := standardwebhooks.NewWebhook("whsec_c2VjcmV0Cg==")
if err != nil {
t.Fatal("Failed to sign test webhook message", err)
}
msgID := "1"
now := time.Now()
sig, err := wh.Sign(msgID, now, payload)
if err != nil {
t.Fatal("Failed to sign test webhook message:", err)
}
headers := make(http.Header)
headers.Set("webhook-signature", sig)
headers.Set("webhook-id", msgID)
headers.Set("webhook-timestamp", strconv.FormatInt(now.Unix(), 10))
_, err = client.Webhooks.Unwrap(payload, headers)
if err != nil {
t.Fatal("Failed to unwrap webhook:", err)
}
}