test

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Aug 21, 2020 License: BSD-3-Clause Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// OTPCodehash is a SHA512 hash of `123456`
	OTPCodeHash = "ba3253876aed6bc22d4a6ff53d8406c6ad864195ed144ab5" +
		"c87621b6c233b548baeae6956df346ec8c17f5ea10f35ee3cbc514797ed7ddd31" +
		"45464e2a0bab413"

	OTPCode = "123456"
)

Variables

This section is empty.

Functions

func MockTokenHash added in v0.2.0

func MockTokenHash(a, m string, t int64) string

func NewRedisDB

func NewRedisDB() (*redis.Client, error)

NewRedisDB returns a redis DB for testing. We allocate a random DB to avoid race conditions in teardown/setup methods.

func Server

func Server(resps ...ServerResp) *httptest.Server

Server creates an external test server with mocked responses.

func SetAuthHeaders

func SetAuthHeaders(r *http.Request)

SetAuthHeaders sets authentication header and client ID cookie to the client request for API testing.

func ValidateErrMessage

func ValidateErrMessage(expectedMsg string, body *bytes.Buffer) error

ValidateErrMessage validates an API error message in the format of { error: { message: "", code: "" } }

Types

type DeviceRepository

type DeviceRepository struct {
	ByIDFn         func() (*auth.Device, error)
	ByClientIDFn   func() (*auth.Device, error)
	ByUserIDFn     func() ([]*auth.Device, error)
	CreateFn       func() error
	GetForUpdateFn func() (*auth.Device, error)
	UpdateFn       func() error
	RemoveFn       func() error
	Calls          struct {
		ByID         int
		ByClientID   int
		ByUserID     int
		Create       int
		GetForUpdate int
		Update       int
		Remove       int
	}
}

DeviceRepository mocks auth.DeviceRepository.

func (*DeviceRepository) ByClientID

func (m *DeviceRepository) ByClientID(ctx context.Context, userID string, clientID []byte) (*auth.Device, error)

ByClientID mock.

func (*DeviceRepository) ByID

func (m *DeviceRepository) ByID(ctx context.Context, deviceID string) (*auth.Device, error)

ByID mock.

func (*DeviceRepository) ByUserID

func (m *DeviceRepository) ByUserID(ctx context.Context, userID string) ([]*auth.Device, error)

ByUserID mock.

func (*DeviceRepository) Create

func (m *DeviceRepository) Create(ctx context.Context, device *auth.Device) error

Create mock.

func (*DeviceRepository) GetForUpdate

func (m *DeviceRepository) GetForUpdate(ctx context.Context, deviceID string) (*auth.Device, error)

GetForUpdate mock.

func (*DeviceRepository) Remove

func (m *DeviceRepository) Remove(ct context.Context, deviceID, userID string) error

Remove mock.

func (*DeviceRepository) Update

func (m *DeviceRepository) Update(ctx context.Context, device *auth.Device) error

Update mock.

type Logger

type Logger struct {
	LogFn func() error
	Calls struct {
		Log int
	}
}

Logger mocks a go-kit logger.

func (*Logger) Log

func (m *Logger) Log(keyvals ...interface{}) error

Log mock.

type LoginHistoryRepository

type LoginHistoryRepository struct {
	ByTokenIDFn    func() (*auth.LoginHistory, error)
	ByUserIDFn     func() ([]*auth.LoginHistory, error)
	CreateFn       func() error
	GetForUpdateFn func() (*auth.LoginHistory, error)
	UpdateFn       func() error
	Calls          struct {
		ByUserID     int
		Create       int
		GetForUpdate int
		Update       int
		ByTokenID    int
	}
}

LoginHistoryRepository mocks auth.LoginHistoryRepository.

func (*LoginHistoryRepository) ByTokenID added in v0.2.0

func (m *LoginHistoryRepository) ByTokenID(ctx context.Context, tokenID string) (*auth.LoginHistory, error)

ByTokenID mock.

func (*LoginHistoryRepository) ByUserID

func (m *LoginHistoryRepository) ByUserID(ctx context.Context, userID string, limit, offset int) ([]*auth.LoginHistory, error)

ByUserID mock.

func (*LoginHistoryRepository) Create

Create mock.

func (*LoginHistoryRepository) GetForUpdate

func (m *LoginHistoryRepository) GetForUpdate(ctx context.Context, tokenID string) (*auth.LoginHistory, error)

GetForUpdate mock.

func (*LoginHistoryRepository) Update

Update mock.

type MessageRepository

type MessageRepository struct {
	PublishFn func(ctx context.Context, msg *auth.Message) error
	RecentFn  func(ctx context.Context) (<-chan *auth.Message, <-chan error)
	Calls     struct {
		Publish int
		Recent  int
	}
}

MessageRepository mocks auth.MessageRepository interface.

func (*MessageRepository) Publish

func (m *MessageRepository) Publish(ctx context.Context, msg *auth.Message) error

Publish mock.

func (*MessageRepository) Recent

