authtest

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Aug 25, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package authtest provides deterministic authentication fixtures and assertions.

Index

Constants

This section is empty.

Variables

View Source
var Epoch = time.Unix(0, 0).UTC()

Epoch is the default deterministic authentication time used by fixtures.

Functions

func 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

func RequirePrincipal(testing TestingT, ctx context.Context, subject string)

RequirePrincipal requires an authenticated subject in ctx.

func Result

Result constructs a tested authenticated result.

Types

type Authenticator

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

Authenticator returns scripted outcomes in order and records redacted calls.

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 a non-secret call and consumes the next outcome.

func (*Authenticator) Calls

func (a *Authenticator) Calls() []Call

Calls returns a copy of recorded non-secret call metadata.

type Call

type Call struct{ Kind authentication.CredentialKind }

Call records only non-secret authentication call metadata.

func (Call) String

func (c Call) String() string

String returns a secret-free call description.

type Clock

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

Clock is a concurrency-safe deterministic clock.

func NewClock

func NewClock(instant time.Time) *Clock

NewClock creates a clock at instant.

func (*Clock) Advance

func (c *Clock) Advance(duration time.Duration) time.Time

Advance moves the clock by duration and returns the new instant.

func (*Clock) Now

func (c *Clock) Now() time.Time

Now returns the current deterministic instant.

type HTTPFixture

type HTTPFixture struct {
	Request  *http.Request
	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 authentication.Result
	Err    error
}

Outcome is one scripted authentication result.

type TestingT

type TestingT interface {
	Helper()
	Fatalf(string, ...any)
}

TestingT is the subset of testing.TB required by fixture assertions.

Jump to

Keyboard shortcuts

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