Documentation ¶
Overview ¶
Package authtest implements some interfaces used by auth package to simplify unit testing.
Index ¶
- Variables
- func MockAuthConfig(c context.Context) context.Context
- type FakeAuth
- type FakeDB
- func (db FakeDB) GetAuthServiceURL(c context.Context) (string, error)
- func (db FakeDB) GetCertificates(c context.Context, id identity.Identity) (*signing.PublicCertificates, error)
- func (db FakeDB) GetTokenServiceURL(c context.Context) (string, error)
- func (db FakeDB) GetWhitelistForIdentity(c context.Context, ident identity.Identity) (string, error)
- func (db FakeDB) IsAllowedOAuthClientID(c context.Context, email, clientID string) (bool, error)
- func (db FakeDB) IsInWhitelist(c context.Context, ip net.IP, whitelist string) (bool, error)
- func (db FakeDB) IsMember(c context.Context, id identity.Identity, groups ...string) (bool, error)
- func (db FakeDB) Use(c context.Context) context.Context
- type FakeErroringDB
- type FakeState
- type MemorySessionStore
- func (s *MemorySessionStore) CloseSession(c context.Context, sessionID string) error
- func (s *MemorySessionStore) GetSession(c context.Context, sessionID string) (*auth.Session, error)
- func (s *MemorySessionStore) OpenSession(c context.Context, userID string, u *auth.User, exp time.Time) (string, error)
Constants ¶
This section is empty.
Variables ¶
ErrAuthenticationError is returned by FakeAuth.Authenticate.
Functions ¶
Types ¶
type FakeAuth ¶
FakeAuth implements auth.Method's Authenticate by returning predefined user.
func (FakeAuth) Authenticate ¶
Authenticate returns predefined User object (if it is not nil) or error.
func (FakeAuth) LoginURL ¶
LoginURL returns fake login URL.
type FakeDB ¶
FakeDB implements user group checking part of db.DB (IsMember).
It is a mapping "identity -> list of its groups". Intended to be used mostly for testing request handlers, thus all other DB methods (that used by auth system when authenticating the request) is not implement and panic when called: the wast majority of request handlers are not calling them.
func (FakeDB) GetAuthServiceURL ¶
GetAuthServiceURL is part of authdb.DB interface. Panics.
func (FakeDB) GetCertificates ¶
func (db FakeDB) GetCertificates(c context.Context, id identity.Identity) (*signing.PublicCertificates, error)
GetCertificates is part of authdb.DB interface. Panics.
func (FakeDB) GetTokenServiceURL ¶
GetTokenServiceURL is part of authdb.DB interface. Panics.
func (FakeDB) GetWhitelistForIdentity ¶
func (db FakeDB) GetWhitelistForIdentity(c context.Context, ident identity.Identity) (string, error)
GetWhitelistForIdentity is part of authdb.DB interface. Panics.
func (FakeDB) IsAllowedOAuthClientID ¶
IsAllowedOAuthClientID is part of authdb.DB interface. Panics.
func (FakeDB) IsInWhitelist ¶
IsInWhitelist is part of authdb.DB interface. Panics.
func (FakeDB) IsMember ¶
IsMember is part of authdb.DB interface.
It returns true if any of 'groups' is listed in db[id].
type FakeErroringDB ¶
FakeErroringDB is authdb.DB with IsMember returning an error.
type FakeState ¶
type FakeState struct { // Identity is main identity associated with the request. // // identity.AnonymousIdentity if not set. Identity identity.Identity // IdentityGroups is list of groups the calling identity belongs to. IdentityGroups []string // Error if not nil is returned by IsMember checks. Error error // FakeDB is a mock authdb.DB implementation to use. // // If not nil, overrides 'IdentityGroups' and 'Error'. FakeDB authdb.DB // PeerIdentityOverride may be set for PeerIdentity() to return custom value. // // By default PeerIdentity() returns Identity (i.e. no delegation is // happening). PeerIdentityOverride identity.Identity // PeerIPOverride may be set for PeerIP() to return custom value. // // By default PeerIP() returns "127.0.0.1". PeerIPOverride net.IP }
FakeState implements auth.State returning predefined values.
Inject it into the context when testing handlers that expect auth state:
ctx = auth.WithState(ctx, &authtest.FakeState{ Identity: "user:user@example.com", IdentityGroups: []string{"admins"}, }) auth.IsMember(ctx, "admins") -> returns true.
func (*FakeState) Authenticator ¶
func (s *FakeState) Authenticator() *auth.Authenticator
Authenticator is part of State interface.
func (*FakeState) Method ¶
Method is part of State interface.
func (*FakeState) PeerIdentity ¶
PeerIdentity is part of State interface.
type MemorySessionStore ¶
type MemorySessionStore struct {
// contains filtered or unexported fields
}
MemorySessionStore implement auth.SessionStore.
func (*MemorySessionStore) CloseSession ¶
func (s *MemorySessionStore) CloseSession(c context.Context, sessionID string) error
CloseSession closes a session given its ID. Does nothing if session is already closed or doesn't exist. Returns only transient errors.
func (*MemorySessionStore) GetSession ¶
GetSession returns existing non-expired session given its ID. Returns nil if session doesn't exist, closed or expired. Returns only transient errors.