Documentation
¶
Overview ¶
Package authtest provides an in-memory implementation of auth.AuthenticatorStore for use in consumer tests. It is not intended for production use.
Every read returns a fresh copy and every write stores a fresh copy, so a consumer test can mutate what it receives without reaching the store's state and vice versa. That isolation is what [TestMemStoreIsolatesStoredValues] pins: it holds today because auth.User, auth.Session and auth.Key contain no pointer, slice or map field, so a struct copy is a complete one. A reference-typed field added to any of the three would silently break it, which is why the guarantee is asserted rather than assumed.
Index ¶
- type MemStore
- func (m *MemStore) APIKeyByHash(_ context.Context, hash string) (key *auth.Key, found bool, err error)
- func (m *MemStore) AddAPIKey(k *auth.Key)
- func (m *MemStore) AddSession(s *auth.Session)
- func (m *MemStore) AddUser(u *auth.User)
- func (m *MemStore) CreateSession(_ context.Context, s *auth.Session) error
- func (m *MemStore) DeleteSession(_ context.Context, tokenHash string) error
- func (m *MemStore) DeleteUserSessions(_ context.Context, userID int64, exceptHash string) error
- func (m *MemStore) SessionByHash(_ context.Context, tokenHash string) (sess *auth.Session, found bool, err error)
- func (m *MemStore) UpdateSessionActivity(_ context.Context, tokenHash string, now time.Time) error
- func (m *MemStore) UserByID(_ context.Context, id int64) (user *auth.User, found bool, err error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type MemStore ¶
type MemStore struct {
// contains filtered or unexported fields
}
MemStore is an in-memory implementation of auth interfaces for testing. A MemStore must be constructed with NewMemStore: the zero value has nil maps and panics on the first Add/Create call.
func (*MemStore) APIKeyByHash ¶
func (m *MemStore) APIKeyByHash(_ context.Context, hash string) (key *auth.Key, found bool, err error)
APIKeyByHash returns a copy of the API key stored under hash. found is false when the key is absent; err is always nil.
func (*MemStore) AddAPIKey ¶
AddAPIKey stores a copy of k, keyed by its KeyHash, assigning an auto-incremented ID when k carries none. Unlike MemStore.AddUser it does not write the ID back: k.ID == 0 is how a caller asks for one, so writing it back would change the meaning of a second Add of the same value.
func (*MemStore) AddSession ¶
AddSession stores a copy of s, keyed by its TokenHash.
func (*MemStore) AddUser ¶
AddUser stores a copy of u and assigns it an auto-incremented ID, which it also writes back to u so the caller knows the ID its user was given.
func (*MemStore) CreateSession ¶
CreateSession stores a copy of s, keyed by its TokenHash.
func (*MemStore) DeleteSession ¶
DeleteSession removes the session stored under tokenHash, if any.
func (*MemStore) DeleteUserSessions ¶
DeleteUserSessions removes every session belonging to userID except the one whose token hash equals exceptHash.
func (*MemStore) SessionByHash ¶
func (m *MemStore) SessionByHash(_ context.Context, tokenHash string) (sess *auth.Session, found bool, err error)
SessionByHash returns a copy of the session stored under tokenHash. found is false when no such session exists; err is always nil.
func (*MemStore) UpdateSessionActivity ¶
UpdateSessionActivity sets LastActivity to now for the session identified by tokenHash. It is a no-op if no such session exists.