Documentation
¶
Overview ¶
Package exec builds HTTP requests from cases and sends them (FR-HTTP).
Index ¶
- func Base(baseURL, serverURL, specBasePath string) (base, warning string, err error)
- func IsWrite(method string) bool
- func WaitReady(ctx context.Context, client *http.Client, base, healthPath string, ...) error
- func WritesAllowed(base string, allowed []string) bool
- type Auth
- type Input
- type NotBuildableError
- type Placement
- type Prepared
- type Response
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Base ¶
Base returns the base URL for requests (FR-HTTP-06).
With a configured BaseURL it replaces the spec's servers entirely; a warning is returned if the servers' base path is missing from it. With an in-process handler (serverURL set, baseURL empty) the servers' base path is appended, because the application is expected to serve its routes there.
func WaitReady ¶
func WaitReady(ctx context.Context, client *http.Client, base, healthPath string, limit time.Duration) error
WaitReady waits until the API answers (FR-HTTP-04). Without healthPath any HTTP response on "/" counts; with healthPath a 2xx is required. Only connection errors and non-2xx health responses are retried.
func WritesAllowed ¶
WritesAllowed reports whether writing requests may go to base (NFR-07): localhost, loopback addresses and hosts in allowed are permitted.
Types ¶
type Auth ¶
type Auth struct {
// Placements is empty if the operation needs no token (FR-AUTH-04).
Placements []Placement
// Unsupported explains why no requirement can be fulfilled.
Unsupported string
}
Auth is the resolved authentication of an operation.
func ResolveAuth ¶
func ResolveAuth(reqs openapi3.SecurityRequirements, schemes openapi3.SecuritySchemes) Auth
ResolveAuth picks the first security requirement whose schemes are all supported (FR-AUTH-01, FR-AUTH-05). An empty requirement list or an empty requirement means no authentication.
type Input ¶
type Input struct {
Base string // base URL without trailing slash
Params params.Inputs
Auth Auth
Token string // used if Auth.Needed()
Headers map[string]string
}
Input is everything Prepare needs besides the case.
type NotBuildableError ¶
type NotBuildableError struct{ Reason string }
NotBuildableError reports that a case cannot be sent (FR-CASE-06).
func (*NotBuildableError) Error ¶
func (e *NotBuildableError) Error() string
type Placement ¶
type Placement struct {
In string // "header", "query" or "cookie"
Name string // header, parameter or cookie name
// Bearer is set for "Authorization: Bearer <token>".
Bearer bool
}
Placement is where a token goes in a request.
func AllPlacements ¶
func AllPlacements(schemes openapi3.SecuritySchemes) []Placement
AllPlacements lists every placement defined by the spec's schemes, so that redaction knows all header, query and cookie names carrying tokens.
type Prepared ¶
type Prepared struct {
Method string
URL string // absolute URL
Target string // path and query, relative to the base URL, for display
Header http.Header
Body []byte
Auth Auth // where the token went; used to build curl commands
}
Prepared is a request ready to be sent.