webpushtest

package
v1.4.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 4, 2026 License: AGPL-3.0 Imports: 10 Imported by: 0

Documentation

Overview

Package webpushtest is an in-process push service for tests and the demo: it answers the requests FCM, Mozilla's autopush, Apple and Windows would get, checks the VAPID token as they do, decrypts the payload when it made the subscription, and records every message. Nothing it's given ever reaches the network.

Index

Constants

This section is empty.

Variables

View Source
var Hosts = map[string]string{
	"chrome":  "https://fcm.googleapis.com/fcm/send/",
	"android": "https://fcm.googleapis.com/fcm/send/",
	"edge":    "https://wns2-bl2p.notify.windows.com/w/?token=",
	"firefox": "https://updates.push.services.mozilla.com/wpush/v2/",
	"safari":  "https://web.push.apple.com/",
	"ios":     "https://web.push.apple.com/",
}

Hosts are the push services' hosts, by browser.

Functions

This section is empty.

Types

type Page

type Page struct {
	Status int
	Header http.Header
	Body   []byte
}

Page is what the service answers a GET with, as the web server of a site would: a site's hosted service worker, the page a link opens.

type Received

type Received struct {
	At       time.Time
	Endpoint string
	Header   http.Header
	Body     []byte
	// Claims are the VAPID token's claims; Key the public key that signed it.
	Claims webpush.Claims
	Key    []byte
	// Payload is the decrypted message, for subscriptions this service made.
	Payload []byte
	// Status is what the service answered.
	Status int
}

Received is one message the service got.

type Service

type Service struct {
	// Now is the clock tokens are checked against.
	Now func() time.Time
	// contains filtered or unexported fields
}

Service is the fake push service.

func New

func New() *Service

New makes an empty push service.

func (*Service) Answer

func (s *Service) Answer(endpoint string, status int)

Answer makes the service answer status for an endpoint from now on: 410 for a subscription that ended, 429 or 503 for a busy service.

func (*Service) Client

func (s *Service) Client() *http.Client

Client sends every request to the service, whatever its host.

func (*Service) Received

func (s *Service) Received() []Received

Received returns what the service got, oldest first.

func (*Service) Reset

func (s *Service) Reset()

Reset forgets what was received.

func (*Service) Serve

func (s *Service) Serve(u string, p Page)

Serve makes GET requests for u answer p (any other GET answers 404), so tests check sites and links without the network.

func (*Service) ServeHTTP

func (s *Service) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP answers a push request as a push service does: 201 with a Location, 400 without aes128gcm, 403 for a token that doesn't verify, 413 over 4096 bytes, or the status set with Answer.

func (*Service) Subscribe

func (s *Service) Subscribe(browser string) (endpoint, p256dh, auth string)

Subscribe makes a subscription as a browser would get from its push service: the endpoint and the keys, in base64url. The service keeps the private key, so it can read what's sent to it.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL