testing

package
v0.2.5 Latest Latest
Warning

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

Go to latest
Published: Jan 10, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package testing provides utilities for testing applications that use authkit. It provides a mock issuer that serves JWKS and can sign tokens, enabling integration tests without needing a real auth server.

Example usage:

issuer := testing.NewTestIssuer()
defer issuer.Close()

// Configure your app to use the test issuer
cfg.Auth.Issuers = []string{issuer.URL()}

// Create tokens for testing
token := issuer.CreateToken("user-123", "[email protected]")

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type TestIssuer

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

TestIssuer provides a complete mock authentication setup for testing. It runs an HTTP server that serves JWKS at /.well-known/jwks.json and can sign JWT tokens that will validate against the JWKS.

func NewTestIssuer

func NewTestIssuer() *TestIssuer

NewTestIssuer creates a new test issuer with a JWKS endpoint. The issuer generates a new RSA key pair and serves the public key as JWKS. Call Close() when done to shut down the test server.

func NewTestIssuerWithAudience

func NewTestIssuerWithAudience(audience string) *TestIssuer

NewTestIssuerWithAudience creates a test issuer with a specific audience claim.

func (*TestIssuer) Audience

func (ti *TestIssuer) Audience() string

Audience returns the audience configured for this test issuer.

func (*TestIssuer) Close

func (ti *TestIssuer) Close()

Close shuts down the test server.

func (*TestIssuer) CreateExpiredToken

func (ti *TestIssuer) CreateExpiredToken(userID, email string) string

CreateExpiredToken creates a token that has already expired. Useful for testing token expiration handling.

func (*TestIssuer) CreateToken

func (ti *TestIssuer) CreateToken(userID, email string) string

CreateToken creates a signed JWT token for testing. The token is signed with the test issuer's private key and will validate against the JWKS served by this issuer.

func (*TestIssuer) CreateTokenWithClaims

func (ti *TestIssuer) CreateTokenWithClaims(userID, email string, extraClaims map[string]any) string

CreateTokenWithClaims creates a signed JWT token with additional custom claims. The custom claims are merged with the standard claims (sub, email, iss, aud, exp, iat).

func (*TestIssuer) CreateTokenWithExpiry

func (ti *TestIssuer) CreateTokenWithExpiry(userID, email string, expiry time.Time) string

CreateTokenWithExpiry creates a signed JWT token with a custom expiry time.

func (*TestIssuer) CreateTokenWithRoles

func (ti *TestIssuer) CreateTokenWithRoles(userID, email string, roles []string) string

CreateTokenWithRoles creates a signed JWT token with role claims.

func (*TestIssuer) URL

func (ti *TestIssuer) URL() string

URL returns the base URL of the test issuer server. Use this as the issuer in your auth configuration.

Jump to

Keyboard shortcuts

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