Documentation
¶
Overview ¶
Package authtest provides deterministic authentication fixtures and assertions.
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 default deterministic authentication time used by fixtures.
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 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.
type Clock ¶
type Clock struct {
// contains filtered or unexported fields
}
Clock is a concurrency-safe deterministic clock.
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.