mock

package
v0.2.113 Latest Latest
Warning

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

Go to latest
Published: Apr 28, 2026 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Overview

Package mock provides mock implementations of storage interfaces for testing purposes. It includes in-memory implementations with call tracking for verification.

Package mock provides mock implementations of storage interfaces for testing.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ClientStore added in v0.2.24

type ClientStore struct {
	SaveClientFunc     func(ctx context.Context, client *storage.Client) error
	GetClientFunc      func(ctx context.Context, clientID string) (*storage.Client, error)
	ValidateSecretFunc func(ctx context.Context, clientID, clientSecret string) error
	ListClientsFunc    func(ctx context.Context) ([]*storage.Client, error)
	CheckIPLimitFunc   func(ctx context.Context, ip string, maxClientsPerIP int) error
	CallCounts         map[string]int
	// contains filtered or unexported fields
}

ClientStore is a mock implementation of storage.ClientStore for testing

func NewClientStore added in v0.2.24

func NewClientStore() *ClientStore

NewClientStore creates a new mock client store

func (*ClientStore) CheckIPLimit added in v0.2.24

func (m *ClientStore) CheckIPLimit(ctx context.Context, ip string, maxClientsPerIP int) error

CheckIPLimit checks if an IP has reached the client registration limit

func (*ClientStore) GetClient added in v0.2.24

func (m *ClientStore) GetClient(ctx context.Context, clientID string) (*storage.Client, error)

GetClient retrieves a client by ID

func (*ClientStore) ListClients added in v0.2.24

func (m *ClientStore) ListClients(ctx context.Context) ([]*storage.Client, error)

ListClients lists all registered clients

func (*ClientStore) ResetCallCounts added in v0.2.24

func (m *ClientStore) ResetCallCounts()

ResetCallCounts resets all call counters

func (*ClientStore) SaveClient added in v0.2.24

func (m *ClientStore) SaveClient(ctx context.Context, client *storage.Client) error

SaveClient saves a registered client

func (*ClientStore) ValidateClientSecret added in v0.2.24

func (m *ClientStore) ValidateClientSecret(ctx context.Context, clientID, clientSecret string) error

ValidateClientSecret validates a client's secret

type CombinedStore added in v0.2.108

type CombinedStore struct {
	*TokenStore
	*ClientStore
	*FlowStore
}

CombinedStore bundles the three per-interface mocks into a single type that satisfies storage.Combined. It lets tests construct a Server via [server.NewWithCombined] with one argument instead of three:

store := mock.NewCombined()
srv, _ := server.NewWithCombined(provider, store, cfg, logger)

