authtest

package
v0.8.1 Latest Latest
Warning

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

Go to latest
Published: Oct 8, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package authtest provides an in-memory auth.Store for tests.

Index

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 NewMemStore

func NewMemStore() *MemStore

NewMemStore returns an empty store.

func (*MemStore) APIKeyByHash

func (m *MemStore) APIKeyByHash(_ context.Context, hash string) (auth.APIKey, error)

func (*MemStore) AcquireLoginLock added in v0.5.0

func (m *MemStore) AcquireLoginLock(_ context.Context, key, owner string, now, until time.Time) (bool, error)

AcquireLoginLock and ReleaseLoginLock keep the locks apart from the counters.

func (*MemStore) AddEraseCount added in v0.4.0

func (m *MemStore) AddEraseCount(_ context.Context, jobID, key string, n int64) error

func (*MemStore) AddRoles

func (m *MemStore) AddRoles(_ context.Context, userID string, roles []string, now time.Time) error

func (*MemStore) AddStorageUsage added in v0.8.0

func (m *MemStore) AddStorageUsage(_ context.Context, owner string, bytes, files int64) error

func (*MemStore) AppendAudit

func (m *MemStore) AppendAudit(_ context.Context, rec auth.AuditRecord) error

func (*MemStore) AuditRecords

func (m *MemStore) AuditRecords() []auth.AuditRecord

AuditRecords returns every stored audit record, oldest first.

func (*MemStore) CancelJob added in v0.8.0

func (m *MemStore) CancelJob(_ context.Context, id string, result auth.JobResult, steps []auth.Step, completedAt, expiresAt time.Time) (bool, error)

func (*MemStore) ClaimDirectUpload added in v0.8.0

func (m *MemStore) ClaimDirectUpload(_ context.Context, id, tokenHash string, now time.Time) (auth.FileJournalEntry, error)

func (*MemStore) ClaimFileDeletions added in v0.8.0

func (m *MemStore) ClaimFileDeletions(_ context.Context, now, lease time.Time, limit int) ([]auth.FileDeletion, error)

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 (m *MemStore) ClaimInvitation(_ context.Context, hash string, now time.Time) (auth.Invitation, error)

func (*MemStore) ClaimInvitationByID added in v0.4.0

func (m *MemStore) ClaimInvitationByID(_ context.Context, id string, now time.Time) (auth.Invitation, error)

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) ClaimPendingUpload added in v0.8.0

func (m *MemStore) ClaimPendingUpload(_ context.Context, id, tokenHash, documentID string, now time.Time) (auth.FileJournalEntry, error)

func (*MemStore) ClearEraseEmail added in v0.4.0

func (m *MemStore) ClearEraseEmail(_ context.Context, jobID string) error

func (*MemStore) ClearLoginAttempts

func (m *MemStore) ClearLoginAttempts(_ context.Context, key string) error

func (*MemStore) CompleteFileDeletion added in v0.8.0

func (m *MemStore) CompleteFileDeletion(_ context.Context, key string) error

func (*MemStore) CompleteIdempotency

func (m *MemStore) CompleteIdempotency(_ context.Context, id string, result *auth.JobResult, jobID string, completedAt, expiresAt time.Time) error

func (*MemStore) CompleteJob

func (m *MemStore) CompleteJob(_ context.Context, id string, result auth.JobResult, completedAt, expiresAt time.Time) error

func (*MemStore) CompletePendingUpload added in v0.8.0

func (m *MemStore) CompletePendingUpload(_ context.Context, id, name, contentType, sha256sum string, size int64, uploadedAt time.Time, image string, at time.Time) error

func (*MemStore) CountOpenPendingUploads added in v0.8.0

func (m *MemStore) CountOpenPendingUploads(_ context.Context, callerKey string, now time.Time) (int, error)

func (*MemStore) CounterKeys added in v0.4.0

func (m *MemStore) CounterKeys() []string

CounterKeys returns the keys of every counter, for tests.

func (*MemStore) CreateAPIKey

func (m *MemStore) CreateAPIKey(_ context.Context, k auth.APIKey) error

func (*MemStore) CreateEmailToken added in v0.4.0

func (m *MemStore) CreateEmailToken(_ context.Context, t auth.EmailToken) error

func (*MemStore) CreateInvitation

func (m *MemStore) CreateInvitation(_ context.Context, inv auth.Invitation) error

func (*MemStore) CreateSession

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

func (*MemStore) CreateUser

func (m *MemStore) CreateUser(_ context.Context, u auth.User) error

func (*MemStore) DeleteAPIKey

func (m *MemStore) DeleteAPIKey(_ context.Context, name string) error

