scenario

package
v0.234.0 Latest Latest
Warning

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

Go to latest
Published: Nov 11, 2026 License: MIT Imports: 36 Imported by: 0

Documentation

Overview

Package scenario holds the godog test harness: a per-scenario context that boots the auth0-mock service in-process on a random port and provides HTTP helpers for the .feature step files.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RegisterSteps

func RegisterSteps(sc *godog.ScenarioContext, c *Context)

RegisterSteps wires the .feature step phrases to Go functions.

Types

type Context

type Context struct {
	BaseURL    string
	Host       string // when set, every request carries this Host header
	BearerTok  string
	MFAToken   string // captured from a 403 mfa_required response.
	RefreshTok string // captured from a token response.
	LastResp   *http.Response
	LastBody   []byte
	SavedBody  []byte // set by "I save the response body".
	// SavedValues holds JSON values saved by name with "I save the response
	// JSON path".
	SavedValues map[string]string
	// SSEResp holds the response from a successful SSE subscription
	// so subsequent steps (push, deliver) can read frames from its
	// body without conflicting with assertions against LastResp.
	SSEResp *http.Response
	// contains filtered or unexported fields
}

Context is the per-scenario state passed to step definitions.

func New

func New(t *testing.T, sc *godog.ScenarioContext) *Context

New constructs a fresh Context, boots the service in-process on a random localhost port, and registers cleanup hooks via godog.

func (*Context) DeleteSeedFile added in v0.234.0

func (c *Context) DeleteSeedFile() error

DeleteSeedFile removes the seed file and polls once.

func (*Context) Do

func (c *Context) Do(method, path string, body string, withBearer bool)

Do sends an HTTP request and stores the response on the context.

func (*Context) DoForm

func (c *Context) DoForm(method, path string, form url.Values, withBearer bool)

DoForm sends a POST with application/x-www-form-urlencoded body.

func (*Context) DoFormWithAuthorization added in v0.233.0

func (c *Context) DoFormWithAuthorization(method, path string, form url.Values, authorization string)

DoFormWithAuthorization is DoForm with an explicit Authorization header value; empty sends none.

func (*Context) KeepCookies added in v0.233.0

func (c *Context) KeepCookies()

KeepCookies makes this scenario's later requests share one cookie jar.

func (*Context) MintBearer

func (c *Context) MintBearer()

MintBearer issues a token via the live /oauth/token endpoint.

func (*Context) MintVia added in v0.234.0

func (c *Context) MintVia(host string)

MintVia mints a user token through the live /oauth/token endpoint, sending the request with the given Host header, and stores it as the bearer. The whole token response is left in LastBody so its id_token can be reused.

func (*Context) ReplaceSeedFile added in v0.234.0

func (c *Context) ReplaceSeedFile(content string) error

ReplaceSeedFile saves content over the seed file the way an editor does (write a temp file, rename it over) and reloads it. Nothing sleeps: the harness runs no watcher and polls twice instead, as a changed file is acted on only once it has been seen on two consecutive polls.

func (*Context) RestartWithIssuer added in v0.234.0

func (c *Context) RestartWithIssuer(issuer string)

RestartWithIssuer stops the scenario's server and boots a fresh one on a new port with the given ISSUER_URL value (e.g. "auto"), repointing BaseURL.

func (*Context) RestartWithSeed added in v0.234.0

func (c *Context) RestartWithSeed(content string) error

RestartWithSeed stops the scenario's server and boots a fresh one whose SEED_FILE holds content. A seed that fails to load is returned as the error and leaves no server running.

func (*Context) VerifyAccessTokenAgainstJWKS

func (c *Context) VerifyAccessTokenAgainstJWKS(tok string) error

VerifyAccessTokenAgainstJWKS fetches the mock's JWKS and verifies the token's RS256 signature using golang-jwt + MicahParks/keyfunc.

Jump to

Keyboard shortcuts

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