func (m *MessageRepository) Recent(ctx context.Context) (<-chan *auth.Message, <-chan error)

Recent mock.

type MessagingService

type MessagingService struct {
	SendFn func() error
	Calls  struct {
		Send int
	}
}

MessagingService mocks auth.MessagingService interface.

func (*MessagingService) Send

func (m *MessagingService) Send(ctx context.Context, msg *auth.Message) error

Send mock.

type OTPService

type OTPService struct {
	TOTPQRStringFn func(u *auth.User) (string, error)
	TOTPSecretFn   func(u *auth.User) (string, error)
	OTPCodeFn      func(address string, method auth.DeliveryMethod) (string, string, error)
	ValidateOTPFn  func(code, hash string) error
	ValidateTOTPFn func(ctx context.Context, u *auth.User, code string) error
	Calls          struct {
		TOTPQRString int
		TOTPSecret   int
		OTPCode      int
		ValidateOTP  int
		ValidateTOTP int
	}
}

OTPService mocks auth.OTPService interface.

func (*OTPService) OTPCode

func (s *OTPService) OTPCode(address string, method auth.DeliveryMethod) (string, string, error)

func (*OTPService) TOTPQRString

func (s *OTPService) TOTPQRString(u *auth.User) (string, error)

func (*OTPService) TOTPSecret

func (s *OTPService) TOTPSecret(u *auth.User) (string, error)

func (*OTPService) ValidateOTP

func (s *OTPService) ValidateOTP(code, hash string) error

func (*OTPService) ValidateTOTP

func (s *OTPService) ValidateTOTP(ctx context.Context, u *auth.User, code string) error

type PGClient

type PGClient struct {
	DB *sql.DB
	// contains filtered or unexported fields
}

PGClient provies a test database.

func NewPGDB

func NewPGDB() (*PGClient, error)

NewPGDB returns a new database for testing. Database names are randomly generated to avoid race conditions with tear down and set up methods with tests.

func (*PGClient) DropDB

func (c *PGClient) DropDB() error

DropDB removes a recently created test database.

type Rediser

type Rediser struct {
	GetFn         func() *redisLib.StringCmd
	SetFn         func() *redisLib.StatusCmd
	WithContextFn func() *redisLib.Client
	CloseFn       func() error
	Calls         struct {
		Get         int
		Set         int
		WithContext int
		Close       int
	}
}

Rediser mocks go-redis client.

func (*Rediser) Close

func (m *Rediser) Close() error

Close mock.

func (*Rediser) Get

func (m *Rediser) Get(ctx context.Context, key string) *redisLib.StringCmd

Get mock.

func (*Rediser) Set

func (m *Rediser) Set(ctx context.Context, key string, v interface{}, t time.Duration) *redisLib.StatusCmd

Set mock.

type RepositoryManager

type RepositoryManager struct {
	NewWithTransactionFn func() (auth.RepositoryManager, error)
	WithAtomicFn         func() (interface{}, error)
	LoginHistoryFn       func() auth.LoginHistoryRepository
	DeviceFn             func() auth.DeviceRepository
	UserFn               func() auth.UserRepository
	Calls                struct {
		NewWithTransaction int
		WithAtomic         int
		LoginHistory       int
		Device             int
		User               int
	}
}

RepositoryManager mocks auth.RepositoryManager interface.

func (*RepositoryManager) Device

Device mock.

func (*RepositoryManager) LoginHistory

func (m *RepositoryManager) LoginHistory() auth.LoginHistoryRepository

LoginHistory mock.

func (*RepositoryManager) NewWithTransaction

func (m *RepositoryManager) NewWithTransaction(ctx context.Context) (auth.RepositoryManager, error)

NewWithTransaction mock.

func (*RepositoryManager) User

User mock.

func (*RepositoryManager) WithAtomic

func (m *RepositoryManager) WithAtomic(operation func() (interface{}, error)) (interface{}, error)

WithAtomic mock.

type ServerResp

type ServerResp struct {
	Path       string
	Resp       string
	StatusCode int
}

ServerResp is a path and response for an external test server.

type TokenService

type TokenService struct {
	RefreshableTillFn func() time.Time
	RefreshableFn     func() error
	CreateFn          func() (*auth.Token, error)
	SignFn            func() (string, error)
	ValidateFn        func() (*auth.Token, error)
	RevokeFn          func() error
	CookiesFn         func() []*http.Cookie
	Calls             struct {
		RefreshableTill int
		Refreshable     int
		Create          int
		Sign            int
		Validate        int
		Revoke          int
		Cookies         int
	}
}

TokenService mocks auth.TokenService interface.

func (*TokenService) Cookies added in v0.2.0

func (m *TokenService) Cookies(ctx context.Context, token *auth.Token) []*http.Cookie

Cookies mock.

func (*TokenService) Create

func (m *TokenService) Create(ctx context.Context, u *auth.User, state auth.TokenState, options ...auth.TokenOption) (*auth.Token, error)

