testutil

package
v3.0.4 Latest Latest
Warning

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

Go to latest
Published: Aug 13, 2026 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package testuril helps setting up required data for testing, such as tokens, claims and verifiers.

Index

Constants

View Source
const InvalidSignatureToken = `` /* 628-byte string literal not displayed */
View Source
const SignatureAlgorithm = jose.RS256

Variables

View Source
var (
	WebKey jose.JSONWebKey
	Signer jose.Signer
)
View Source
var (
	ValidIssuer     = "local.com"
	ValidSubject    = "tim@local.com"
	ValidAudience   = []string{"unit", "test"}
	ValidAuthTime   = time.Now().Add(-time.Minute)       // authtime is always 1 minute in the past
	ValidExpiration = ValidAuthTime.Add(2 * time.Minute) // token is always 1 more minute available
	ValidJWTID      = "9876"
	ValidSessionID  = "08a5019c-17e1-4977-8f42-65a12843ea02"
	ValidNonce      = "12345"
	ValidACR        = "something"
	ValidAMR        = []string{"foo", "bar"}
	ValidClientID   = "555666"
	ValidSkew       = time.Second
)

These variables always result in a valid token

Functions

func ACRVerify

func ACRVerify(acr string) error

ACRVerify is a oidc.ACRVerifier func.

func NewAccessToken

func NewAccessToken(issuer, subject string, audience []string, expiration time.Time, jwtid, clientID string, skew time.Duration) (string, *oidc.AccessTokenClaims)

NewAcccessToken creates a new AccessTokenClaims with passed data and returns a signed token and claims.

func NewAccessTokenCustom

func NewAccessTokenCustom(issuer, subject string, audience []string, expiration time.Time, jwtid, clientID string, skew time.Duration, custom map[string]any) (string, *oidc.AccessTokenClaims)

func NewIDToken

func NewIDToken(issuer, subject string, audience []string, expiration, authTime time.Time, nonce string, acr string, amr []string, clientID string, skew time.Duration, atHash string) (string, *oidc.IDTokenClaims)

NewIDToken creates a new IDTokenClaims with passed data and returns a signed token and claims.

func NewIDTokenCustom

func NewIDTokenCustom(issuer, subject string, audience []string, expiration, authTime time.Time, nonce string, acr string, amr []string, clientID string, skew time.Duration, atHash string, custom map[string]any) (string, *oidc.IDTokenClaims)

func NewJWTProfileAssertion

func NewJWTProfileAssertion(issuer, clientID string, audience []string, issuedAt, expiration time.Time) (string, *oidc.JWTTokenRequest)

func NewLogoutToken added in v3.0.4

func NewLogoutToken(issuer, subject string, audience oidc.Audience, expiration time.Time, jwtID, sessionID string, skew time.Duration) (string, *oidc.LogoutTokenClaims)

NewLogoutToken creates a new LogoutTokenClaims with passed data and returns a signed token and claims. The returned claims are normalized to their unmarshaled form, so that assertions in tests will work.

func SignClaims added in v3.0.4

func SignClaims(claims any) string

SignClaims signs the passed claims with the reproducible test key and returns the compact serialized token. It can be used to create tokens with arbitrary (also invalid) claims.

func ValidAccessToken

func ValidAccessToken() (string, *oidc.AccessTokenClaims)

ValidAccessToken returns a token and claims that are in the token. It uses the Valid* global variables and the token always passes verification within the same test run.

func ValidIDToken

func ValidIDToken() (string, *oidc.IDTokenClaims)

ValidIDToken returns a token and claims that are in the token. It uses the Valid* global variables and the token will always pass verification.

func ValidJWTProfileAssertion

func ValidJWTProfileAssertion() (string, *oidc.JWTTokenRequest)

func ValidLogoutToken added in v3.0.4

func ValidLogoutToken() (string, *oidc.LogoutTokenClaims)

ValidLogoutToken returns a signed logout token and claims that are in the token. It carries a sid claim and no sub claim, uses the Valid* global variables and the token will always pass verification.

Types

type JWTProfileKeyStorage

type JWTProfileKeyStorage struct{}

func (JWTProfileKeyStorage) GetKeyByIDAndClientID

func (JWTProfileKeyStorage) GetKeyByIDAndClientID(ctx context.Context, keyID string, clientID string) (*jose.JSONWebKey, error)

type KeySet

type KeySet struct{}

KeySet implements oidc.Keys

func (KeySet) VerifySignature

func (KeySet) VerifySignature(ctx context.Context, jws *jose.JSONWebSignature) (payload []byte, err error)

VerifySignature implments op.KeySet.

Directories

Path Synopsis
Package gen allows generating of example tokens and claims.
Package gen allows generating of example tokens and claims.

Jump to

Keyboard shortcuts

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