1
0
mirror of https://github.com/nikoksr/notify.git synced 2026-04-26 21:01:59 +02:00
Files
Niko Köser 2b5aecf17e fix(webpush): correct test expectations for empty VAPID keys (#987)
The tests were expecting that sending with empty VAPID keys ("") should
succeed (wantErr: false), but this is incorrect. The webpush-go library
attempts to parse empty strings as valid keys and fails with
"P256 point not on curve" error.

Changed test expectations to correctly expect errors when VAPID keys are
empty strings, which is the actual behavior of the underlying library.

Fixes the two failing webpush tests:
- Send_a_message_with_no_vapid_private_key
- Send_a_message_with_no_vapid_keys
2025-12-12 13:46:59 +01:00
..
2023-06-07 23:01:35 +02:00
2023-06-07 23:01:35 +02:00

Webpush Notifications

go.dev reference

Prerequisites

Generate VAPID Public and Private Keys for the notification service. This can be done using many tools, one of which is GenerateVAPIDKeys from webpush-go.

Compatibility

This service is compatible with the Web Push Protocol and VAPID.

For a list of compatible browsers, see this for the Push API and this for the Web Notifications.

Usage

package main

import (
	"context"
	"log"

	"github.com/nikoksr/notify"
	"github.com/nikoksr/notify/service/webpush"
)

const vapidPublicKey = "..."  // Add a vapidPublicKey
const vapidPrivateKey = "..." // Add a vapidPrivateKey

func main() {
	subscription := webpush.Subscription{
		Endpoint: "https://your-endpoint",
		Keys: {
			Auth:   "...",
			P256dh: "...",
		},
	}

	webpushSvc := webpush.New(vapidPublicKey, vapidPrivateKey)
	webpushSvc.AddReceivers(subscription)

	notifier := notify.NewWithServices(webpushSvc)

	if err := notifier.Send(context.Background(), "TEST", "Message using golang notifier library"); err != nil {
		log.Fatalf("notifier.Send() failed: %s", err.Error())
	}

	log.Println("Notification sent successfully")
}