func (*MemStore) DeleteEmailJobsOfUser added in v0.4.0

func (m *MemStore) DeleteEmailJobsOfUser(_ context.Context, userID string) error

func (*MemStore) DeleteEmailTokensOfUser added in v0.4.0

func (m *MemStore) DeleteEmailTokensOfUser(_ context.Context, userID string) error

func (*MemStore) DeleteInvitation

func (m *MemStore) DeleteInvitation(_ context.Context, id string) error

func (*MemStore) DeleteOtherSessions

func (m *MemStore) DeleteOtherSessions(_ context.Context, userID, keepID string) (int64, error)

func (*MemStore) DeleteSecret

func (m *MemStore) DeleteSecret(_ context.Context, database, name string) error

func (*MemStore) DeleteSession

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

func (*MemStore) DeleteSessions

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

func (*MemStore) DeleteUser

func (m *MemStore) DeleteUser(_ context.Context, id string) error

func (*MemStore) Deletions added in v0.8.0

func (m *MemStore) Deletions() []auth.FileDeletion

Deletions returns the queued deletions, for tests.

func (*MemStore) EmailTokens added in v0.4.0

func (m *MemStore) EmailTokens() []auth.EmailToken

EmailTokens returns every stored token record, for tests.

func (*MemStore) EnqueueJob

func (m *MemStore) EnqueueJob(_ context.Context, j auth.Job) error

func (*MemStore) EraseUser added in v0.4.0

func (m *MemStore) EraseUser(_ context.Context, id, placeholderEmail string, now time.Time) error

func (*MemStore) FileDeletionStats added in v0.8.0

func (m *MemStore) FileDeletionStats(_ context.Context) (auth.FileDeletionStats, error)

func (*MemStore) FileJournalEntry added in v0.8.0

func (m *MemStore) FileJournalEntry(_ context.Context, id string) (auth.FileJournalEntry, error)

func (*MemStore) GetCheckReport added in v0.8.0

func (m *MemStore) GetCheckReport(_ context.Context, database, collection string) (auth.CheckReport, bool, error)

func (*MemStore) GetEmailToken added in v0.4.0

func (m *MemStore) GetEmailToken(_ context.Context, hash string) (auth.EmailToken, error)

func (*MemStore) GetJob

func (m *MemStore) GetJob(_ context.Context, id string) (auth.Job, bool, error)

func (*MemStore) Identity

func (m *MemStore) Identity(_ context.Context, provider, subject string) (auth.Identity, error)

func (*MemStore) ImageDeclarations added in v0.8.1

func (m *MemStore) ImageDeclarations(_ context.Context) (map[string]string, error)

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 (m *MemStore) InvalidateEmailTokens(_ context.Context, userID, purpose string, now time.Time) error

func (*MemStore) JournalEntry added in v0.8.0

func (m *MemStore) JournalEntry(id string) (auth.FileJournalEntry, bool)

JournalEntry returns an upload's record, for tests.

func (*MemStore) JournalFile added in v0.8.0

func (m *MemStore) JournalFile(_ context.Context, e auth.FileJournalEntry) error

func (*MemStore) ListAPIKeys

func (m *MemStore) ListAPIKeys(context.Context) ([]auth.APIKey, error)

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) ListCheckReports added in v0.8.0

func (m *MemStore) ListCheckReports(_ context.Context, documents bool) ([]auth.CheckReport, error)

func (*MemStore) ListInvitations

func (m *MemStore) ListInvitations(context.Context) ([]auth.Invitation, error)

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) ListJobs

func (m *MemStore) ListJobs(_ context.Context, f auth.JobFilter) ([]auth.Job, bool, error)

ListJobs filters like the MongoDB store, newest first.

func (*MemStore) ListScheduleStates added in v0.8.0

func (m *MemStore) ListScheduleStates(context.Context) ([]auth.ScheduleState, error)

func (*MemStore) ListSecrets

func (m *MemStore) ListSecrets(context.Context) ([]auth.Secret, error)

func (*MemStore) ListSessions

func (m *MemStore) ListSessions(_ context.Context, userID string) ([]auth.Session, error)

func (*MemStore) ListUnverifiedUsers added in v0.4.0

func (m *MemStore) ListUnverifiedUsers(_ context.Context, before time.Time, limit int) ([]auth.User, error)

func (*MemStore) ListUsers

func (m *MemStore) ListUsers(context.Context) ([]auth.User, error)

func (*MemStore) ListUsersPage added in v0.5.0

func (m *MemStore) ListUsersPage(ctx context.Context, contains, after string, skip, limit int) ([]auth.User, bool, error)

func (*MemStore) LoginAttempts

