Skip to content

armgit / Pulse

Public Imported from GitHub
0

Real-time monitoring dashboard for Proxmox VE, PBS, Docker, Kubernetes, TrueNAS and vSphere. Self-hosted, with alerts for failed backups, full disks, unhealthy containers and offline nodes.

test(notifications): protect destination and occurrence receipt identity

pulse-triage[bot]724359508587
diff --git a/internal/notifications/delivery_identity_test.go b/internal/notifications/delivery_identity_test.go
new file mode 100644
index 0000000000..e6f04db485
--- /dev/null
+++ b/internal/notifications/delivery_identity_test.go
@@ -0,0 +1,76 @@
+package notifications
+
+import (
+ "reflect"
+ "testing"
+ "time"
+
+ "github.com/rcourtman/pulse-go-rewrite/internal/alerts"
+)
+
+func TestDeliveryDestinationIdentityNormalization(t *testing.T) {
+ email := func(to ...string) notificationDeliveryJob {
+ return notificationDeliveryJob{Type: "email", EmailConfig: &EmailConfig{To: to}}
+ }
+ apprise := func(server, key string, targets ...string) notificationDeliveryJob {
+ return notificationDeliveryJob{Type: "apprise", AppriseConfig: &AppriseConfig{ServerURL: server, ConfigKey: key, Targets: targets}}
+ }
+ tests := []struct {
+ name string
+ original, equivalent, changed notificationDeliveryJob
+ }{
+ {"apprise targets", apprise("https://relay.example.test", "ops", "ntfy://b", "ntfy://a"), apprise(" https://relay.example.test ", " ops ", " ntfy://a ", "ntfy://b"), apprise("https://relay.example.test", "ops", "ntfy://c", "ntfy://a")},
+ {"apprise server", apprise("https://one.example.test", "ops", "ntfy://a"), apprise("https://one.example.test", "ops", "ntfy://a"), apprise("https://two.example.test", "ops", "ntfy://a")},
+ {"apprise configuration", apprise("https://relay.example.test", "ops", "ntfy://a"), apprise("https://relay.example.test", "ops", "ntfy://a"), apprise("https://relay.example.test", "other", "ntfy://a")},
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ var input []string
+ if tt.original.EmailConfig != nil {
+ input = tt.original.EmailConfig.To
+ } else {
+ input = tt.original.AppriseConfig.Targets
+ }
+ before := append([]string(nil), input...)
+ key := notificationDeliveryDestinationKey(tt.original)
+ if key == "" {
+ t.Fatal("missing destination identity")
+ }
+ if key != notificationDeliveryDestinationKey(tt.equivalent) {
+ t.Fatal("equivalent destination changed identity")
+ }
+ if key == notificationDeliveryDestinationKey(tt.changed) {
+ t.Fatal("changed destination inherited identity")
+ }
+ if !reflect.DeepEqual(input, before) {
+ t.Fatal("identity calculation mutated configured order")
+ }
+ })
+ }
+}
+
+func TestDeliveryReceiptIdentityRequiresOccurrence(t *testing.T) {
+ start := time.Date(2026, 9, 8, 7, 0, 0, 123, time.UTC)
+ original := &alerts.Alert{ID: "cpu-1", StartTime: start}
+ key := notificationDeliveryReceiptKey(original, "destination")
+ if key == "" {
+ t.Fatal("missing occurrence identity")
+ }
+ next := original.Clone()
+ next.StartTime = start.Add(time.Nanosecond)
+ if key == notificationDeliveryReceiptKey(next, "destination") {
+ t.Fatal("adjacent recurrence reused identity")
+ }
+ if key == notificationDeliveryReceiptKey(original, "other") {
+ t.Fatal("other destination reused identity")
+ }
+ for _, alert := range []*alerts.Alert{nil, {}, {ID: "cpu-1"}, {StartTime: start}} {
+ if notificationDeliveryReceiptKey(alert, "destination") != "" {
+ t.Fatal("incomplete occurrence gained receipt identity")
+ }
+ }
+ if notificationDeliveryReceiptKey(original, "") != "" {
+ t.Fatal("missing destination gained receipt identity")
+ }
+}