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: 24 Imported by: 0

Documentation

Overview

Package candidtest provides an inmemory candid service for use in tests.

Package candidtest holds a mock implementation of the identity manager suitable for testing.

Index

Constants

View Source
const GroupListGroup = "group-lister"

GroupListGroup is the group that users must belong to in order to enquire about other users' groups.

Variables

This section is empty.

Functions

func AddIdentity

func AddIdentity(ctx context.Context, st store.Store, identity *store.Identity)

AddIdentity adds a new identity to the given store. If there is an error adding the identity AddIdentity will panic.

func Serve

func Serve(t Testing, p candid.ServerParams, versions ...string) *httptest.Server

Serve starts a new candid server using the given parameters. Any required parameters that are not spedified will use appropriate defaults. The given API versions will be added to the server, if no API versions are specified then all available versions will be used. Serve uses the Cleanup method on the given Testing object to defer cleaning up any reseources that it creates.

func ServeTLS

func ServeTLS(t Testing, p candid.ServerParams, versions ...string) *httptest.Server

ServeTLS starts a new candid server using the given parameters on a TLS server. Any required parameters that are not spedified will use appropriate defaults. The given API versions will be added to the server, if no API versions are specified then all available versions will be used. Serve uses the Cleanup method on the given Testing object to defer cleaning up any reseources that it creates.

Types

type Server

type Server struct {
	// URL holds the URL of the mock identity server.
	// The discharger endpoint is located at URL/v1/discharge.
	URL *url.URL

	// PublicKey holds the public key of the mock identity server.
	PublicKey *bakery.PublicKey

	// Bakery holds the macaroon bakery used by
	// the mock server.
	Bakery *identchecker.Bakery
	// contains filtered or unexported fields
}

Server represents a mock identity server. It currently serves only the discharge and groups endpoints.

func NewServer

func NewServer() *Server

NewServer runs a mock identity server. It can discharge macaroons and return information on user group membership. The returned server should be closed after use.

func (*Server) AddUser

func (srv *Server) AddUser(name string, groups ...string)

AddUser adds a new user that's in the given set of groups. If the user already exists, the given groups are added to that user's groups.

func (*Server) CandidClient

func (srv *Server) CandidClient(username string) *candidclient.Client

CandidClient returns an identity manager client that takes to the given server as the given user name.

func (*Server) Client

func (srv *Server) Client(username string) *httpbakery.Client

Client returns a bakery client that will discharge as the given user. If the user does not exist, it is added with no groups.

func (*Server) Close

func (srv *Server) Close()

Close shuts down the server.

func (*Server) PublicKeyForLocation

func (srv *Server) PublicKeyForLocation(loc string) (*bakery.PublicKey, error)

PublicKeyForLocation implements bakery.PublicKeyLocator by returning the server's public key for all locations.

func (*Server) RemoveUser

func (srv *Server) RemoveUser(user string)

RemoveUser removes the given user.

func (*Server) RemoveUsers

func (srv *Server) RemoveUsers()

RemoveUsers removes all added users and resets the default user to nothing.

func (*Server) SetDefaultUser

func (srv *Server) SetDefaultUser(name string)

SetDefaultUser configures the server so that it will discharge for the given user if no agent-login cookie is found. The user does not need to have been added. Note that this will bypass the VisitURL logic.

If the name is empty, there will be no default user.

func (*Server) ThirdPartyInfo

func (srv *Server) ThirdPartyInfo(ctx context.Context, loc string) (bakery.ThirdPartyInfo, error)

ThirdPartyInfo implements bakery.ThirdPartyLocator.ThirdPartyInfo.

func (*Server) UserPublicKey

func (srv *Server) UserPublicKey(username string) *bakery.KeyPair

UserPublicKey returns the key for the given user. It panics if the user has not been added.

type Testing

type Testing interface {
	// Cleanup is used to cleanup reseourcs created as part of the test.
	Cleanup(func())

	// Fatalf is used to stop the test when a fatal error occurs.
	Fatalf(f string, args ...interface{})
}

Jump to

Keyboard shortcuts

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