The individual mock fields remain accessible when a test wants to install custom behavior or inspect CallCounts — e.g. store.TokenStore.SaveTokenFunc or store.ClientStore.CallCounts. The embedded ResetCallCounts methods are ambiguous at the CombinedStore level by design (Go won't promote a method name shared by three embedded types); use the individual pointers or the CombinedStore.ResetAllCallCounts helper below.

func NewCombined added in v0.2.108

func NewCombined() *CombinedStore

NewCombined returns a CombinedStore with freshly constructed TokenStore/ClientStore/FlowStore mocks (each via their existing constructors).

func (*CombinedStore) ResetAllCallCounts added in v0.2.108

func (c *CombinedStore) ResetAllCallCounts()

ResetAllCallCounts forwards to each embedded mock's ResetCallCounts. Exists because the bare ResetCallCounts method is ambiguous on *CombinedStore — all three embedded types expose one.

type FlowStore added in v0.2.24

type FlowStore struct {
	SaveAuthStateFunc              func(ctx context.Context, state *storage.AuthorizationState) error
	GetAuthStateFunc               func(ctx context.Context, stateID string) (*storage.AuthorizationState, error)
	GetAuthStateByProviderFunc     func(ctx context.Context, providerState string) (*storage.AuthorizationState, error)
	DeleteAuthStateFunc            func(ctx context.Context, stateID string) error
	SaveAuthCodeFunc               func(ctx context.Context, code *storage.AuthorizationCode) error
	GetAuthCodeFunc                func(ctx context.Context, code string) (*storage.AuthorizationCode, error)
	DeleteAuthCodeFunc             func(ctx context.Context, code string) error
	AtomicCheckAndMarkCodeUsedFunc func(ctx context.Context, code string) (*storage.AuthorizationCode, error)
	CallCounts                     map[string]int
	// contains filtered or unexported fields
}

FlowStore is a mock implementation of storage.FlowStore for testing

func NewFlowStore added in v0.2.24

func NewFlowStore() *FlowStore

NewFlowStore creates a new mock flow store

func (*FlowStore) AtomicCheckAndMarkAuthCodeUsed added in v0.2.24

func (m *FlowStore) AtomicCheckAndMarkAuthCodeUsed(ctx context.Context, code string) (*storage.AuthorizationCode, error)

AtomicCheckAndMarkAuthCodeUsed atomically checks if a code is unused and marks it as used

func (*FlowStore) DeleteAuthorizationCode added in v0.2.24

func (m *FlowStore) DeleteAuthorizationCode(ctx context.Context, code string) error

DeleteAuthorizationCode removes an authorization code

func (*FlowStore) DeleteAuthorizationState added in v0.2.24

func (m *FlowStore) DeleteAuthorizationState(ctx context.Context, stateID string) error

DeleteAuthorizationState removes an authorization state

func (*FlowStore) GetAuthorizationCode added in v0.2.24

func (m *FlowStore) GetAuthorizationCode(ctx context.Context, code string) (*storage.AuthorizationCode, error)

GetAuthorizationCode retrieves an authorization code

func (*FlowStore) GetAuthorizationState added in v0.2.24

func (m *FlowStore) GetAuthorizationState(ctx context.Context, stateID string) (*storage.AuthorizationState, error)

GetAuthorizationState retrieves an authorization state by client state

func (*FlowStore) GetAuthorizationStateByProviderState added in v0.2.24

func (m *FlowStore) GetAuthorizationStateByProviderState(ctx context.Context, providerState string) (*storage.AuthorizationState, error)

GetAuthorizationStateByProviderState retrieves an authorization state by provider state

func (*FlowStore) ResetCallCounts added in v0.2.24

func (m *FlowStore) ResetCallCounts()

ResetCallCounts resets all call counters

func (*FlowStore) SaveAuthorizationCode added in v0.2.24

func (m *FlowStore) SaveAuthorizationCode(ctx context.Context, code *storage.AuthorizationCode) error

SaveAuthorizationCode saves an issued authorization code

func (*FlowStore) SaveAuthorizationState added in v0.2.24

func (m *FlowStore) SaveAuthorizationState(ctx context.Context, state *storage.AuthorizationState) error

SaveAuthorizationState saves the state of an ongoing authorization flow

type TokenStore added in v0.2.24

type TokenStore struct {
	SaveTokenFunc          func(ctx context.Context, userID string, token *oauth2.Token) error
	GetTokenFunc           func(ctx context.Context, userID string) (*oauth2.Token, error)
	DeleteTokenFunc        func(ctx context.Context, userID string) error
	SaveUserInfoFunc       func(ctx context.Context, userID string, info *providers.UserInfo) error
	GetUserInfoFunc        func(ctx context.Context, userID string) (*providers.UserInfo, error)
	SaveRefreshFunc        func(ctx context.Context, refreshToken, userID string, expiresAt time.Time) error
	GetRefreshFunc         func(ctx context.Context, refreshToken string) (string, error)
	DeleteRefreshFunc      func(ctx context.Context, refreshToken string) error
	AtomicGetAndDeleteFunc func(ctx context.Context, refreshToken string) (string, string, *oauth2.Token, error)
	CallCounts             map[string]int
	// contains filtered or unexported fields
}

TokenStore is a mock implementation of storage.TokenStore for testing

func NewTokenStore added in v0.2.24

func NewTokenStore() *TokenStore

NewTokenStore creates a new mock token store

func (*TokenStore) AtomicGetAndDeleteRefreshToken added in v0.2.42

func (m *TokenStore) AtomicGetAndDeleteRefreshToken(ctx context.Context, refreshToken string) (string, string, *oauth2.Token, error)

AtomicGetAndDeleteRefreshToken atomically retrieves and deletes a refresh token. This prevents race conditions in refresh token rotation and reuse detection. Returns the userID, clientID, and provider token if successful.

SECURITY: This operation is atomic - only ONE concurrent request can succeed. SECURITY: Returns clientID for client binding validation per OAuth 2.1 Section 6.

func (*TokenStore) DeleteRefreshToken added in v0.2.24

func (m *TokenStore) DeleteRefreshToken(ctx context.Context, refreshToken string) error

DeleteRefreshToken removes a refresh token

func (*TokenStore) DeleteToken added in v0.2.24

func (m *TokenStore) DeleteToken(ctx context.Context, userID string) error

DeleteToken removes a token for a user

func (*TokenStore) GetRefreshTokenInfo added in v0.2.24

func (m *TokenStore) GetRefreshTokenInfo(ctx context.Context, refreshToken string) (string, error)

GetRefreshTokenInfo retrieves the user ID for a refresh token

func (*TokenStore) GetToken added in v0.2.24

func (m *TokenStore) GetToken(ctx context.Context, userID string) (*oauth2.Token, error)

GetToken retrieves a token for a user

func (*TokenStore) GetUserInfo added in v0.2.24

func (m *TokenStore) GetUserInfo(ctx context.Context, userID string) (*providers.UserInfo, error)

GetUserInfo retrieves user information

func (*TokenStore) ResetCallCounts added in v0.2.24

func (m *TokenStore) ResetCallCounts()

ResetCallCounts resets all call counters

func (*TokenStore) SaveRefreshToken added in v0.2.24

func (m *TokenStore) SaveRefreshToken(ctx context.Context, refreshToken, userID string, expiresAt time.Time) error

SaveRefreshToken saves a refresh token mapping to user ID with expiry

func (*TokenStore) SaveRefreshTokenWithClientID added in v0.2.42

func (m *TokenStore) SaveRefreshTokenWithClientID(_ context.Context, refreshToken, userID, clientID string, expiresAt time.Time) error

SaveRefreshTokenWithClientID saves a refresh token with client binding. This is a test helper that combines SaveRefreshToken with client ID.

func (*TokenStore) SaveToken added in v0.2.24

func (m *TokenStore) SaveToken(ctx context.Context, userID string, token *oauth2.Token) error

SaveToken saves a token for a user

func (*TokenStore) SaveUserInfo added in v0.2.24

func (m *TokenStore) SaveUserInfo(ctx context.Context, userID string, info *providers.UserInfo) error

SaveUserInfo saves user information

func (*TokenStore) SetRefreshTokenClientID added in v0.2.42

func (m *TokenStore) SetRefreshTokenClientID(refreshToken, clientID string)

SetRefreshTokenClientID sets the clientID for a refresh token. This is a test helper for setting up refresh tokens with client binding.

Jump to

Keyboard shortcuts

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