mirror of
https://github.com/Dvorinka/Containr.git
synced 2026-10-28 07:41:27 +00:00
- calculateNextRun: field-count, garbage, bad-zone errors; CRON_TZ actually shifts the instant (UTC vs Asia/Tokyo) - validWebhookURL: http/https only, host required, whitespace trimmed - canvas layout math extracted to canvas/layout.ts (component files may only export components) and covered: rectsOverlap gap zone, resolveFreeSpot grid-snap/collision/bounds-fallback, groupSlot fit/append/grow/ignore-dragged, buildMetadataFromFlow serialization Generated with [Devin](https://devin.ai) Co-authored-by: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
64 lines
1.8 KiB
Go
64 lines
1.8 KiB
Go
package api
|
|
|
|
import (
|
|
"encoding/json"
|
|
"testing"
|
|
)
|
|
|
|
func TestWebhookEventMatches(t *testing.T) {
|
|
subs := func(list ...string) json.RawMessage {
|
|
raw, _ := json.Marshal(list)
|
|
return raw
|
|
}
|
|
cases := []struct {
|
|
events json.RawMessage
|
|
event string
|
|
want bool
|
|
}{
|
|
{subs("service.*"), "service.deploy", true},
|
|
{subs("service.*"), "database.create", false},
|
|
{subs("*"), "service.deploy", true},
|
|
{subs("deployment.fail", "service.*"), "deployment.fail", true},
|
|
{subs("deployment.fail"), "deployment.success", false},
|
|
{subs(" ping "), "ping", true},
|
|
{subs(), "service.deploy", false},
|
|
{json.RawMessage(`"not-a-list"`), "service.deploy", false},
|
|
{json.RawMessage(`invalid`), "service.deploy", false},
|
|
}
|
|
for i, tc := range cases {
|
|
if got := webhookEventMatches(tc.events, tc.event); got != tc.want {
|
|
t.Errorf("case %d: matches(%s, %q) = %v, want %v", i, tc.events, tc.event, got, tc.want)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestValidWebhookURL(t *testing.T) {
|
|
cases := []struct {
|
|
name string
|
|
url string
|
|
wantErr bool
|
|
}{
|
|
{"https", "https://hooks.example.com/wh/abc", false},
|
|
{"http", "http://internal.lan:8080/notify", false},
|
|
{"whitespace trimmed", " https://example.com/hook ", false},
|
|
{"with query", "https://example.com/hook?token=x", false},
|
|
{"ftp rejected", "ftp://files.example.com/x", true},
|
|
{"no scheme", "example.com/hook", true},
|
|
{"bare scheme", "https://", true},
|
|
{"empty", "", true},
|
|
{"javascript rejected", "javascript:alert(1)", true},
|
|
{"host empty", "http:///path-only", true},
|
|
}
|
|
for _, tc := range cases {
|
|
t.Run(tc.name, func(t *testing.T) {
|
|
err := validWebhookURL(tc.url)
|
|
if tc.wantErr && err == nil {
|
|
t.Errorf("validWebhookURL(%q) = nil, want error", tc.url)
|
|
}
|
|
if !tc.wantErr && err != nil {
|
|
t.Errorf("validWebhookURL(%q) = %v, want nil", tc.url, err)
|
|
}
|
|
})
|
|
}
|
|
}
|