A continuation of HomeBox the inventory and organization system built for the Home User
fix: #1395 (generic:// shorthand)
Matthew Kilgoreb6523e5664e2
diff --git a/backend/internal/sys/validate/notifier_url.go b/backend/internal/sys/validate/notifier_url.goindex 0583d102..9f28f6b9 100644--- a/backend/internal/sys/validate/notifier_url.go+++ b/backend/internal/sys/validate/notifier_url.go@@ -133,7 +133,18 @@ func isGenericNotifier(notifierURL string) bool {// extractGenericURL extracts the actual HTTP(S) URL from a generic notifier URLfunc extractGenericURL(notifierURL string) (string, error) {if strings.HasPrefix(notifierURL, "generic://") {- return strings.TrimPrefix(notifierURL, "generic://"), nil+ rawURL := strings.TrimPrefix(notifierURL, "generic://")++ if rawURL == "" {+ return "", fmt.Errorf("generic notifier URL is empty")+ }++ // Support shorthand generic://host/path by defaulting to HTTPS.+ if strings.HasPrefix(rawURL, "http://") || strings.HasPrefix(rawURL, "https://") {+ return rawURL, nil+ }++ return "https://" + rawURL, nil}if strings.HasPrefix(notifierURL, "generic+https://") {return strings.TrimPrefix(notifierURL, "generic+"), nildiff --git a/backend/internal/sys/validate/notifier_url_test.go b/backend/internal/sys/validate/notifier_url_test.goindex 5168499c..110f5f3b 100644--- a/backend/internal/sys/validate/notifier_url_test.go+++ b/backend/internal/sys/validate/notifier_url_test.go@@ -32,6 +32,17 @@ func TestValidateNotifierURL(t *testing.T) {},expectError: false,},+ {+ name: "generic notifier shorthand host/path passes",+ url: "generic://example.com/webhook",+ config: config.NotifierConf{+ BlockLocalhost: true,+ BlockLocalNets: true,+ BlockBogonNets: true,+ BlockCloudMetadata: true,+ },+ expectError: false,+ },{name: "generic notifier with localhost blocked",url: "generic://http://localhost:8080/webhook",@@ -328,6 +339,12 @@ func TestExtractGenericURL(t *testing.T) {expected: "http://example.com/webhook",expectError: false,},+ {+ name: "generic:// shorthand defaults to https",+ url: "generic://example.com/webhook",+ expected: "https://example.com/webhook",+ expectError: false,+ },{name: "generic+https://",url: "generic+https://example.com/webhook",