bakerytest

package
v0.0.0-...-fed95e0 Latest Latest
Warning

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

Go to latest
Published: Apr 30, 2016 License: LGPL-3.0 Imports: 11 Imported by: 0

Documentation

Overview

Package bakerytest provides test helper functions for the bakery.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Discharger

type Discharger struct {
	Service *bakery.Service
	// contains filtered or unexported fields
}

Discharger is a third-party caveat discharger suitable for testing. It listens on a local network port for discharge requests. It should be shut down by calling Close when done with.

func NewDischarger

func NewDischarger(
	locator bakery.PublicKeyLocator,
	checker func(req *http.Request, cond, arg string) ([]checkers.Caveat, error),
) *Discharger

NewDischarger returns a new third party caveat discharger which uses the given function to check caveats. The cond and arg arguments to the function are as returned by checkers.ParseCaveat.

If locator is non-nil, it will be used to find public keys for any third party caveats returned by the checker.

Calling this function has the side-effect of setting InsecureSkipVerify in http.DefaultTransport.TLSClientConfig until all the dischargers are closed.

func (*Discharger) Close

func (d *Discharger) Close()

Close shuts down the server. It may be called more than once on the same discharger.

func (*Discharger) Location

func (d *Discharger) Location() string

Location returns the location of the discharger, suitable for setting as the location in a third party caveat. This will be the URL of the server.

func (*Discharger) PublicKeyForLocation

func (d *Discharger) PublicKeyForLocation(loc string) (*bakery.PublicKey, error)

PublicKeyForLocation implements bakery.PublicKeyLocator.

type InteractiveDischarger

type InteractiveDischarger struct {
	Discharger
	Mux *http.ServeMux
	// contains filtered or unexported fields
}

InteractiveDischarger is a Discharger that always requires interraction to complete the discharge.

func NewInteractiveDischarger

func NewInteractiveDischarger(locator bakery.PublicKeyLocator, visitHandler http.Handler) *InteractiveDischarger

NewInteractiveDischarger returns a new InteractiveDischarger. The InteractiveDischarger will serve the following endpoints by default:

/discharge - always causes interaction to be required.
/publickey - gets the bakery public key.
/visit - delegates to visitHandler.
/wait - blocks waiting for the interaction to complete.

Additional endpoints may be added to Mux as necessary.

The /discharge endpoint generates a error with the code httpbakery.ErrInterractionRequired. The visitURL and waitURL will point to the /visit and /wait endpoints of the InteractiveDischarger respectively. These URLs will also carry context information in query parameters, any handlers should be careful to preserve this context information between calls. The easiest way to do this is to always use the URL method when generating new URLs.

The /visit endpoint is handled by the provided visitHandler. This handler performs the required interactions and should result in the FinishInteraction method being called. This handler may process the interaction in a number of steps, possibly using additional handlers, so long as FinishInteraction is called when no further interaction is required.

The /wait endpoint blocks until FinishInteraction has been called by the corresponding /visit endpoint, or another endpoint triggered by visitHandler.

If locator is non-nil, it will be used to find public keys for any third party caveats returned by the checker.

Calling this function has the side-effect of setting InsecureSkipVerify in http.DefaultTransport.TLSClientConfig until all the dischargers are closed.

The returned InteractiveDischarger must be closed when finished with.

func (*InteractiveDischarger) FinishInteraction

func (d *InteractiveDischarger) FinishInteraction(w http.ResponseWriter, r *http.Request, cavs []checkers.Caveat, err error)

FinishInteraction signals to the InteractiveDischarger that a particular interaction is complete. It causes any waiting requests to return. If err is not nil then it will be returned by the corresponding /wait request.

func (*InteractiveDischarger) HostRelativeURL

func (d *InteractiveDischarger) HostRelativeURL(path string, r *http.Request) string

HostRelativeURL is like URL but includes only the URL path and query parameters. Use this when returning a URL for use in GetInteractionMethods.

func (*InteractiveDischarger) URL

func (d *InteractiveDischarger) URL(path string, r *http.Request) string

URL returns a URL addressed to the given path in the discharger that contains any discharger context information found in the given request. Use this to generate intermediate URLs before calling FinishInteraction.

Jump to

Keyboard shortcuts

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