Documentation
¶
Index ¶
- type CompositeFixtureProvider
- type Fixture
- type FixtureProvider
- type FixtureRequest
- type FixtureSet
- type FuncProvider
- type HTTPFixtureRule
- type JWKSFixture
- func (f *JWKSFixture) Clock() clock.Clock
- func (f *JWKSFixture) CreateAndSignToken(claims map[string]interface{}) (string, error)
- func (f *JWKSFixture) CreateAndSignTokenWithExpiry(claims map[string]interface{}, expiry time.Time) (string, error)
- func (f *JWKSFixture) GetFixture(req *http.Request) *Fixture
- func (f *JWKSFixture) Issuer() string
- func (f *JWKSFixture) JWKSURL() string
- func (f *JWKSFixture) KeyID() string
- func (f *JWKSFixture) SignToken(token jwt.Token) (string, error)
- type JWKSFixtureConfig
- type MapProvider
- type RuleBasedProvider
- type Transport
- type TransportConfig
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CompositeFixtureProvider ¶
type CompositeFixtureProvider struct {
// contains filtered or unexported fields
}
CompositeFixtureProvider composes multiple fixture providers and provides direct access to specific fixture types (e.g., JWKS fixtures by issuer)
func NewCompositeFixtureProvider ¶
func NewCompositeFixtureProvider(providers []FixtureProvider, jwksFixtures map[string]*JWKSFixture) *CompositeFixtureProvider
NewCompositeFixtureProvider creates a composite fixture provider
func (*CompositeFixtureProvider) GetFixture ¶
func (c *CompositeFixtureProvider) GetFixture(req *http.Request) *Fixture
GetFixture implements FixtureProvider by trying each provider in order
func (*CompositeFixtureProvider) JWKSFixture ¶
func (c *CompositeFixtureProvider) JWKSFixture(issuer string) *JWKSFixture
JWKSFixture returns a JWKS fixture by issuer, or nil if not found
type Fixture ¶
type Fixture struct {
StatusCode int `json:"status" yaml:"status"`
Headers map[string]string `json:"headers,omitempty" yaml:"headers,omitempty"`
Body string `json:"body" yaml:"body"`
Delay *time.Duration `json:"delay,omitempty" yaml:"delay,omitempty"`
}
Fixture defines an HTTP response to return for requests
type FixtureProvider ¶
FixtureProvider returns a fixture for a request, or nil if no fixture applies
type FixtureRequest ¶
type FixtureRequest struct {
Method string `json:"method" yaml:"method"` // e.g., "GET", "POST", "*" for any
URL string `json:"url" yaml:"url"` // exact match or pattern
URLType string `json:"url_type,omitempty" yaml:"url_type,omitempty"` // "exact" (default) or "pattern"
Headers map[string]string `json:"headers,omitempty" yaml:"headers,omitempty"` // optional header matching
}
FixtureRequest defines request matching criteria (for file-based fixtures)
type FixtureSet ¶
type FixtureSet struct {
Rules []HTTPFixtureRule `json:"fixtures" yaml:"fixtures"`
}
FixtureSet is a collection of fixture rules (for file loading)
type FuncProvider ¶
type FuncProvider struct {
// contains filtered or unexported fields
}
FuncProvider uses a function to provide fixtures (most flexible)
func NewFuncProvider ¶
func NewFuncProvider(fn func(*http.Request) *Fixture) *FuncProvider
NewFuncProvider creates a new function-based fixture provider
func (*FuncProvider) GetFixture ¶
func (p *FuncProvider) GetFixture(req *http.Request) *Fixture
GetFixture returns a fixture by calling the provided function
type HTTPFixtureRule ¶
type HTTPFixtureRule struct {
Request FixtureRequest `json:"request" yaml:"request"`
Response Fixture `json:"response" yaml:"response"`
}
HTTPFixtureRule defines request criteria and corresponding response (for file-based fixtures)
type JWKSFixture ¶
type JWKSFixture struct {
// contains filtered or unexported fields
}
JWKSFixture is a specialized HTTP fixture that serves a JWKS endpoint and provides a signing API for creating test tokens with corresponding private keys
func NewJWKSFixture ¶
func NewJWKSFixture(cfg JWKSFixtureConfig) (*JWKSFixture, error)
NewJWKSFixture creates a new JWKS fixture with a generated RSA key pair
func (*JWKSFixture) Clock ¶
func (f *JWKSFixture) Clock() clock.Clock
Clock returns the clock used by this fixture
func (*JWKSFixture) CreateAndSignToken ¶
func (f *JWKSFixture) CreateAndSignToken(claims map[string]interface{}) (string, error)
CreateAndSignToken creates a new JWT with the given claims and signs it The issuer, issued-at, and expiration claims are set automatically using the fixture's clock
func (*JWKSFixture) CreateAndSignTokenWithExpiry ¶
func (f *JWKSFixture) CreateAndSignTokenWithExpiry(claims map[string]interface{}, expiry time.Time) (string, error)
CreateAndSignTokenWithExpiry creates a new JWT with the given claims and custom expiry, and signs it Uses the fixture's clock for the issued-at claim
func (*JWKSFixture) GetFixture ¶
func (f *JWKSFixture) GetFixture(req *http.Request) *Fixture
GetFixture implements FixtureProvider interface Returns a fixture for JWKS URL requests
func (*JWKSFixture) JWKSURL ¶
func (f *JWKSFixture) JWKSURL() string
JWKSURL returns the JWKS URL this fixture serves
type JWKSFixtureConfig ¶
type JWKSFixtureConfig struct {
// Issuer is the issuer URL (for iss claim)
Issuer string
// JWKSURL is the URL where the JWKS will be served
JWKSURL string
// KeyID is the key identifier (kid)
// If empty, defaults to "test-key-1"
KeyID string
// Algorithm is the signing algorithm
// If zero value, defaults to RS256
Algorithm jwa.SignatureAlgorithm
// Clock is the time source for token timestamps
// If nil, uses system clock
Clock clock.Clock
// PrivateKeyPEM is optional PEM-encoded RSA private key material.
// When set, the fixture uses this key instead of generating a new one.
PrivateKeyPEM []byte
// PrivateKeyFile is a path to a PEM-encoded RSA private key file.
PrivateKeyFile string
}
JWKSFixtureConfig configures a JWKS fixture
type MapProvider ¶
type MapProvider struct {
// contains filtered or unexported fields
}
MapProvider provides fixtures based on a simple map lookup (method+URL key)
func NewMapProvider ¶
func NewMapProvider(fixtures map[string]*Fixture) *MapProvider
NewMapProvider creates a new map-based fixture provider Key format: "METHOD URL" (e.g., "GET https://api.example.com/user/alice")
func (*MapProvider) GetFixture ¶
func (p *MapProvider) GetFixture(req *http.Request) *Fixture
GetFixture returns a fixture for the given request based on method+URL key
type RuleBasedProvider ¶
type RuleBasedProvider struct {
// contains filtered or unexported fields
}
RuleBasedProvider matches requests against a set of rules
func LoadFixturesFromDir ¶
func LoadFixturesFromDir(dir string) (*RuleBasedProvider, error)
LoadFixturesFromDir loads all fixture files from a directory
func LoadFixturesFromFile ¶
func LoadFixturesFromFile(path string) (*RuleBasedProvider, error)
LoadFixturesFromFile loads fixtures from a JSON or YAML file
func NewRuleBasedProvider ¶
func NewRuleBasedProvider(rules []HTTPFixtureRule) *RuleBasedProvider
NewRuleBasedProvider creates a new rule-based fixture provider
func (*RuleBasedProvider) GetFixture ¶
func (p *RuleBasedProvider) GetFixture(req *http.Request) *Fixture
GetFixture returns a fixture for the given request if any rule matches
type Transport ¶
type Transport struct {
// contains filtered or unexported fields
}
Transport implements http.RoundTripper using a FixtureProvider
func NewTransport ¶
func NewTransport(config TransportConfig) *Transport
NewTransport creates a new fixture transport
type TransportConfig ¶
type TransportConfig struct {
Provider FixtureProvider
Fallback http.RoundTripper // optional fallback transport
Strict bool // if true, error when provider returns nil
Clock clock.Clock // optional clock for delays (defaults to system clock)
}
TransportConfig configures the fixture transport