candidtest

package
v1.0.0-alpha4 Latest Latest
Warning

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

Go to latest
Published: Jun 29, 2018 License: AGPL-3.0 Imports: 25 Imported by: 0

Documentation

Overview

Package candidtest provides suites and functions useful for testing the identity manager.

Index

Constants

This section is empty.

Variables

View Source
var DefaultTemplate = template.New("")

Functions

func AssertEqualIdentity

func AssertEqualIdentity(c *gc.C, obtained, expected *store.Identity)

AssertEqualIdentity asserts that the two provided identites are semantically equivilent.

Types

type DischargeSuite

type DischargeSuite struct {
	StoreServerSuite

	Bakery *identchecker.Bakery
	// contains filtered or unexported fields
}

A DischargeSuite is a test suite useful for testing discharges.

func (*DischargeSuite) AssertDischarge

func (s *DischargeSuite) AssertDischarge(c *gc.C, i httpbakery.Interactor)

AssertDischarge checks that a macaroon can be discharged with interaction using the specified visitor.

func (*DischargeSuite) AssertMacaroon

func (s *DischargeSuite) AssertMacaroon(c *gc.C, ms macaroon.Slice, op bakery.Op, id string)

AssertMacaroon asserts that the given macaroon slice is valid for the given operation. If id is specified then the declared identity in the macaroon is checked to be the same as id.

func (*DischargeSuite) Discharge

func (s *DischargeSuite) Discharge(c *gc.C, condition string, client *httpbakery.Client) (macaroon.Slice, error)

Discharge attempts to perform a discharge of a new macaroon against this suites identity server using the given client and returns a macaroon slice containing a discharged macaroon or any error. The newly minted macaroon will have a third-party caveat addressed to the identity server with the given condition.

func (*DischargeSuite) NewMacaroon

func (s *DischargeSuite) NewMacaroon(c *gc.C, condition string, op bakery.Op) *bakery.Macaroon

NewMacaroon creates a new macaroon with a third-party caveat addressed to the identity server which has the given condition.

func (*DischargeSuite) SetUpTest

func (s *DischargeSuite) SetUpTest(c *gc.C)

SetUpTest creates a new identity server ready to perform discharges and serves it.

type NoVisit

type NoVisit struct{}

NoVisit is a httpbakery.Visitor that returns an error without attempting a visit.

func (NoVisit) VisitWebPage

func (NoVisit) VisitWebPage(context.Context, *httpbakery.Client, map[string]*url.URL) error

VisitWebPage implements httpbakery.Visitor.VisitWebPage

type ServerSuite

type ServerSuite struct {
	// Params is used to configure the server. Any settings must be
	// set before calling SetUpTest. At the least Store, MeetingStore
	// and RootKeyStore must be configured.
	Params identity.ServerParams

	// Versions configures the API versions which will be served by
	// the server. This must be set before calling SetUpTest.
	Versions map[string]identity.NewAPIHandlerFunc

	// URL contains the URL of the server.
	URL string

	// Ctx contains a context.Context that has been initialised with
	// the servers.
	Ctx context.Context
	// contains filtered or unexported fields
}

A ServerSuite is a test suite that

func (*ServerSuite) AdminClient

func (s *ServerSuite) AdminClient() *httpbakery.Client

AdminClient creates a new httpbakery.Client that is configured to log in as an admin user.

func (*ServerSuite) AdminIdentityClient

func (s *ServerSuite) AdminIdentityClient(c *gc.C) *candidclient.Client

AdminIdentityClient creates a new candidclient.Client that is configured to log in as an admin user.

func (*ServerSuite) Client

Client creates a new httpbakery.Client which uses the given visitor as its WebPageVisitor. If no Visitor is specified then NoVisit will be used.

func (*ServerSuite) CreateAgent

func (s *ServerSuite) CreateAgent(c *gc.C, username string, groups ...string) *bakery.KeyPair

CreateAgent creates a new agent user in the identity server's store with the given name and groups. The agent's username and key are returned.

The agent will be owned by admin@candid.

