1package webhook
2
3import (
4 "errors"
5 "testing"
6
7 "github.com/charmbracelet/soft-serve/pkg/ssrf"
8)
9
10// TestValidateWebhookURL verifies the wrapper delegates correctly and
11// error aliases work across the package boundary. IP range coverage
12// is in pkg/ssrf/ssrf_test.go -- here we just confirm the plumbing.
13func TestValidateWebhookURL(t *testing.T) {
14 tests := []struct {
15 name string
16 url string
17 wantErr bool
18 errType error
19 }{
20 {"valid", "https://1.1.1.1/webhook", false, nil},
21 {"bad scheme", "ftp://example.com", true, ErrInvalidScheme},
22 {"private IP", "http://127.0.0.1/webhook", true, ErrPrivateIP},
23 {"empty", "", true, ErrInvalidURL},
24 }
25
26 for _, tt := range tests {
27 t.Run(tt.name, func(t *testing.T) {
28 err := ValidateWebhookURL(tt.url)
29 if (err != nil) != tt.wantErr {
30 t.Errorf("ValidateWebhookURL(%q) error = %v, wantErr %v", tt.url, err, tt.wantErr)
31 return
32 }
33 if tt.wantErr && tt.errType != nil {
34 if !errors.Is(err, tt.errType) {
35 t.Errorf("ValidateWebhookURL(%q) error = %v, want %v", tt.url, err, tt.errType)
36 }
37 }
38 })
39 }
40}
41
42func TestErrorAliases(t *testing.T) {
43 if ErrPrivateIP != ssrf.ErrPrivateIP {
44 t.Error("ErrPrivateIP should alias ssrf.ErrPrivateIP")
45 }
46 if ErrInvalidScheme != ssrf.ErrInvalidScheme {
47 t.Error("ErrInvalidScheme should alias ssrf.ErrInvalidScheme")
48 }
49 if ErrInvalidURL != ssrf.ErrInvalidURL {
50 t.Error("ErrInvalidURL should alias ssrf.ErrInvalidURL")
51 }
52}