Documentation
¶
Overview ¶
Package admin0 exposes the mock's control-plane endpoints under /admin0/*.
These endpoints are NEVER authenticated — they're meant for test setup and teardown from outside the bearer-protected Mgmt API surface.
Index ¶
- Variables
- func Mount(r chi.Router, d Deps)
- type AdvanceClockHandler
- type DeleteAllPermissionsHandler
- type DeleteAuthorizeErrorByIDHandler
- type DeleteAuthorizeErrorsHandler
- type DeleteClaimMappingsHandler
- type DeleteClaimsHandler
- type DeleteClockHandler
- type DeleteExpectationByIDHandler
- type DeleteExpectationsHandler
- type DeleteJournalHandler
- type DeletePermissionsHandler
- type Deps
- type EventsPublisher
- type ExpireEventsHandler
- type GetAllPermissionsHandler
- type GetClaimMappingsHandler
- type GetClaimsHandler
- type GetClockHandler
- type GetEventSubscribersHandler
- type GetExpectationByIDHandler
- type GetMFARequiredHandler
- type GetPermissionsHandler
- type ListAuthorizeErrorsHandler
- type ListExpectationsHandler
- type ListJournalHandler
- type ListUnmatchedJournalHandler
- type PostAuthorizeErrorHandler
- type PostEventsHandler
- type PostExpectationHandler
- type PutClaimMappingsHandler
- type PutClaimsHandler
- type PutClockHandler
- type PutMFARequiredHandler
- type PutPermissionsHandler
- type ResetHandler
Constants ¶
This section is empty.
Variables ¶
var Fragment []byte
Fragment is the per-package OpenAPI 3.1 partial document describing every /admin0/* route registered in this package's Mount function. The genopenapi bundler merges it with the base Mgmt API spec to produce api/auth0-mock.openapi.json.
Functions ¶
Types ¶
type AdvanceClockHandler ¶ added in v0.227.0
type AdvanceClockHandler struct {
Clock *clock.Controlled
}
AdvanceClockHandler mutates the held value by `by`. Returns 400 invalid_clock_state when the clock is in real mode.
func (*AdvanceClockHandler) ServeHTTP ¶ added in v0.227.0
func (h *AdvanceClockHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)
type DeleteAllPermissionsHandler ¶
type DeleteAllPermissionsHandler struct {
Store *permissions.Store
}
DeleteAllPermissionsHandler removes every audience's permissions.
func (*DeleteAllPermissionsHandler) ServeHTTP ¶
func (h *DeleteAllPermissionsHandler) ServeHTTP(w http.ResponseWriter, _ *http.Request)
type DeleteAuthorizeErrorByIDHandler ¶ added in v0.233.0
type DeleteAuthorizeErrorByIDHandler struct {
Store *authorizeerr.Store
}
DeleteAuthorizeErrorByIDHandler removes one rule; an unknown ID is a no-op.
func (*DeleteAuthorizeErrorByIDHandler) ServeHTTP ¶ added in v0.233.0
func (h *DeleteAuthorizeErrorByIDHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)
type DeleteAuthorizeErrorsHandler ¶ added in v0.233.0
type DeleteAuthorizeErrorsHandler struct {
Store *authorizeerr.Store
}
DeleteAuthorizeErrorsHandler removes every rule.
func (*DeleteAuthorizeErrorsHandler) ServeHTTP ¶ added in v0.233.0
func (h *DeleteAuthorizeErrorsHandler) ServeHTTP(w http.ResponseWriter, _ *http.Request)
type DeleteClaimMappingsHandler ¶ added in v0.231.0
type DeleteClaimMappingsHandler struct {
Store *claims.MappingStore
}
DeleteClaimMappingsHandler clears every mapping.
func (*DeleteClaimMappingsHandler) ServeHTTP ¶ added in v0.231.0
func (h *DeleteClaimMappingsHandler) ServeHTTP(w http.ResponseWriter, _ *http.Request)
type DeleteClaimsHandler ¶
DeleteClaimsHandler clears every custom claim.
func (*DeleteClaimsHandler) ServeHTTP ¶
func (h *DeleteClaimsHandler) ServeHTTP(w http.ResponseWriter, _ *http.Request)
type DeleteClockHandler ¶ added in v0.227.0
type DeleteClockHandler struct {
Clock *clock.Controlled
}
DeleteClockHandler restores the clock to real mode.
func (*DeleteClockHandler) ServeHTTP ¶ added in v0.227.0
func (h *DeleteClockHandler) ServeHTTP(w http.ResponseWriter, _ *http.Request)
type DeleteExpectationByIDHandler ¶ added in v0.226.0
DeleteExpectationByIDHandler removes a single expectation by its store-assigned ID. The route is /admin0/expectations/{id}; chi extracts the id parameter. Idempotent — deleting an unknown id is a 204 no-op, same as the bulk DELETE on an unregistered operation.
func (*DeleteExpectationByIDHandler) ServeHTTP ¶ added in v0.226.0
func (h *DeleteExpectationByIDHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)
type DeleteExpectationsHandler ¶
DeleteExpectationsHandler clears expectations. An empty body clears all; a {method, path} body clears every expectation registered for that operation (the catch-all and every request-matched one).
Two intentional behaviours worth noting:
- An empty/whitespace-only body means "clear all". The read error from io.ReadAll is deliberately ignored: a failed or empty read falls through to ResetAll, which is a benign outcome for a teardown DELETE.
- Clearing an operation that was never registered is an idempotent no-op (returns 204). ResetEndpoint is documented as a no-op for unregistered keys, and DELETE intentionally does NOT validate {method, path} against the spec (unlike POST) because teardown should be forgiving.
func (*DeleteExpectationsHandler) ServeHTTP ¶
func (h *DeleteExpectationsHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)
type DeleteJournalHandler ¶ added in v0.233.0
DeleteJournalHandler empties the journal.
func (*DeleteJournalHandler) ServeHTTP ¶ added in v0.233.0
func (h *DeleteJournalHandler) ServeHTTP(w http.ResponseWriter, _ *http.Request)
type DeletePermissionsHandler ¶
type DeletePermissionsHandler struct {
Store *permissions.Store
}
DeletePermissionsHandler clears the permissions for one audience.
func (*DeletePermissionsHandler) ServeHTTP ¶
func (h *DeletePermissionsHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)
type Deps ¶
type Deps struct {
Matches *matches.Store
Claims *claims.Store
ClaimMappings *claims.MappingStore
// Sessions is cleared by /admin0/reset. Nil is fine.
Sessions *session.Store
// AuthorizeErrors holds the /authorize failure rules. Nil is defaulted
// to an empty store by Mount.
AuthorizeErrors *authorizeerr.Store
Permissions *permissions.Store
MFA *mfa.Store
Validator *spec.Validator
Clock *clock.Controlled
// Events is the SSE hub for POST /admin0/events. Nil is fine for
// admin0 tests that don't exercise the events surface — the route
// only registers when both Events and Validator are non-nil, and
// reset's shutdown call is skipped.
Events EventsPublisher
// Journal backs /admin0/journal*. Nil is defaulted to a disabled
// journal (size 0) by Mount.
Journal *journal.Journal
}
Deps groups the in-memory stores admin0 controls.
type EventsPublisher ¶ added in v0.228.0
type EventsPublisher interface {
Publish(events.Event) error
Reset(context.Context) error
// ActiveSubscribers / TotalSubscribers back GET
// /admin0/events/subscribers so tests can observe the SSE
// connection lifecycle (e.g. assert a stream closed cleanly).
ActiveSubscribers() int
TotalSubscribers() int
// ExpireAll / ExpireBefore back POST /admin0/events/expire, the
// narrow counterpart to Reset: they age out replay cursors and
// nothing else. Two methods rather than one with an empty-string
// sentinel, so "expire everything" can only ever be said on purpose.
// ExpireBefore's second return says whether the buffer held the
// cursor; the handler turns a false into 404 rather than a success
// that expired nothing.
ExpireAll() int
ExpireBefore(cursor string) (dropped int, found bool)
}
EventsPublisher is the seam between the /admin0/events handler and the SSE hub. The concrete implementation is *events.Hub; tests use fakes that record calls. Reset is on the interface because the ResetHandler drains the SSE state between tests via this hook (without permanently destroying the hub).
type ExpireEventsHandler ¶ added in v0.232.0
type ExpireEventsHandler struct {
Events EventsPublisher
}
ExpireEventsHandler ages out cursors in the SSE replay buffer so a test can provoke the 410 Gone / event_aged_out path on demand, instead of pushing past the buffer's capacity to force natural eviction or reaching for /admin0/reset (which also drops every other store and disconnects subscribers).
`?before=<cursor>` expires everything older than that cursor and keeps the cursor itself resumable; without it the whole buffer goes. Subscribers that are already streaming are untouched — expiry only affects future resumes.
Responds 200 with {"expired": <count>}: the number of cursors dropped. Repeating a `?before` call is safe and still answers 200 — the boundary cursor survives its own expiry, so the second call finds it and drops 0.
A cursor the buffer doesn't hold is 404 / cursor_not_found rather than a 200 that expired nothing, because {"expired": 0} cannot say which of the two it meant. A test that mistypes an offset would otherwise be told its expiry worked and fail several steps later, on the reconnect that got 200 where it asserted 410. The same 404 answers when the mock was started with replay disabled: there is no buffer holding that cursor either.
func (*ExpireEventsHandler) ServeHTTP ¶ added in v0.232.0
func (h *ExpireEventsHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)
type GetAllPermissionsHandler ¶
type GetAllPermissionsHandler struct {
Store *permissions.Store
}
GetAllPermissionsHandler returns the full per-audience permission map.
func (*GetAllPermissionsHandler) ServeHTTP ¶
func (h *GetAllPermissionsHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)
type GetClaimMappingsHandler ¶ added in v0.231.0
type GetClaimMappingsHandler struct {
Store *claims.MappingStore
}
GetClaimMappingsHandler returns the request-parameter → claim-name map that /oauth/token projects into minted tokens.
func (*GetClaimMappingsHandler) ServeHTTP ¶ added in v0.231.0
func (h *GetClaimMappingsHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)
type GetClaimsHandler ¶
GetClaimsHandler returns the per-process custom-claim map.
func (*GetClaimsHandler) ServeHTTP ¶
func (h *GetClaimsHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)
type GetClockHandler ¶ added in v0.227.0
type GetClockHandler struct {
Clock *clock.Controlled
}
GetClockHandler reports the current clock mode and resolved Now.
func (*GetClockHandler) ServeHTTP ¶ added in v0.227.0
func (h *GetClockHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)
type GetEventSubscribersHandler ¶ added in v0.229.0
type GetEventSubscribersHandler struct {
Events EventsPublisher
}
GetEventSubscribersHandler reports the SSE hub's live and lifetime-within-window subscriber counts. Intended for tests that assert on connection lifecycle — e.g. "after closing my stream, active drops back to 0". Active is eventually-consistent: the hub removes a subscriber when the server observes its connection close, so poll until it settles rather than asserting immediately.
func (*GetEventSubscribersHandler) ServeHTTP ¶ added in v0.229.0
func (h *GetEventSubscribersHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)
type GetExpectationByIDHandler ¶ added in v0.226.0
GetExpectationByIDHandler returns a single expectation by its store-assigned ID with its current Hits counter populated. Used by the SDK's RegisteredExpectation.Hits(ctx). 404 (unknown_id) when no such expectation exists — distinguishes "cleared" from "never hit" for the caller.
func (*GetExpectationByIDHandler) ServeHTTP ¶ added in v0.226.0
func (h *GetExpectationByIDHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)
type GetMFARequiredHandler ¶
GetMFARequiredHandler reports whether the password and password-realm grants currently demand MFA step-up.
func (*GetMFARequiredHandler) ServeHTTP ¶
func (h *GetMFARequiredHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)
type GetPermissionsHandler ¶
type GetPermissionsHandler struct {
Store *permissions.Store
}
GetPermissionsHandler returns the permissions registered for one audience.
func (*GetPermissionsHandler) ServeHTTP ¶
func (h *GetPermissionsHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)
type ListAuthorizeErrorsHandler ¶ added in v0.233.0
type ListAuthorizeErrorsHandler struct {
Store *authorizeerr.Store
}
ListAuthorizeErrorsHandler returns every rule in registration order.
func (*ListAuthorizeErrorsHandler) ServeHTTP ¶ added in v0.233.0
func (h *ListAuthorizeErrorsHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)
type ListExpectationsHandler ¶
ListExpectationsHandler returns every registered expectation.
func (*ListExpectationsHandler) ServeHTTP ¶
func (h *ListExpectationsHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)
type ListJournalHandler ¶ added in v0.233.0
ListJournalHandler returns every recorded /api/v2 call, oldest first, optionally narrowed by ?method= and ?path=.
func (*ListJournalHandler) ServeHTTP ¶ added in v0.233.0
func (h *ListJournalHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)
type ListUnmatchedJournalHandler ¶ added in v0.233.0
ListUnmatchedJournalHandler returns only the calls no stub matched.
func (*ListUnmatchedJournalHandler) ServeHTTP ¶ added in v0.233.0
func (h *ListUnmatchedJournalHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)
type PostAuthorizeErrorHandler ¶ added in v0.233.0
type PostAuthorizeErrorHandler struct {
Store *authorizeerr.Store
}
PostAuthorizeErrorHandler registers a rule that makes /authorize fail.
func (*PostAuthorizeErrorHandler) ServeHTTP ¶ added in v0.233.0
func (h *PostAuthorizeErrorHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)
type PostEventsHandler ¶ added in v0.228.0
type PostEventsHandler struct {
Events EventsPublisher
Validator *spec.Validator
}
PostEventsHandler validates an incoming Auth0 event-stream envelope against the OpenAPI text/event-stream schema for GET /events and pushes it into the SSE hub. Responds 202 Accepted with {"id": "<inner-cloudevent-id>"} on success. Validation failures use the standard mgmt error envelope.
func (*PostEventsHandler) ServeHTTP ¶ added in v0.228.0
func (h *PostEventsHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)
type PostExpectationHandler ¶
PostExpectationHandler registers (upserts) an expectation for the Management API operation identified by {method, path}.
func (*PostExpectationHandler) ServeHTTP ¶
func (h *PostExpectationHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)
type PutClaimMappingsHandler ¶ added in v0.231.0
type PutClaimMappingsHandler struct {
Store *claims.MappingStore
}
PutClaimMappingsHandler replaces the mapping with the JSON object in the request body ({"<request parameter>": "<claim name>", ...}). An empty object turns the projection off.
func (*PutClaimMappingsHandler) ServeHTTP ¶ added in v0.231.0
func (h *PutClaimMappingsHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)
type PutClaimsHandler ¶
PutClaimsHandler replaces the per-process custom-claim map with the JSON object in the request body.
func (*PutClaimsHandler) ServeHTTP ¶
func (h *PutClaimsHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)
type PutClockHandler ¶ added in v0.227.0
type PutClockHandler struct {
Clock *clock.Controlled
}
PutClockHandler freezes the clock to a specific instant or switches it into offset mode. Body must contain exactly one of `now` / `offset`.
func (*PutClockHandler) ServeHTTP ¶ added in v0.227.0
func (h *PutClockHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)
type PutMFARequiredHandler ¶
PutMFARequiredHandler toggles MFA enforcement at runtime. Body: {"required":true|false}.
func (*PutMFARequiredHandler) ServeHTTP ¶
func (h *PutMFARequiredHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)
type PutPermissionsHandler ¶
type PutPermissionsHandler struct {
Store *permissions.Store
}
PutPermissionsHandler sets the permissions for one audience to the JSON array in the request body.
func (*PutPermissionsHandler) ServeHTTP ¶
func (h *PutPermissionsHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)
type ResetHandler ¶
type ResetHandler struct {
Deps Deps
}
ResetHandler wipes every store admin0 governs: registered matches, custom claims, claim mappings, remembered user sessions, authorize error rules, per-audience permissions, and the MFA flag; it also restores the clock to real mode and resets the SSE events hub (drains subscribers, clears the replay buffer, zeroes counters).
func (*ResetHandler) ServeHTTP ¶
func (h *ResetHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)