candidtest

package
v1.12.3 Latest Latest
Warning

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

Go to latest
Published: Feb 23, 2024 License: AGPL-3.0 Imports: 30 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 *qt.C, obtained, expected *store.Identity)

AssertEqualIdentity asserts that the two provided identites are semantically equivilent.

func BakeryClient

func BakeryClient(i httpbakery.Interactor) *httpbakery.Client

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

func LogTo

func LogTo(c *qt.C)

LogTo configures loggo to log to qt.C for the duration of the test. If TEST_LOGGING_CONFIG is set, it will be used to configure the logging modules.

When c.Done is called, the loggo configuration will be reset.

func LoginFormAction

func LoginFormAction(resp *http.Response) (string, error)

LoginFormAction gets the action parameter (POST URL) of a login form.

func OpenWebBrowser

func OpenWebBrowser(c *qt.C, rh ResponseHandler) func(u *url.URL) error

OpenWebBrowser returns a function that simulates opening a web browser to complete a login. This function only returns a non-nil error to its caller if there is an error initialising the client. If rh is non-nil it will be called with the *http.Response that was received by the client. This handler should arrange for any required further processing and return the result.

func PasswordLogin

func PasswordLogin(c *qt.C, username, password string) func(u *url.URL) error

PasswordLogin return a function that can be used with httpbakery.WebBrowserInteractor.OpenWebBrowser that will be configured to perform a username/password login using the given values.

Types

type DischargeCreator

type DischargeCreator struct {
	ServerURL string

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

DischargeCreator represents a third party service that creates discharges addressed to Candid.

func NewDischargeCreator

func NewDischargeCreator(server *Server) *DischargeCreator

NewDischargeCreator returns a DischargeCreator that creates third party caveats addressed to the given server, which must be serving the "discharger" API.

func NewUserIDDischargeCreator

func NewUserIDDischargeCreator(server *Server) *DischargeCreator

NewUserIDDischargeCreator returns a DischargeCreator that creates third party caveats addressed to the given server, which must be serving the "discharger" API. The macaroons will use unique user IDs rather than usernames.

func (*DischargeCreator) AssertDischarge

func (s *DischargeCreator) AssertDischarge(c *qt.C, i httpbakery.Interactor)

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

func (*DischargeCreator) AssertMacaroon

func (s *DischargeCreator) AssertMacaroon(c *qt.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 (*DischargeCreator) Discharge

func (s *DischargeCreator) Discharge(c *qt.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 (*DischargeCreator) NewMacaroon

func (s *DischargeCreator) NewMacaroon(c *qt.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.

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 ResponseHandler

type ResponseHandler func(*http.Client, *http.Response) (*http.Response, error)

A ResponseHandler is a function that is used by OpenWebBrowser to perform further processing with a response. A ResponseHandler should parse the response to determine the next action, close the body of the incoming response and perform queries in order to return the final response to the caller. The final response should not have its body closed.

func PostLoginForm

func PostLoginForm(username, password string) ResponseHandler

PostLoginForm returns a ResponseHandler that can be passed to OpenWebBrowser which will complete a login form with the given Username and Password, and return the result.

func SelectInteractiveLogin

func SelectInteractiveLogin(rh ResponseHandler) ResponseHandler

SelectInteractiveLogin is a ResponseHandler that processes the list of login methods in the incoming response and performs a GET on that URL. If rh is non-nil it will be used to further process the response before returning to the caller.

type Server

type Server struct {
	// URL contains the URL of the server.
	URL string

	// Ctx contains a context.Context that has been initialised with
	// the servers.
	Ctx context.Context

	// Key holds the key that the server uses.
	Key *bakery.KeyPair
	// contains filtered or unexported fields
}

Server implements a test fixture that contains a candid server.

func NewMemServer

func NewMemServer(c *qt.C, versions map[string]identity.NewAPIHandlerFunc) *Server

NewMemServer returns a Server instance that uses in-memory storage and serves the given API version

func NewServer

func NewServer(c *qt.C, p identity.ServerParams, versions map[string]identity.NewAPIHandlerFunc) *Server

NewServer returns new Server instance. The server parameters must contain at least Store, MeetingStore and RootKeyStore. The versions argument configures what API versions to serve.

If p.Key is zero then a new key will be generated. If p.PrivateAddr is zero then it will default to localhost. If p.Template is zero then DefaultTemplate will be used.

func NewServerWithSublocation added in v1.6.0

func NewServerWithSublocation(c *qt.C, p identity.ServerParams, versions map[string]identity.NewAPIHandlerFunc, sublocation string) *Server

NewServerWithSublocation returns a new Server instance. It does the same as NewServer, but it allows to specify a sublocation that fakes the server as operating from a subpath (e.g. http://serveraddr/sublocation).

func (*Server) AdminClient

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

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

func (*Server) AdminIdentityClient

func (s *Server) AdminIdentityClient(userID bool) *candidclient.Client

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

func (*Server) Client

Client is a convenience method that returns the result of calling BakeryClient(i)

func (*Server) CreateAgent

func (s *Server) CreateAgent(c *qt.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 (*Server) CreateUser

func (s *Server) CreateUser(c *qt.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 (*Server) Do

func (s *Server) Do(c *qt.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 (*Server) Get

func (s *Server) Get(c *qt.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 (*Server) IdentityClient

func (s *Server) IdentityClient(c *qt.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 (*Server) RoundTrip

func (s *Server) RoundTrip(c *qt.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 (*Server) ThirdPartyInfo

func (s *Server) 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 Store

type Store struct {
	Store              store.Store
	ProviderDataStore  store.ProviderDataStore
	MeetingStore       meeting.Store
	BakeryRootKeyStore bakery.RootKeyStore
	ACLStore           aclstore.ACLStore
}

Store implements a test fixture that contains memory-based store implementations for use with tests.

func NewStore

func NewStore() *Store

NewStore returns a new Store that uses in-memory storage.

func (*Store) AssertUser

func (s *Store) AssertUser(c *qt.C, id *store.Identity) *store.Identity

AssertUser asserts that the specified user is stored in the store. It returns the stored identity.

func (*Store) ServerParams

func (s *Store) ServerParams() identity.ServerParams

ServerParams returns parameters suitable for passing to NewServer that will use s as its store.

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

LegacyInteract implements httpbakery.LegacyInteractor.LegacyInteract.

Jump to

Keyboard shortcuts

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