Documentation
¶
Overview ¶
Package authtest provides synthetic deterministic fixtures via Principal, NewClock/NewAuthenticator and HTTP helpers. Callers own fixture/error privacy, request mutation and any body lifecycle. These helpers are not hostile- collaborator or provider-conformance guarantees; scripted state is serialized.
Index ¶
- Variables
- func Principal(testing TestingT, spec authentication.PrincipalSpec) authentication.Principal
- func RequireFailure(testing TestingT, err error, kind authentication.FailureKind)
- func RequirePrincipal(testing TestingT, ctx context.Context, subject string)
- func Result(testing TestingT, spec authentication.PrincipalSpec) authentication.Result
- type Authenticator
- type Call
- type Clock
- type HTTPFixture
- type Outcome
- type TestingT
Constants ¶
This section is empty.
Variables ¶
var Epoch = time.Unix(0, 0).UTC()
Epoch is the mutable default fixture timestamp. Set it only before concurrent fixture use; the package does not synchronize writes to this exported variable.
Functions ¶
func Principal ¶
func Principal(testing TestingT, spec authentication.PrincipalSpec) authentication.Principal
Principal constructs a tested principal and supplies Epoch when no authentication time was specified.
func RequireFailure ¶
func RequireFailure(testing TestingT, err error, kind authentication.FailureKind)
RequireFailure requires a classified authentication failure.
func RequirePrincipal ¶
RequirePrincipal requires an authenticated subject in ctx.
func Result ¶
func Result(testing TestingT, spec authentication.PrincipalSpec) authentication.Result
Result constructs a tested authenticated result.
Types ¶
type Authenticator ¶
type Authenticator struct {
// contains filtered or unexported fields
}
Authenticator serializes scripted outcomes and call recording under an instance mutex. It borrows errors and trusts credential.Kind: that callback runs under the mutex and must not block, panic or reenter this fixture. Custom kinds are not redacted; fixtures must remain synthetic/non-secret.
func NewAuthenticator ¶
func NewAuthenticator(outcomes ...Outcome) *Authenticator
NewAuthenticator creates a deterministic scripted authenticator.
func (*Authenticator) Authenticate ¶
func (a *Authenticator) Authenticate(ctx context.Context, credential authentication.Credential) (authentication.Result, error)
Authenticate records Kind before checking cancellation, then consumes one outcome only for an active context. Empty scripts fail unavailable; nil credential is recorded with empty kind. Nil context/provider panics propagate. Calls/outcomes are serialized, but no general collaborator recovery is provided.
func (*Authenticator) Calls ¶
func (a *Authenticator) Calls() []Call
Calls returns a copy of recorded non-secret call metadata.
type Call ¶
type Call struct {
// Kind is raw caller routing metadata, not confidentiality-screened.
Kind authentication.CredentialKind
}
Call records only credential kind, never credential contents. Custom Kind strings remain caller-asserted non-secret fixture data.
type Clock ¶
type Clock struct {
// contains filtered or unexported fields
}
Clock is a concurrency-safe deterministic clock.
type HTTPFixture ¶
type HTTPFixture struct {
// Request is the caller-owned mutable httptest request; it may retain the supplied body.
Request *http.Request
// Recorder is the caller-owned mutable response recorder, not concurrent-safe.
Recorder *httptest.ResponseRecorder
}
HTTPFixture contains a real request and response recorder.
func NewHTTPFixture ¶
func NewHTTPFixture(method, target string, body io.Reader) HTTPFixture
NewHTTPFixture creates a deterministic real HTTP fixture.
type Outcome ¶
type Outcome struct {
// Result is the immutable scripted result returned unchanged.
Result authentication.Result
// Err is a borrowed scripted error, not automatically sanitized by fixtures.
Err error
}
Outcome is one scripted authentication result.
type TestingT ¶
type TestingT interface {
// Helper marks assertion call sites without changing the scripted result.
Helper()
// Fatalf reports a trusted-fixture assertion failure; conventional tests stop
// execution, but construction helpers return zero values if Fatalf returns.
Fatalf(string, ...any)
}
TestingT is the subset of testing.TB required by fixture assertions.