func (m *MemStore) LoginAttempts(_ context.Context, key string) (auth.Attempts, error)

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 (m *MemStore) PutIdentity(_ context.Context, id auth.Identity) error

func (*MemStore) QueueFileDeletion added in v0.8.0

func (m *MemStore) QueueFileDeletion(_ context.Context, d auth.FileDeletion) error

func (*MemStore) RecordInvocation

func (m *MemStore) RecordInvocation(_ context.Context, r auth.InvocationRecord) error

func (*MemStore) RecordLoginFailure

func (m *MemStore) RecordLoginFailure(_ context.Context, key string, at, expires time.Time) error

func (*MemStore) RedeemEmailToken added in v0.4.0

func (m *MemStore) RedeemEmailToken(_ context.Context, hash, purpose string, now time.Time) (auth.EmailToken, error)

func (*MemStore) ReleaseIdempotency

func (m *MemStore) ReleaseIdempotency(_ context.Context, id string) error

func (*MemStore) ReleaseLoginLock added in v0.5.0

func (m *MemStore) ReleaseLoginLock(_ context.Context, key, owner string) error

func (*MemStore) ReleaseUpload added in v0.8.0

func (m *MemStore) ReleaseUpload(_ context.Context, id, status string, at time.Time) error

func (*MemStore) RemoveRole

func (m *MemStore) RemoveRole(_ context.Context, userID, role string, now time.Time) error

func (*MemStore) RenewJobLease added in v0.8.0

func (m *MemStore) RenewJobLease(_ context.Context, id string, attempt int, until time.Time) (bool, error)

func (*MemStore) ReopenJob added in v0.4.0

func (m *MemStore) ReopenJob(_ context.Context, id string, expiresAt time.Time) (bool, error)

func (*MemStore) RetryFileDeletion added in v0.8.0

func (m *MemStore) RetryFileDeletion(_ context.Context, key string, notBefore time.Time) error

func (*MemStore) RetryJob added in v0.4.0

func (m *MemStore) RetryJob(_ context.Context, id string, notBefore time.Time) error

func (*MemStore) SecretByScope

func (m *MemStore) SecretByScope(_ context.Context, database, name string) (auth.Secret, error)

func (*MemStore) Session

func (m *MemStore) Session(id string) (auth.Session, bool)

Session returns a stored session by id.

func (*MemStore) SessionByTokenHash

func (m *MemStore) SessionByTokenHash(_ context.Context, hash string) (auth.Session, auth.User, error)

func (*MemStore) SessionCount

func (m *MemStore) SessionCount(userID string) int

SessionCount returns how many sessions the user has, expired or not.

func (*MemStore) SetCheckReport added in v0.8.0

func (m *MemStore) SetCheckReport(_ context.Context, r auth.CheckReport) error

func (*MemStore) SetFileJournalStatus added in v0.8.0

func (m *MemStore) SetFileJournalStatus(_ context.Context, id, status, documentID string, at, expiresAt time.Time) error

func (*MemStore) SetImageDeclaration added in v0.8.1

func (m *MemStore) SetImageDeclaration(_ context.Context, key, fingerprint string) error

func (*MemStore) SetJobSteps added in v0.8.0

func (m *MemStore) SetJobSteps(_ context.Context, id string, attempt int, steps []auth.Step, omitted int) (bool, error)

func (*MemStore) SetScheduleState added in v0.8.0

func (m *MemStore) SetScheduleState(_ context.Context, st auth.ScheduleState) error

func (*MemStore) StaleFileJournal added in v0.8.0

func (m *MemStore) StaleFileJournal(_ context.Context, before, now time.Time, limit int) ([]auth.FileJournalEntry, error)

func (*MemStore) StorageUsage added in v0.8.0

func (m *MemStore) StorageUsage(_ context.Context, limit int) (auth.StorageUsage, error)

func (*MemStore) StorageUsageOf added in v0.8.1

func (*MemStore) TouchAPIKey

func (m *MemStore) TouchAPIKey(_ context.Context, hash string, at time.Time) error

func (*MemStore) TouchSession

func (m *MemStore) TouchSession(_ context.Context, id string, lastUsed, expires time.Time) error

func (*MemStore) UpdateUser

func (m *MemStore) UpdateUser(_ context.Context, id string, upd auth.UserUpdate, now time.Time) error

func (*MemStore) UpsertSecret

func (m *MemStore) UpsertSecret(_ context.Context, s auth.Secret) error

func (*MemStore) UserByEmail

func (m *MemStore) UserByEmail(_ context.Context, email string) (auth.User, error)

func (*MemStore) UserByID

func (m *MemStore) UserByID(_ context.Context, id string) (auth.User, error)

Jump to

Keyboard shortcuts

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