candidtest

package
v1.0.0-...-4aba4ec Latest Latest
Warning

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

Go to latest
Published: Apr 5, 2018 License: LGPL-3.0 Imports: 18 Imported by: 0

Documentation

Overview

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

This section is empty.

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.

Jump to

Keyboard shortcuts

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