pushtest

package
v0.4.0 Latest Latest
Warning

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

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

Documentation

Overview

Package pushtest is a fake Web Push service and a fake browser for tests. The service checks each request the way real push services do (VAPID signature and audience, content coding, TTL) and the browser decrypts what it received, so a test sees the notification a person would.

Index

Constants

View Source
const Origin = "https://example.com"

Origin is the audience the VAPID claims must name. The test TLS certificate is for example.com, so tests reach the service under that name.

Variables

This section is empty.

Functions

func Endpoint

func Endpoint(name string) string

Endpoint is the URL of a new subscription on this service.

func VerifyVAPID

func VerifyVAPID(header, origin string, now time.Time) (map[string]any, error)

VerifyVAPID checks an Authorization header (`vapid t=…, k=…`) for a request to origin and returns the JWT claims.

Types

type Browser

type Browser struct {
	// contains filtered or unexported fields
}

Browser is one push subscription's private side.

func NewBrowser

func NewBrowser() *Browser

NewBrowser makes fresh browser keys.

func (*Browser) Auth

func (b *Browser) Auth() string

func (*Browser) Decrypt

func (b *Browser) Decrypt(body []byte) ([]byte, error)

Decrypt reads an aes128gcm push message (RFC 8291, receiver side).

func (*Browser) P256dh

func (b *Browser) P256dh() string

P256dh and Auth are the keys of the browser's PushSubscription, base64url.

type Request

type Request struct {
	Path    string
	Header  http.Header
	Body    []byte
	Problem string // why it was refused, "" if accepted
}

Request is one push received by the service.

type Service

type Service struct {
	*httptest.Server
	// contains filtered or unexported fields
}

Service is a fake push service over TLS. Endpoints are <URL>/push/<anything>.

func Start

func Start(t testing.TB) *Service

Start runs the service until the test ends.

func (*Service) Fail

func (s *Service) Fail(path string, status int)

Fail makes pushes to path answer status from now on (0 resets).

func (*Service) Received

func (s *Service) Received(t testing.TB, name string, b *Browser) []map[string]any

Received decrypts the accepted pushes to name for browser b.

func (*Service) Requests

func (s *Service) Requests() []Request

Requests returns what was received so far.

Jump to

Keyboard shortcuts

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