Documentation ¶
Overview ¶
Package candidtest provides suites and functions useful for testing the identity manager.
Index ¶
- Variables
- func AssertEqualIdentity(c *qt.C, obtained, expected *store.Identity)
- func BakeryClient(i httpbakery.Interactor) *httpbakery.Client
- func LogTo(c *qt.C)
- func LoginFormAction(resp *http.Response) (string, error)
- func OpenWebBrowser(c *qt.C, rh ResponseHandler) func(u *url.URL) error
- func PasswordLogin(c *qt.C, username, password string) func(u *url.URL) error
- type DischargeCreator
- func (s *DischargeCreator) AssertDischarge(c *qt.C, i httpbakery.Interactor)
- func (s *DischargeCreator) AssertMacaroon(c *qt.C, ms macaroon.Slice, op bakery.Op, id string)
- func (s *DischargeCreator) Discharge(c *qt.C, condition string, client *httpbakery.Client) (macaroon.Slice, error)
- func (s *DischargeCreator) NewMacaroon(c *qt.C, condition string, op bakery.Op) *bakery.Macaroon
- type NoVisit
- type ResponseHandler
- type Server
- func (s *Server) AdminClient() *httpbakery.Client
- func (s *Server) AdminIdentityClient(userID bool) *candidclient.Client
- func (s *Server) Client(i httpbakery.Interactor) *httpbakery.Client
- func (s *Server) CreateAgent(c *qt.C, username string, groups ...string) *bakery.KeyPair
- func (s *Server) CreateUser(c *qt.C, name string, groups ...string) string
- func (s *Server) Do(c *qt.C, req *http.Request) *http.Response
- func (s *Server) Get(c *qt.C, url string) *http.Response
- func (s *Server) IdentityClient(c *qt.C, username string, groups ...string) *candidclient.Client
- func (s *Server) RoundTrip(c *qt.C, req *http.Request) *http.Response
- func (s *Server) ThirdPartyInfo(ctx context.Context, loc string) (bakery.ThirdPartyInfo, error)
- type Store
- type VisitorFunc
Constants ¶
This section is empty.
Variables ¶
var DefaultTemplate = template.New("")
Functions ¶
func AssertEqualIdentity ¶
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 ¶
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 ¶
LoginFormAction gets the action parameter (POST URL) of a login form.
func OpenWebBrowser ¶
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.
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 ¶
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 ¶
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.
type ResponseHandler ¶
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 ¶
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 ¶
func (s *Server) Client(i httpbakery.Interactor) *httpbakery.Client
Client is a convenience method that returns the result of calling BakeryClient(i)
func (*Server) CreateAgent ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 (*Store) AssertUser ¶
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 ¶
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.