ntfy webhook format

This commit is contained in:
Bel LaPointe
2025-04-22 20:40:19 -06:00
parent 54bbca8fea
commit 5b9bead96f
2 changed files with 27 additions and 10 deletions

View File

@@ -5,6 +5,7 @@ import (
"io/ioutil"
"net/http"
"net/http/httptest"
"net/url"
"os"
"path"
"slices"
@@ -153,13 +154,17 @@ func TestRunWith(t *testing.T) {
func TestRecursive(t *testing.T) {
webhooks := []string{}
s := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if r.URL.Query().Get("p") == "" {
t.Errorf("webhook wasn't called with ?p: %s", r.URL.String())
if r.Method != http.MethodPut {
t.Errorf("unexpected webhook method %s", r.Method)
}
if r.URL.User.String() != "" {
t.Errorf("unexpected auth on url %s", r.URL.String())
}
if u, p, _ := r.BasicAuth(); u != "u" || p != "p" {
t.Errorf("webhook didnt translate u:p to basic auth")
}
b, _ := ioutil.ReadAll(r.Body)
if string(b) != r.URL.Query().Get("p") {
t.Errorf("webhook wasn't called with ?p == {body}: %q vs %q", r.URL.Query().Get("p"), b)
}
t.Logf("%s { %s }", r.URL.String(), b)
webhooks = append(webhooks, string(b))
}))
t.Cleanup(s.Close)
@@ -176,7 +181,9 @@ func TestRecursive(t *testing.T) {
}
})
main.WebhookOnRecursiveMiss = s.URL
u, _ := url.Parse(s.URL)
u.User = url.UserPassword("u", "p")
main.WebhookOnRecursiveMiss = u.String()
main.WebhookOnRecursiveMissCacheD = t.TempDir()
t.Cleanup(func() {
main.WebhookOnRecursiveMiss = ""