testutil

package
v1.8.0 Latest Latest
Warning

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

Go to latest
Published: Oct 15, 2026 License: Apache-2.0 Imports: 23 Imported by: 0

Documentation

Overview

Package testutil holds test fixtures shared by the jws, identity and resolver packages: key generators, PEM and certificate helpers, a fake fetcher, key assertions, and the sign-resolve-verify claim flow. It imports jws and identity, so their tests must be external (package jws_test).

Index

Constants

View Source
const (

	// SVIDSubject is the SPIFFE ID the test certificates carry by default.
	SVIDSubject = "spiffe://acme.com/agents/finance"

	// RecordCID is the record every test claim is attached to.
	RecordCID = "bafybeigdyrzt5sfp7udm7hu76uh7y26nf3efuylqabf3oclgtqy55fbzdi"
)

Variables

This section is empty.

Functions

func CertificatePEM

func CertificatePEM(der []byte) []byte

CertificatePEM encodes a DER certificate as a PEM block.

func EdPublic

func EdPublic(t *testing.T, key ed25519.PrivateKey) ed25519.PublicKey

EdPublic returns the public half of key as an ed25519.PublicKey.

func JWKS

func JWKS(t *testing.T, keys ...crypto.PublicKey) []byte

JWKS serializes the public halves of keys as a JWKS document.

func NewECKey

func NewECKey(t *testing.T, curve elliptic.Curve) *ecdsa.PrivateKey

NewECKey generates an ECDSA key on curve.

func NewEdKey

func NewEdKey(t *testing.T) ed25519.PrivateKey

NewEdKey generates an Ed25519 key.

func NewKey

func NewKey(t *testing.T, kind string) crypto.Signer

NewKey generates a signing key of the given kind: ES256, ES384, EdDSA or RS256.

func NewRSAKey

func NewRSAKey(t *testing.T) *rsa.PrivateKey

NewRSAKey generates a 2048-bit RSA key.

func NewSmallRSAKey

func NewSmallRSAKey(t *testing.T) *rsa.PrivateKey

NewSmallRSAKey generates a 1024-bit RSA key, below the size jws accepts.

func PKCS8PEM

func PKCS8PEM(t *testing.T, key crypto.PrivateKey) []byte

PKCS8PEM encodes key as an unencrypted PKCS#8 PEM block.

func RequireSameKeys

func RequireSameKeys(t *testing.T, want, got []crypto.PublicKey)

RequireSameKeys asserts got holds exactly the wanted keys, in any order.

func SelfSignedCertPEM

func SelfSignedCertPEM(t *testing.T, key crypto.Signer, uriSAN string) []byte

SelfSignedCertPEM returns a self-signed certificate for key carrying uriSAN as its only URI SAN.

func SignedCertClaim

func SignedCertClaim(t *testing.T, subject string, key crypto.PrivateKey, certPEM []byte) *identityv1.Claim

SignedCertClaim signs a claim for subject that carries certPEM, the certificate of key.

func SignedClaim

func SignedClaim(t *testing.T, subject string, key crypto.PrivateKey) *identityv1.Claim

SignedClaim signs a fresh identity claim for subject the way a publisher would.

func VerifyClaim

func VerifyClaim(t *testing.T, r resolvers.Resolver, claim *identityv1.Claim) (bool, error)

VerifyClaim is the flow a real caller follows: resolve the subject's keys, then verify the claim against all of them.

Types

type FakeFetcher

type FakeFetcher struct {
	Docs      map[string][]byte
	Requested []string
}

FakeFetcher serves canned documents by URL and records what was requested.

func (*FakeFetcher) Get

func (f *FakeFetcher) Get(_ context.Context, url string) ([]byte, error)

Get implements resolvers.Fetcher.

Jump to

Keyboard shortcuts

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