authtest

package
v0.0.0-...-a99bcb5 Latest Latest
Warning

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

Go to latest
Published: Dec 2, 2026 License: OSL-3.0 Imports: 11 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DeriveTestCSRFToken

func DeriveTestCSRFToken(rawSessionToken string) string

DeriveTestCSRFToken returns the CSRF token a service configured with TestCSRFKey expects for rawSessionToken: hex(HMAC-SHA256(key, token)). It re-derives the value independently, so a change to the production derivation fails the tests that use it.

func TestCSRFKey

func TestCSRFKey() []byte

TestCSRFKey returns the fixed 32-byte CSRF key shared by test services. Pass it as auth.ServiceConfig.CSRFKey so a service built via auth.NewService derives CSRF tokens deterministically, letting tests reproduce the expected token with DeriveTestCSRFToken.

func TestPasswordHash

func TestPasswordHash(t testing.TB, password string) string

TestPasswordHash returns a bcrypt hash of password at bcrypt.MinCost, for fixtures that need a User.PasswordHash the service will accept without the production work factor.

Types

type MockEmailSender

type MockEmailSender struct {
	mock.Mock
}

MockEmailSender is a mock implementation of the email sender for testing.

func (*MockEmailSender) SendPasswordResetEmail

func (m *MockEmailSender) SendPasswordResetEmail(ctx context.Context, email, resetURL string) error

func (*MockEmailSender) SendUserInviteEmail

func (m *MockEmailSender) SendUserInviteEmail(ctx context.Context, email, setupURL string) error

type MockStore

type MockStore struct {
	mock.Mock
}

MockStore is a testify mock of auth.StoreInterface for tests outside package auth. Tests inside package auth use their own copy in test_helpers_test.go (importing this package from there would be an import cycle), so a new store method must be added to both.

func (*MockStore) AdminExists

func (m *MockStore) AdminExists(ctx context.Context) (bool, error)

func (*MockStore) ClaimMFALoginTokenAttempt

func (m *MockStore) ClaimMFALoginTokenAttempt(ctx context.Context, tokenHash string, maxAttempts int) (*auth.MFALoginToken, error)

func (*MockStore) ClaimTOTPCounter

func (m *MockStore) ClaimTOTPCounter(ctx context.Context, userID string, counter int64) (bool, error)

func (*MockStore) CleanupExpiredSessions

func (m *MockStore) CleanupExpiredSessions(ctx context.Context) error

func (*MockStore) ClearPendingMFASecret

func (m *MockStore) ClearPendingMFASecret(ctx context.Context, userID string) error

func (*MockStore) CompletePasswordReset

func (m *MockStore) CompletePasswordReset(ctx context.Context, user *auth.User, readResetToken, readPasswordHash string) error

func (*MockStore) ConsumeMFALoginToken

func (m *MockStore) ConsumeMFALoginToken(ctx context.Context, tokenHash string) (bool, error)

func (*MockStore) ConsumeMFARecoveryCode

func (m *MockStore) ConsumeMFARecoveryCode(ctx context.Context, userID string, readCodes, remaining []string) error

func (*MockStore) ConsumePasswordResetToken

func (m *MockStore) ConsumePasswordResetToken(ctx context.Context, userID, readResetToken string) error

func (*MockStore) CountGroupMembers

func (m *MockStore) CountGroupMembers(ctx context.Context, groupID string) (int, error)

func (*MockStore) CreateAPIKey

func (m *MockStore) CreateAPIKey(ctx context.Context, key *auth.UserAPIKey) error

API Key operations.

func (*MockStore) CreateAdminIfNone

func (m *MockStore) CreateAdminIfNone(ctx context.Context, user *auth.User) (bool, error)

func (*MockStore) CreateGroup

func (m *MockStore) CreateGroup(ctx context.Context, group *auth.Group) error

func (*MockStore) CreateMFALoginToken

func (m *MockStore) CreateMFALoginToken(ctx context.Context, tokenHash, userID string, passwordVersion int64, ttl time.Duration) (time.Time, error)

func (*MockStore) CreateSession

func (m *MockStore) CreateSession(ctx context.Context, session *auth.Session) error

