From a5a55bd43a6ef8b1245c826c3135f7d26168494d Mon Sep 17 00:00:00 2001 From: binwiederhier Date: Thu, 7 Aug 2025 18:54:37 +0200 Subject: [PATCH] Move WebPush tests --- server/server_test.go | 36 ----------------------------------- server/server_webpush_test.go | 35 ++++++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 36 deletions(-) diff --git a/server/server_test.go b/server/server_test.go index 41633dd5..19c0165c 100644 --- a/server/server_test.go +++ b/server/server_test.go @@ -23,7 +23,6 @@ import ( "testing" "time" - "github.com/SherClockHolmes/webpush-go" "github.com/stretchr/testify/require" "heckel.io/ntfy/v2/log" "heckel.io/ntfy/v2/util" @@ -281,30 +280,6 @@ func TestServer_WebEnabled(t *testing.T) { rr = request(t, s2, "GET", "/app.html", "", nil) require.Equal(t, 200, rr.Code) } - -func TestServer_WebPushEnabled(t *testing.T) { - conf := newTestConfig(t) - conf.WebRoot = "" // Disable web app - s := newTestServer(t, conf) - - rr := request(t, s, "GET", "/manifest.webmanifest", "", nil) - require.Equal(t, 404, rr.Code) - - conf2 := newTestConfig(t) - s2 := newTestServer(t, conf2) - - rr = request(t, s2, "GET", "/manifest.webmanifest", "", nil) - require.Equal(t, 404, rr.Code) - - conf3 := newTestConfigWithWebPush(t) - s3 := newTestServer(t, conf3) - - rr = request(t, s3, "GET", "/manifest.webmanifest", "", nil) - require.Equal(t, 200, rr.Code) - require.Equal(t, "application/manifest+json", rr.Header().Get("Content-Type")) - -} - func TestServer_PublishLargeMessage(t *testing.T) { c := newTestConfig(t) c.AttachmentCacheDir = "" // Disable attachments @@ -3257,17 +3232,6 @@ func newTestConfigWithAuthFile(t *testing.T) *Config { return conf } -func newTestConfigWithWebPush(t *testing.T) *Config { - conf := newTestConfig(t) - privateKey, publicKey, err := webpush.GenerateVAPIDKeys() - require.Nil(t, err) - conf.WebPushFile = filepath.Join(t.TempDir(), "webpush.db") - conf.WebPushEmailAddress = "testing@example.com" - conf.WebPushPrivateKey = privateKey - conf.WebPushPublicKey = publicKey - return conf -} - func newTestServer(t *testing.T, config *Config) *Server { server, err := New(config) require.Nil(t, err) diff --git a/server/server_webpush_test.go b/server/server_webpush_test.go index 6aa6c60a..f116103a 100644 --- a/server/server_webpush_test.go +++ b/server/server_webpush_test.go @@ -5,6 +5,7 @@ package server import ( "encoding/json" "fmt" + "github.com/SherClockHolmes/webpush-go" "github.com/stretchr/testify/require" "heckel.io/ntfy/v2/user" "heckel.io/ntfy/v2/util" @@ -12,6 +13,7 @@ import ( "net/http" "net/http/httptest" "net/netip" + "path/filepath" "strings" "sync/atomic" "testing" @@ -22,6 +24,28 @@ const ( testWebPushEndpoint = "https://updates.push.services.mozilla.com/wpush/v1/AAABBCCCDDEEEFFF" ) +func TestServer_WebPush_Enabled(t *testing.T) { + conf := newTestConfig(t) + conf.WebRoot = "" // Disable web app + s := newTestServer(t, conf) + + rr := request(t, s, "GET", "/manifest.webmanifest", "", nil) + require.Equal(t, 404, rr.Code) + + conf2 := newTestConfig(t) + s2 := newTestServer(t, conf2) + + rr = request(t, s2, "GET", "/manifest.webmanifest", "", nil) + require.Equal(t, 404, rr.Code) + + conf3 := newTestConfigWithWebPush(t) + s3 := newTestServer(t, conf3) + + rr = request(t, s3, "GET", "/manifest.webmanifest", "", nil) + require.Equal(t, 200, rr.Code) + require.Equal(t, "application/manifest+json", rr.Header().Get("Content-Type")) + +} func TestServer_WebPush_Disabled(t *testing.T) { s := newTestServer(t, newTestConfig(t)) @@ -256,3 +280,14 @@ func requireSubscriptionCount(t *testing.T, s *Server, topic string, expectedLen require.Nil(t, err) require.Len(t, subs, expectedLength) } + +func newTestConfigWithWebPush(t *testing.T) *Config { + conf := newTestConfig(t) + privateKey, publicKey, err := webpush.GenerateVAPIDKeys() + require.Nil(t, err) + conf.WebPushFile = filepath.Join(t.TempDir(), "webpush.db") + conf.WebPushEmailAddress = "testing@example.com" + conf.WebPushPrivateKey = privateKey + conf.WebPushPublicKey = publicKey + return conf +}