jwttest

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Jun 15, 2026 License: AGPL-3.0 Imports: 11 Imported by: 0

Documentation

Overview

Package jwttest provides an in-process jwt.Signer for tests. It generates RSA keys on the fly and never touches disk or external services. Production code MUST NOT import this package.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Signer

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

Signer is an in-memory jwt.Signer for tests. All operations are goroutine-safe; AddKey / SetActive / DropKey may be called concurrently with Sign / Verify.

func NewSigner

func NewSigner(tb testing.TB, kid string) *Signer

NewSigner constructs a Signer with a single key (the active one). Subsequent keys are added with AddKey.

func (*Signer) ActiveKID

func (s *Signer) ActiveKID() string

ActiveKID returns the kid stamped on new tokens.

func (*Signer) AddKey

func (s *Signer) AddKey(tb testing.TB, kid string)

AddKey generates a fresh RSA-2048 key and registers it under kid.

func (*Signer) DropKey

func (s *Signer) DropKey(kid string)

DropKey removes a key entirely. Tokens signed with that kid will no longer verify.

func (*Signer) Get

func (s *Signer) Get(kid string) (*rsa.PublicKey, bool)

Get returns the public key for the supplied kid.

func (*Signer) Keys

func (s *Signer) Keys() []jwt.PublicKey

Keys returns the snapshot of public keys.

func (*Signer) SetActive

func (s *Signer) SetActive(kid string)

SetActive marks the kid as the active signing key.

func (*Signer) SignAccessToken

func (s *Signer) SignAccessToken(ctx context.Context, claims jwt.Claims, expiry time.Duration) (string, error)

SignAccessToken signs an access-token JWT.

func (*Signer) SignClaims

func (s *Signer) SignClaims(_ context.Context, claims map[string]any) (string, error)

SignClaims signs a generic claim map.

Jump to

Keyboard shortcuts

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