func (*MockStore) CreateUser

func (m *MockStore) CreateUser(ctx context.Context, user *auth.User) error

func (*MockStore) DeleteAPIKey

func (m *MockStore) DeleteAPIKey(ctx context.Context, keyID string) error

func (*MockStore) DeleteGroup

func (m *MockStore) DeleteGroup(ctx context.Context, groupID string) error

func (*MockStore) DeleteSession

func (m *MockStore) DeleteSession(ctx context.Context, token string) error

func (*MockStore) DeleteUser

func (m *MockStore) DeleteUser(ctx context.Context, userID string) error

func (*MockStore) DeleteUserSessions

func (m *MockStore) DeleteUserSessions(ctx context.Context, userID string) error

func (*MockStore) DisableMFA

func (m *MockStore) DisableMFA(ctx context.Context, userID, readSecret string, readCodes []string) error

func (*MockStore) EnableMFA

func (m *MockStore) EnableMFA(ctx context.Context, userID, pendingSecret string, totpCounter int64, recoveryHashes []string) error

func (*MockStore) GetAPIKeyByHash

func (m *MockStore) GetAPIKeyByHash(ctx context.Context, keyHash string) (*auth.UserAPIKey, error)

func (*MockStore) GetAPIKeyByID

func (m *MockStore) GetAPIKeyByID(ctx context.Context, keyID string) (*auth.UserAPIKey, error)

func (*MockStore) GetGroup

func (m *MockStore) GetGroup(ctx context.Context, groupID string) (*auth.Group, error)

func (*MockStore) GetSession

func (m *MockStore) GetSession(ctx context.Context, token string) (*auth.Session, error)

func (*MockStore) GetUserByEmail

func (m *MockStore) GetUserByEmail(ctx context.Context, email string) (*auth.User, error)

func (*MockStore) GetUserByID

func (m *MockStore) GetUserByID(ctx context.Context, userID string) (*auth.User, error)

func (*MockStore) GetUserByResetToken

func (m *MockStore) GetUserByResetToken(ctx context.Context, token string) (*auth.User, error)

func (*MockStore) ListAPIKeysByUser

func (m *MockStore) ListAPIKeysByUser(ctx context.Context, userID string) ([]*auth.UserAPIKey, error)

func (*MockStore) ListGroups

func (m *MockStore) ListGroups(ctx context.Context) ([]auth.Group, error)

func (*MockStore) ListUsers

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

func (*MockStore) Ping

func (m *MockStore) Ping(ctx context.Context) error

func (*MockStore) RecordAPIKeyUsage

func (m *MockStore) RecordAPIKeyUsage(ctx context.Context, keyID string, delta int64) error

func (*MockStore) RecordFailedLogin

func (m *MockStore) RecordFailedLogin(ctx context.Context, userID string) error

func (*MockStore) RecordSuccessfulLogin

func (m *MockStore) RecordSuccessfulLogin(ctx context.Context, userID string) error

func (*MockStore) ReplaceMFARecoveryCodes

func (m *MockStore) ReplaceMFARecoveryCodes(ctx context.Context, userID, readSecret string, readCodes, newHashes []string) error

func (*MockStore) SetPasswordResetToken

func (m *MockStore) SetPasswordResetToken(ctx context.Context, user *auth.User, readExpiry *time.Time) error

func (*MockStore) SetPendingMFASecret

func (m *MockStore) SetPendingMFASecret(ctx context.Context, userID, secret string, expiresAt time.Time) error

func (*MockStore) UpdateAPIKey

func (m *MockStore) UpdateAPIKey(ctx context.Context, key *auth.UserAPIKey) error

func (*MockStore) UpdateGroup

func (m *MockStore) UpdateGroup(ctx context.Context, group *auth.Group) error

func (*MockStore) UpdateUserAdminFields

func (m *MockStore) UpdateUserAdminFields(ctx context.Context, user *auth.User, readEmail string, readGroupIDs []string, readActive bool) error

func (*MockStore) UpdateUserCredentials

func (m *MockStore) UpdateUserCredentials(ctx context.Context, user *auth.User, readEmail, readPasswordHash string) error

Jump to

Keyboard shortcuts

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