Documentation
¶
Overview ¶
Package authtest provides an in-memory auth.Store for tests.
Index ¶
- type MemStore
- func (m *MemStore) APIKeyByHash(_ context.Context, hash string) (auth.APIKey, error)
- func (m *MemStore) AddEraseCount(_ context.Context, jobID, key string, n int64) error
- func (m *MemStore) AddRoles(_ context.Context, userID string, roles []string, now time.Time) error
- func (m *MemStore) AppendAudit(_ context.Context, rec auth.AuditRecord) error
- func (m *MemStore) AuditRecords() []auth.AuditRecord
- func (m *MemStore) ClaimIdempotency(_ context.Context, rec auth.IdempotencyRecord) (auth.IdempotencyRecord, bool, error)
- func (m *MemStore) ClaimInvitation(_ context.Context, hash string, now time.Time) (auth.Invitation, error)
- func (m *MemStore) ClaimInvitationByID(_ context.Context, id string, now time.Time) (auth.Invitation, error)
- func (m *MemStore) ClaimJob(_ context.Context, workerID string, at time.Time, margin time.Duration) (auth.Job, bool, error)
- func (m *MemStore) ClearEraseEmail(_ context.Context, jobID string) error
- func (m *MemStore) ClearLoginAttempts(_ context.Context, key string) error
- func (m *MemStore) CompleteIdempotency(_ context.Context, id string, result *auth.JobResult, jobID string, ...) error
- func (m *MemStore) CompleteJob(_ context.Context, id string, result auth.JobResult, ...) error
- func (m *MemStore) CounterKeys() []string
- func (m *MemStore) CreateAPIKey(_ context.Context, k auth.APIKey) error
- func (m *MemStore) CreateEmailToken(_ context.Context, t auth.EmailToken) error
- func (m *MemStore) CreateInvitation(_ context.Context, inv auth.Invitation) error
- func (m *MemStore) CreateSession(_ context.Context, s auth.Session) error
- func (m *MemStore) CreateUser(_ context.Context, u auth.User) error
- func (m *MemStore) DeleteAPIKey(_ context.Context, name string) error
- func (m *MemStore) DeleteEmailJobsOfUser(_ context.Context, userID string) error
- func (m *MemStore) DeleteEmailTokensOfUser(_ context.Context, userID string) error
- func (m *MemStore) DeleteInvitation(_ context.Context, id string) error
- func (m *MemStore) DeleteOtherSessions(_ context.Context, userID, keepID string) (int64, error)
- func (m *MemStore) DeleteSecret(_ context.Context, database, name string) error
- func (m *MemStore) DeleteSession(_ context.Context, userID, id string) error
- func (m *MemStore) DeleteSessions(_ context.Context, userID string) (int64, error)
- func (m *MemStore) DeleteUser(_ context.Context, id string) error
- func (m *MemStore) EmailTokens() []auth.EmailToken
- func (m *MemStore) EnqueueJob(_ context.Context, j auth.Job) error
- func (m *MemStore) EraseUser(_ context.Context, id, placeholderEmail string, now time.Time) error
- func (m *MemStore) GetEmailToken(_ context.Context, hash string) (auth.EmailToken, error)
- func (m *MemStore) GetJob(_ context.Context, id string) (auth.Job, bool, error)
- func (m *MemStore) Identity(_ context.Context, provider, subject string) (auth.Identity, error)
- func (m *MemStore) IncrementCounter(_ context.Context, key string, at, expires time.Time) (int, time.Time, error)
- func (m *MemStore) InvalidateEmailTokens(_ context.Context, userID, purpose string, now time.Time) error
- func (m *MemStore) ListAPIKeys(context.Context) ([]auth.APIKey, error)
- func (m *MemStore) ListAudit(_ context.Context, f auth.AuditFilter) ([]auth.AuditRecord, bool, error)
- func (m *MemStore) ListInvitations(context.Context) ([]auth.Invitation, error)
- func (m *MemStore) ListInvocations(_ context.Context, f auth.InvocationFilter) ([]auth.InvocationRecord, bool, error)
- func (m *MemStore) ListJobs(_ context.Context, f auth.JobFilter) ([]auth.Job, bool, error)
- func (m *MemStore) ListSecrets(context.Context) ([]auth.Secret, error)
- func (m *MemStore) ListSessions(_ context.Context, userID string) ([]auth.Session, error)
- func (m *MemStore) ListUnverifiedUsers(_ context.Context, before time.Time, limit int) ([]auth.User, error)
- func (m *MemStore) ListUsers(context.Context) ([]auth.User, error)
- func (m *MemStore) LoginAttempts(_ context.Context, key string) (auth.Attempts, error)
- func (m *MemStore) PutIdentity(_ context.Context, id auth.Identity) error
- func (m *MemStore) RecordInvocation(_ context.Context, r auth.InvocationRecord) error
- func (m *MemStore) RecordLoginFailure(_ context.Context, key string, at, expires time.Time) error
- func (m *MemStore) RedeemEmailToken(_ context.Context, hash, purpose string, now time.Time) (auth.EmailToken, error)
- func (m *MemStore) ReleaseIdempotency(_ context.Context, id string) error
- func (m *MemStore) RemoveRole(_ context.Context, userID, role string, now time.Time) error
- func (m *MemStore) ReopenJob(_ context.Context, id string, expiresAt time.Time) (bool, error)
- func (m *MemStore) RetryJob(_ context.Context, id string, notBefore time.Time) error
- func (m *MemStore) SecretByScope(_ context.Context, database, name string) (auth.Secret, error)
- func (m *MemStore) Session(id string) (auth.Session, bool)
- func (m *MemStore) SessionByTokenHash(_ context.Context, hash string) (auth.Session, auth.User, error)
- func (m *MemStore) SessionCount(userID string) int
- func (m *MemStore) TouchAPIKey(_ context.Context, hash string, at time.Time) error
- func (m *MemStore) TouchSession(_ context.Context, id string, lastUsed, expires time.Time) error
- func (m *MemStore) UpdateUser(_ context.Context, id string, upd auth.UserUpdate, now time.Time) error
- func (m *MemStore) UpsertSecret(_ context.Context, s auth.Secret) error
- func (m *MemStore) UserByEmail(_ context.Context, email string) (auth.User, error)
- func (m *MemStore) UserByID(_ context.Context, id string) (auth.User, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type MemStore ¶
type MemStore struct {
// FailPutIdentity, when set, is returned by PutIdentity.
FailPutIdentity error
// contains filtered or unexported fields
}
MemStore is an in-memory auth.Store. The zero value is not usable; use NewMemStore.
func (*MemStore) APIKeyByHash ¶
func (*MemStore) AddEraseCount ¶ added in v0.4.0
func (*MemStore) AppendAudit ¶
func (*MemStore) AuditRecords ¶
func (m *MemStore) AuditRecords() []auth.AuditRecord
AuditRecords returns every stored audit record, oldest first.
func (*MemStore) ClaimIdempotency ¶
func (m *MemStore) ClaimIdempotency(_ context.Context, rec auth.IdempotencyRecord) (auth.IdempotencyRecord, bool, error)
ClaimIdempotency inserts rec if its id isn't already used, mirroring the MongoDB store's insert-or-fetch-existing atomicity (a single mutex makes this trivially atomic here).
func (*MemStore) ClaimInvitation ¶
func (*MemStore) ClaimInvitationByID ¶ added in v0.4.0
func (*MemStore) ClaimJob ¶
func (m *MemStore) ClaimJob(_ context.Context, workerID string, at time.Time, margin time.Duration) (auth.Job, bool, error)
ClaimJob picks the oldest job that's never been claimed, or whose lease has expired, the same rule the MongoDB store's query applies.
func (*MemStore) ClearEraseEmail ¶ added in v0.4.0
func (*MemStore) ClearLoginAttempts ¶
func (*MemStore) CompleteIdempotency ¶
func (*MemStore) CompleteJob ¶
func (*MemStore) CounterKeys ¶ added in v0.4.0
CounterKeys returns the keys of every counter, for tests.
func (*MemStore) CreateAPIKey ¶
func (*MemStore) CreateEmailToken ¶ added in v0.4.0
func (*MemStore) CreateInvitation ¶
func (*MemStore) CreateSession ¶
func (*MemStore) DeleteAPIKey ¶
func (*MemStore) DeleteEmailJobsOfUser ¶ added in v0.4.0
func (*MemStore) DeleteEmailTokensOfUser ¶ added in v0.4.0
func (*MemStore) DeleteInvitation ¶
func (*MemStore) DeleteOtherSessions ¶
func (*MemStore) DeleteSecret ¶
func (*MemStore) DeleteSession ¶
func (*MemStore) DeleteSessions ¶
func (*MemStore) EmailTokens ¶ added in v0.4.0
func (m *MemStore) EmailTokens() []auth.EmailToken
EmailTokens returns every stored token record, for tests.
func (*MemStore) GetEmailToken ¶ added in v0.4.0
func (*MemStore) IncrementCounter ¶
func (m *MemStore) IncrementCounter(_ context.Context, key string, at, expires time.Time) (int, time.Time, error)
IncrementCounter is a fixed window, unlike RecordLoginFailure's sliding cleanup deadline: expires (and so the reset) only moves once the current window has actually ended, or a steady stream of calls would push the deadline forward forever and never reset the count.
func (*MemStore) InvalidateEmailTokens ¶ added in v0.4.0
func (*MemStore) ListAPIKeys ¶
func (*MemStore) ListAudit ¶
func (m *MemStore) ListAudit(_ context.Context, f auth.AuditFilter) ([]auth.AuditRecord, bool, error)
ListAudit filters like the MongoDB store, newest first. Expired records are kept, as before MongoDB's TTL monitor removes them.
func (*MemStore) ListInvitations ¶
func (*MemStore) ListInvocations ¶
func (m *MemStore) ListInvocations(_ context.Context, f auth.InvocationFilter) ([]auth.InvocationRecord, bool, error)
ListInvocations filters like the MongoDB store, newest first. Expired records are kept, as before MongoDB's TTL monitor removes them.
func (*MemStore) ListSecrets ¶
func (*MemStore) ListSessions ¶
func (*MemStore) ListUnverifiedUsers ¶ added in v0.4.0
func (*MemStore) LoginAttempts ¶
LoginAttempts returns the counter even past its expiry, like MongoDB before its TTL monitor deletes it; a failure after expiry restarts it.
func (*MemStore) PutIdentity ¶
func (*MemStore) RecordInvocation ¶
func (*MemStore) RecordLoginFailure ¶
func (*MemStore) RedeemEmailToken ¶ added in v0.4.0
func (*MemStore) ReleaseIdempotency ¶
func (*MemStore) RemoveRole ¶
func (*MemStore) SecretByScope ¶
func (*MemStore) SessionByTokenHash ¶
func (*MemStore) SessionCount ¶
SessionCount returns how many sessions the user has, expired or not.