authtest

package
v2.1.0 Latest Latest
Warning

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

Go to latest
Published: Jul 17, 2026 License: GPL-2.0, GPL-3.0 Imports: 4 Imported by: 0

Documentation

Overview

Package authtest provides an in-memory implementation of auth.AuthStore for use in consumer tests. It is not intended for production use.

Index

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.

func NewMemStore

func NewMemStore() *MemStore

NewMemStore returns a new empty MemStore.

func (*MemStore) AddAPIKey

func (m *MemStore) AddAPIKey(k *auth.Key)

AddAPIKey adds an API key to the store.

func (*MemStore) AddSession

func (m *MemStore) AddSession(s *auth.Session)

AddSession adds a session to the store.

func (*MemStore) AddUser

func (m *MemStore) AddUser(u *auth.User)

AddUser adds a user to the store and assigns an auto-incremented ID.

func (*MemStore) CreateSession

func (m *MemStore) CreateSession(_ context.Context, s *auth.Session) error

CreateSession stores a copy of s, keyed by its TokenHash.

func (*MemStore) DeleteSession

func (m *MemStore) DeleteSession(_ context.Context, tokenHash string) error

DeleteSession removes the session stored under tokenHash, if any.

func (*MemStore) DeleteUserSessions

func (m *MemStore) DeleteUserSessions(_ context.Context, userID int64, exceptHash string) error

DeleteUserSessions removes every session belonging to userID except the one whose token hash equals exceptHash.

func (*MemStore) GetAPIKeyByHash

func (m *MemStore) GetAPIKeyByHash(_ context.Context, hash string) (*auth.Key, error)

GetAPIKeyByHash returns the API key stored under hash, or (nil, nil) if absent.

func (*MemStore) GetSessionByHash

func (m *MemStore) GetSessionByHash(_ context.Context, tokenHash string) (*auth.Session, error)

GetSessionByHash returns the session stored under tokenHash, or (nil, nil) if no such session exists.

func (*MemStore) GetUserByID

func (m *MemStore) GetUserByID(_ context.Context, id int64) (*auth.User, error)

GetUserByID returns the user with the given id, or (nil, nil) if absent.

func (*MemStore) UpdateSessionActivity

func (m *MemStore) UpdateSessionActivity(_ context.Context, tokenHash string, now time.Time) error

UpdateSessionActivity sets LastActivity to now for the session identified by tokenHash. It is a no-op if no such session exists.

Jump to

Keyboard shortcuts

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