func (*ServerSuite) CreateUser

func (s *ServerSuite) CreateUser(c *gc.C, name string, groups ...string) string

CreateUser creates a new user in the identity server's store with the given name and groups. The user's username is returned.

func (*ServerSuite) Do

func (s *ServerSuite) Do(c *gc.C, req *http.Request) *http.Response

Do is a convenience function for performing HTTP requests against the server. The server's URL will be prepended to the one specified in the request and then the request will be performed using http.DefaultClient.

func (*ServerSuite) Get

func (s *ServerSuite) Get(c *gc.C, url string) *http.Response

Get is a convenience function for performing HTTP requests against the server. The server's URL will be prepended to the one given and then the GET will be performed using http.DefaultClient.

func (*ServerSuite) IdentityClient

func (s *ServerSuite) IdentityClient(c *gc.C, username string, groups ...string) *candidclient.Client

IdentityClient creates a new agent with the given username (which must end in @candid) and groups and then creates an candidclient.Client which authenticates using that agent.

func (*ServerSuite) RoundTrip

func (s *ServerSuite) RoundTrip(c *gc.C, req *http.Request) *http.Response

RoundTrip is a convenience function for performing a single HTTP requests against the server. The server's URL will be prepended to the one specified in the request and then a single request will be performed using http.DefaultTransport.

func (*ServerSuite) SetUpTest

func (s *ServerSuite) SetUpTest(c *gc.C)

SetUpTest creates a new identity server and serves it. The server is configured based on the Params and Versions fields. If the Key parameter is not set then a new key will be generated. If the PrivateAddr parameter is not set then it will default to localhost. If the adminAgentPublicKey is not set then a new key will be generated, note that if it is set the AdminClient and AdminIdentityClient can not be used. If the Template parameter is not set then DefaultTemplate will be used.

func (*ServerSuite) TearDownTest

func (s *ServerSuite) TearDownTest(c *gc.C)

TearDownTest cleans up the resources created during SetUpTest.

func (*ServerSuite) ThirdPartyInfo

func (s *ServerSuite) ThirdPartyInfo(ctx context.Context, loc string) (bakery.ThirdPartyInfo, error)

ThirdPartyInfo implements bakery.ThirdPartyLocator.THirdPartyInfo allowing the suite to be used as a bakery.ThirdPArtyLocator.

type StoreServerSuite

type StoreServerSuite struct {
	StoreSuite
	ServerSuite
}

A StoreServerSuite combines a StoreSuite and a ServerSuite to provider an initialized server with storage.

func (*StoreServerSuite) SetUpTest

func (s *StoreServerSuite) SetUpTest(c *gc.C)

func (*StoreServerSuite) TearDownTest

func (s *StoreServerSuite) TearDownTest(c *gc.C)

type StoreSuite

type StoreSuite struct {
	testing.IsolationSuite

	Store              store.Store
	ProviderDataStore  store.ProviderDataStore
	MeetingStore       meeting.Store
	BakeryRootKeyStore bakery.RootKeyStore
}

A StoreSuite is a test suite that initializes a store.Store, meeting.MeetingStore and bakery.RootKeyStore for use with tests.

func (*StoreSuite) SetUpSuite

func (s *StoreSuite) SetUpSuite(c *gc.C)

func (*StoreSuite) SetUpTest

func (s *StoreSuite) SetUpTest(c *gc.C)

func (*StoreSuite) TearDownSuite

func (s *StoreSuite) TearDownSuite(c *gc.C)

func (*StoreSuite) TearDownTest

func (s *StoreSuite) TearDownTest(c *gc.C)

type VisitorFunc

type VisitorFunc func(*url.URL) error

A VisitorFunc converts a function to a httpbakery.LegacyInteractor.

func (VisitorFunc) LegacyInteract

func (f VisitorFunc) LegacyInteract(ctx context.Context, _ *httpbakery.Client, _ string, u *url.URL) error

VisitWebPage implements httpbakery.Visitor.VisitWebPage.

Jump to

Keyboard shortcuts

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