MCPcopy Create free account
hub / github.com/authorizerdev/authorizer / TestWebhooks

Function TestWebhooks

internal/integration_tests/webhooks_test.go:17–82  ·  view source on GitHub ↗

TestWebhooks tests the _webhooks list and _webhook single queries

(t *testing.T)

Source from the content-addressed store, hash-verified

15
16// TestWebhooks tests the _webhooks list and _webhook single queries
17func TestWebhooks(t *testing.T) {
18 cfg := getTestConfig()
19 ts := initTestSetup(t, cfg)
20 req, ctx := createContext(ts)
21
22 t.Run("should fail list webhooks without admin auth", func(t *testing.T) {
23 req.Header.Set("Cookie", "")
24 res, err := ts.GraphQLProvider.Webhooks(ctx, &model.PaginatedRequest{})
25 assert.Error(t, err)
26 assert.Nil(t, res)
27 })
28
29 t.Run("should list webhooks with admin auth", func(t *testing.T) {
30 h, err := crypto.EncryptPassword(cfg.AdminSecret)
31 require.NoError(t, err)
32 req.Header.Set("Cookie", fmt.Sprintf("%s=%s", constants.AdminCookieName, h))
33
34 res, err := ts.GraphQLProvider.Webhooks(ctx, &model.PaginatedRequest{})
35 require.NoError(t, err)
36 assert.NotNil(t, res)
37 assert.NotNil(t, res.Pagination)
38 })
39
40 t.Run("should add and get single webhook", func(t *testing.T) {
41 h, err := crypto.EncryptPassword(cfg.AdminSecret)
42 require.NoError(t, err)
43 req.Header.Set("Cookie", fmt.Sprintf("%s=%s", constants.AdminCookieName, h))
44
45 // Add a webhook
46 addRes, err := ts.GraphQLProvider.AddWebhook(ctx, &model.AddWebhookRequest{
47 EventName: constants.UserLoginWebhookEvent,
48 Endpoint: "https://example.com/webhook",
49 Enabled: true,
50 EventDescription: refs.NewStringRef("Test webhook"),
51 })
52 require.NoError(t, err)
53 assert.NotNil(t, addRes)
54
55 // List webhooks to get the ID
56 webhooks, err := ts.GraphQLProvider.Webhooks(ctx, &model.PaginatedRequest{})
57 require.NoError(t, err)
58 assert.GreaterOrEqual(t, len(webhooks.Webhooks), 1)
59
60 webhookID := webhooks.Webhooks[0].ID
61
62 // Get single webhook
63 webhook, err := ts.GraphQLProvider.Webhook(ctx, &model.WebhookRequest{
64 ID: webhookID,
65 })
66 require.NoError(t, err)
67 assert.NotNil(t, webhook)
68 assert.Equal(t, webhookID, webhook.ID)
69 })
70
71 t.Run("should fail get webhook with invalid ID", func(t *testing.T) {
72 h, err := crypto.EncryptPassword(cfg.AdminSecret)
73 require.NoError(t, err)
74 req.Header.Set("Cookie", fmt.Sprintf("%s=%s", constants.AdminCookieName, h))

Callers

nothing calls this directly

Calls 12

EncryptPasswordFunction · 0.92
NewStringRefFunction · 0.92
getTestConfigFunction · 0.85
initTestSetupFunction · 0.85
createContextFunction · 0.85
ErrorMethod · 0.80
SetMethod · 0.65
WebhooksMethod · 0.65
AddWebhookMethod · 0.65
WebhookMethod · 0.65
RunMethod · 0.45
StringMethod · 0.45

Tested by

no test coverage detected