Create mock.

func (*TokenService) Refreshable added in v0.2.0

func (m *TokenService) Refreshable(ctx context.Context, token *auth.Token, refreshToken string) error

Refreshable mock.

func (*TokenService) RefreshableTill added in v0.2.0

func (m *TokenService) RefreshableTill(ctx context.Context, token *auth.Token, refreshToken string) time.Time

RefreshableTill mock.

func (*TokenService) Revoke

func (m *TokenService) Revoke(ctx context.Context, tokenID string) error

Revoke mock.

func (*TokenService) Sign

func (m *TokenService) Sign(ctx context.Context, token *auth.Token) (string, error)

Sign mock.

func (*TokenService) Validate

func (m *TokenService) Validate(ctx context.Context, signedToken string, clientID string) (*auth.Token, error)

Validate mock.

type UserRepository

type UserRepository struct {
	ByIdentityFn           func() (*auth.User, error)
	GetForUpdateFn         func() (*auth.User, error)
	DisableOTPFn           func() (*auth.User, error)
	RemoveDeliveryMethodFn func() (*auth.User, error)
	CreateFn               func() error
	ReCreateFn             func() error
	UpdateFn               func() error
	Calls                  struct {
		ByIdentity           int
		DisableOTP           int
		RemoveDeliveryMethod int
		GetForUpdate         int
		Create               int
		ReCreate             int
		Update               int
	}
}

UserRepository mocks auth.UserRepository.

func (*UserRepository) ByIdentity

func (m *UserRepository) ByIdentity(ctx context.Context, attribute, value string) (*auth.User, error)

ByIdentity mock.

func (*UserRepository) Create

func (m *UserRepository) Create(ctx context.Context, u *auth.User) error

Create mock.

func (*UserRepository) DisableOTP

func (m *UserRepository) DisableOTP(ctx context.Context, userID string, method auth.DeliveryMethod) (*auth.User, error)

DisableOTP mock.

func (*UserRepository) GetForUpdate

func (m *UserRepository) GetForUpdate(ctx context.Context, userID string) (*auth.User, error)

GetForUpdate mock.

func (*UserRepository) ReCreate

func (m *UserRepository) ReCreate(ctx context.Context, u *auth.User) error

ReCreate mock.

func (*UserRepository) RemoveDeliveryMethod

func (m *UserRepository) RemoveDeliveryMethod(ctx context.Context, userID string, method auth.DeliveryMethod) (*auth.User, error)

RemoveDeliveryMethod mock.

func (*UserRepository) Update

func (m *UserRepository) Update(ctx context.Context, u *auth.User) error

Update mock.

type WebAuthnLib

type WebAuthnLib struct {
	BeginRegistrationFn  func() (*webauthnProto.CredentialCreation, *webauthnLib.SessionData, error)
	FinishRegistrationFn func() (*webauthnLib.Credential, error)
	BeginLoginFn         func() (*webauthnProto.CredentialAssertion, *webauthnLib.SessionData, error)
	FinishLoginFn        func() (*webauthnLib.Credential, error)
	Calls                struct {
		BeginRegistration  int
		FinishRegistration int
		BeginLogin         int
		FinishLogin        int
	}
}

WebAuthnLib mocks duo-labs/webauthn third party library.

func (*WebAuthnLib) BeginLogin

BeginLogin mock.

func (*WebAuthnLib) BeginRegistration

BeginRegistration mock.

func (*WebAuthnLib) FinishLogin

FinishLogin mock.

func (*WebAuthnLib) FinishRegistration

func (m *WebAuthnLib) FinishRegistration(user webauthnLib.User, session webauthnLib.SessionData, r *http.Request) (*webauthnLib.Credential, error)

FinishRegistration mock.

type WebAuthnService

type WebAuthnService struct {
	BeginSignUpFn  func() ([]byte, error)
	FinishSignUpFn func() (*auth.Device, error)
	BeginLoginFn   func() ([]byte, error)
	FinishLoginFn  func() error
	Calls          struct {
		BeginSignUp  int
		FinishSignUp int
		BeginLogin   int
		FinishLogin  int
	}
}

WebAuthnService mocks auth.WebAuthnService.

func (*WebAuthnService) BeginLogin

func (m *WebAuthnService) BeginLogin(ctx context.Context, user *auth.User) ([]byte, error)

BeginLogin mock.

func (*WebAuthnService) BeginSignUp

func (m *WebAuthnService) BeginSignUp(ctx context.Context, user *auth.User) ([]byte, error)

BeginSignUp mock.

func (*WebAuthnService) FinishLogin

func (m *WebAuthnService) FinishLogin(ctx context.Context, user *auth.User, r *http.Request) error

FinishLogin mock.

func (*WebAuthnService) FinishSignUp

func (m *WebAuthnService) FinishSignUp(ctx context.Context, user *auth.User, r *http.Request) (*auth.Device, error)

FinishSignUp mock.

Jump to

Keyboard shortcuts

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