Back to godoc.org

Package bakerytest

v2.2.0
Latest Go to latest
Published: Mar 4, 2020 | License: LGPL-3.0 | Module: gopkg.in/macaroon-bakery.v2

Overview

Package bakerytest provides test helper functions for the bakery.

Index

Package Files

Variables

var ErrTokenNotRecognized = errgo.New("discharge token not recognized")

func ConditionParser

func ConditionParser(check func(cond, arg string) ([]checkers.Caveat, error)) httpbakery.ThirdPartyCaveatCheckerP

ConditionParser adapts the given function into an httpbakery.ThirdPartyCaveatCheckerP. It parses the caveat's condition and calls the function with the result.

func ConditionParserP

func ConditionParserP(check func(cond, arg string) ([]checkers.Caveat, error)) httpbakery.ThirdPartyCaveatChecker

ConditionParserP adapts the given function into an httpbakery.ThirdPartyCaveatChecker. It parses the caveat's condition and calls the function with the result.

type Discharger

type Discharger struct {

	// Mux holds the HTTP multiplexor used by
	// the discharger server.
	Mux *httprouter.Router

	// Key holds the discharger's private key.
	Key *bakery.KeyPair

	// Locator holds the third party locator
	// used when adding a third party caveat
	// returned by a third party caveat checker.
	Locator bakery.ThirdPartyLocator

	// CheckerP is called to check third party caveats when they're
	// discharged. It defaults to NopThirdPartyCaveatCheckerP.
	CheckerP httpbakery.ThirdPartyCaveatCheckerP

	// Checker is the deprecated version of CheckerP, and will be
	// ignored if CheckerP is non-nil.
	Checker httpbakery.ThirdPartyCaveatChecker
	// contains filtered or unexported fields
}

Discharger represents a third party caveat discharger server.

func NewDischarger

func NewDischarger(locator bakery.ThirdPartyLocator) *Discharger

NewDischarger returns a new discharger server that can be used to discharge third party caveats. It uses the given locator to add third party caveats returned by the Checker. The discharger also acts as a locator, returning locator information for itself only.

The returned discharger should be closed after use.

This should not be used concurrently unless httpbakery.AllowInsecureThirdPartyLocator is set, because otherwise it needs to run a TLS server and modify http.DefaultTransport to allow insecure connections.

func (*Discharger) AddHTTPHandlers

func (d *Discharger) AddHTTPHandlers(hs []httprequest.Handler)

AddHTTPHandlers adds the given HTTP handlers to the set of endpoints handled by the discharger.

func (*Discharger) CheckThirdPartyCaveat

func (d *Discharger) CheckThirdPartyCaveat(ctx context.Context, p httpbakery.ThirdPartyCaveatCheckerParams) ([]checkers.Caveat, error)

CheckThirdPartyCaveat implements httpbakery.ThirdPartyCaveatCheckerP by calling d.CheckerP, or d.Checker if that's nil.

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) DischargeMacaroon

func (d *Discharger) DischargeMacaroon(
	ctx context.Context,
	cav *bakery.ThirdPartyCaveatInfo,
	caveats []checkers.Caveat,
) (*bakery.Macaroon, error)

DischargeMacaroon returns a discharge macaroon for the given caveat information with the given caveats added. It assumed the actual third party caveat has already been checked.

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) ThirdPartyInfo

func (d *Discharger) ThirdPartyInfo(ctx context.Context, loc string) (bakery.ThirdPartyInfo, error)

PublicKeyForLocation implements bakery.PublicKeyLocator by returning information on the discharger's server location only.

type Rendezvous

type Rendezvous struct {
	// contains filtered or unexported fields
}

Rendezvous implements a place where discharge information can be stored, recovered and waited for.

func NewRendezvous

func NewRendezvous() *Rendezvous

func (*Rendezvous) Await

func (r *Rendezvous) Await(dischargeId string, timeout time.Duration) ([]checkers.Caveat, error)

Await waits for DischargeComplete or DischargeFailed to be called, and returns either the caveats passed to DischargeComplete or the error passed to DischargeFailed.

It waits for at least the given duration. If timeout is zero, it returns the information only if it is already available.

func (*Rendezvous) CheckToken

func (r *Rendezvous) CheckToken(token *httpbakery.DischargeToken, cav *bakery.ThirdPartyCaveatInfo) ([]checkers.Caveat, error)

CheckToken checks that the given token is valid for discharging the given caveat, and returns any caveats passed to DischargeComplete if it is.

func (*Rendezvous) DischargeComplete

func (r *Rendezvous) DischargeComplete(dischargeId string, caveats []checkers.Caveat)

DischargeComplete marks the discharge with the given id as completed with the given caveats, which will be associated with the given discharge id and returned from Await.

func (*Rendezvous) DischargeFailed

func (r *Rendezvous) DischargeFailed(dischargeId string, err error)

DischargeFailed marks the discharge with the given id as failed with the given error, which will be returned from Await or CheckToken when they're called with that id.

func (*Rendezvous) DischargeToken

func (r *Rendezvous) DischargeToken(dischargeId string) *httpbakery.DischargeToken

func (*Rendezvous) Info

func (r *Rendezvous) Info(dischargeId string) (*bakery.ThirdPartyCaveatInfo, bool)

Info returns information on the given discharge id and reports whether the information has been found.

func (*Rendezvous) NewDischarge

func (r *Rendezvous) NewDischarge(cav *bakery.ThirdPartyCaveatInfo) string

NewDischarge creates a new discharge in the rendezvous associated with the given caveat information. It returns an identifier for the discharge that can later be used to complete the discharge or find out the information again.

Documentation was rendered with GOOS=linux and GOARCH=amd64.

Jump to identifier

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to identifier