-
Notifications
You must be signed in to change notification settings - Fork 56
Expand file tree
/
Copy pathrepository_test.go
More file actions
59 lines (51 loc) · 2.43 KB
/
Copy pathrepository_test.go
File metadata and controls
59 lines (51 loc) · 2.43 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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package repository_test
import (
"testing"
"github.com/padok-team/burrito/internal/repository"
"github.com/padok-team/burrito/internal/repository/credentials"
"github.com/stretchr/testify/assert"
)
// allProviderKeys lists every provider key handled by
// repository.GetProviderFromCredentials. That switch statement is the single,
// mandatory registration point for providers (see internal/repository/AGENTS.md:
// "Adding a provider = add a case here"), so keeping this list in sync with it
// guarantees that every provider reachable in production is exercised by the
// non-regression test below.
var allProviderKeys = []string{"github", "gitlab", "standard", "mock"}
// TestGetWebhookProvider_RejectsEmptyWebhookSecret is a security non-regression
// test: no provider must ever hand back a usable webhook provider when the
// webhook secret is empty. An empty secret makes go-playground/webhooks skip
// HMAC/token verification entirely, which would let anyone POST forged,
// unsigned events to /api/webhook. The invariant is enforced centrally in
// GetProviderFromCredentials, so this test drives every provider through that
// factory to prove the enforcement is wired in for all of them.
func TestGetWebhookProvider_RejectsEmptyWebhookSecret(t *testing.T) {
for _, key := range allProviderKeys {
t.Run(key, func(t *testing.T) {
provider, err := repository.GetProviderFromCredentials(credentials.Credential{
Provider: key,
WebhookSecret: "",
})
assert.NoError(t, err, "provider %q should be constructible", key)
_, err = provider.GetWebhookProvider()
assert.Error(t, err, "provider %q must return an error when the webhook secret is empty", key)
})
}
}
// TestGetWebhookProvider_AcceptsNonEmptyWebhookSecret guards the legitimate,
// correctly-configured path: providers that support webhooks must still return
// a working webhook provider when a secret is configured.
func TestGetWebhookProvider_AcceptsNonEmptyWebhookSecret(t *testing.T) {
for _, key := range []string{"github", "gitlab"} {
t.Run(key, func(t *testing.T) {
provider, err := repository.GetProviderFromCredentials(credentials.Credential{
Provider: key,
WebhookSecret: "a-real-secret",
})
assert.NoError(t, err, "provider %q should be constructible", key)
whProvider, err := provider.GetWebhookProvider()
assert.NoError(t, err, "provider %q should accept a non-empty webhook secret", key)
assert.NotNil(t, whProvider)
})
}
}