Documentation
¶
Index ¶
- Constants
- func MockTokenHash(a, m string, t int64) string
- func NewRedisDB() (*redis.Client, error)
- func Server(resps ...ServerResp) *httptest.Server
- func SetAuthHeaders(r *http.Request)
- func ValidateErrMessage(expectedMsg string, body *bytes.Buffer) error
- type DeviceRepository
- func (m *DeviceRepository) ByClientID(ctx context.Context, userID string, clientID []byte) (*auth.Device, error)
- func (m *DeviceRepository) ByID(ctx context.Context, deviceID string) (*auth.Device, error)
- func (m *DeviceRepository) ByUserID(ctx context.Context, userID string) ([]*auth.Device, error)
- func (m *DeviceRepository) Create(ctx context.Context, device *auth.Device) error
- func (m *DeviceRepository) GetForUpdate(ctx context.Context, deviceID string) (*auth.Device, error)
- func (m *DeviceRepository) Remove(ct context.Context, deviceID, userID string) error
- func (m *DeviceRepository) Update(ctx context.Context, device *auth.Device) error
- type Logger
- type LoginHistoryRepository
- func (m *LoginHistoryRepository) ByTokenID(ctx context.Context, tokenID string) (*auth.LoginHistory, error)
- func (m *LoginHistoryRepository) ByUserID(ctx context.Context, userID string, limit, offset int) ([]*auth.LoginHistory, error)
- func (m *LoginHistoryRepository) Create(ctx context.Context, login *auth.LoginHistory) error
- func (m *LoginHistoryRepository) GetForUpdate(ctx context.Context, tokenID string) (*auth.LoginHistory, error)
- func (m *LoginHistoryRepository) Update(ctx context.Context, login *auth.LoginHistory) error
- type MessageRepository
- type MessagingService
- type OTPService
- func (s *OTPService) OTPCode(address string, method auth.DeliveryMethod) (string, string, error)
- func (s *OTPService) TOTPQRString(u *auth.User) (string, error)
- func (s *OTPService) TOTPSecret(u *auth.User) (string, error)
- func (s *OTPService) ValidateOTP(code, hash string) error
- func (s *OTPService) ValidateTOTP(ctx context.Context, u *auth.User, code string) error
- type PGClient
- type Rediser
- type RepositoryManager
- func (m *RepositoryManager) Device() auth.DeviceRepository
- func (m *RepositoryManager) LoginHistory() auth.LoginHistoryRepository
- func (m *RepositoryManager) NewWithTransaction(ctx context.Context) (auth.RepositoryManager, error)
- func (m *RepositoryManager) User() auth.UserRepository
- func (m *RepositoryManager) WithAtomic(operation func() (interface{}, error)) (interface{}, error)
- type ServerResp
- type TokenService
- func (m *TokenService) Cookies(ctx context.Context, token *auth.Token) []*http.Cookie
- func (m *TokenService) Create(ctx context.Context, u *auth.User, state auth.TokenState, ...) (*auth.Token, error)
- func (m *TokenService) Refreshable(ctx context.Context, token *auth.Token, refreshToken string) error
- func (m *TokenService) RefreshableTill(ctx context.Context, token *auth.Token, refreshToken string) time.Time
- func (m *TokenService) Revoke(ctx context.Context, tokenID string) error
- func (m *TokenService) Sign(ctx context.Context, token *auth.Token) (string, error)
- func (m *TokenService) Validate(ctx context.Context, signedToken string, clientID string) (*auth.Token, error)
- type UserRepository
- func (m *UserRepository) ByIdentity(ctx context.Context, attribute, value string) (*auth.User, error)
- func (m *UserRepository) Create(ctx context.Context, u *auth.User) error
- func (m *UserRepository) DisableOTP(ctx context.Context, userID string, method auth.DeliveryMethod) (*auth.User, error)
- func (m *UserRepository) GetForUpdate(ctx context.Context, userID string) (*auth.User, error)
- func (m *UserRepository) ReCreate(ctx context.Context, u *auth.User) error
- func (m *UserRepository) RemoveDeliveryMethod(ctx context.Context, userID string, method auth.DeliveryMethod) (*auth.User, error)
- func (m *UserRepository) Update(ctx context.Context, u *auth.User) error
- type WebAuthnLib
- func (m *WebAuthnLib) BeginLogin(user webauthnLib.User, opts ...webauthnLib.LoginOption) (*webauthnProto.CredentialAssertion, *webauthnLib.SessionData, error)
- func (m *WebAuthnLib) BeginRegistration(user webauthnLib.User, opts ...webauthnLib.RegistrationOption) (*webauthnProto.CredentialCreation, *webauthnLib.SessionData, error)
- func (m *WebAuthnLib) FinishLogin(user webauthnLib.User, session webauthnLib.SessionData, r *http.Request) (*webauthnLib.Credential, error)
- func (m *WebAuthnLib) FinishRegistration(user webauthnLib.User, session webauthnLib.SessionData, r *http.Request) (*webauthnLib.Credential, error)
- type WebAuthnService
- func (m *WebAuthnService) BeginLogin(ctx context.Context, user *auth.User) ([]byte, error)
- func (m *WebAuthnService) BeginSignUp(ctx context.Context, user *auth.User) ([]byte, error)
- func (m *WebAuthnService) FinishLogin(ctx context.Context, user *auth.User, r *http.Request) error
- func (m *WebAuthnService) FinishSignUp(ctx context.Context, user *auth.User, r *http.Request) (*auth.Device, error)
Constants ¶
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 NewRedisDB ¶
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 ¶
SetAuthHeaders sets authentication header and client ID cookie to the client request for API testing.
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) GetForUpdate ¶
GetForUpdate 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 ¶
func (m *LoginHistoryRepository) Create(ctx context.Context, login *auth.LoginHistory) error
Create mock.
func (*LoginHistoryRepository) GetForUpdate ¶
func (m *LoginHistoryRepository) GetForUpdate(ctx context.Context, tokenID string) (*auth.LoginHistory, error)
GetForUpdate mock.
func (*LoginHistoryRepository) Update ¶
func (m *LoginHistoryRepository) Update(ctx context.Context, login *auth.LoginHistory) error
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.
type MessagingService ¶
MessagingService mocks auth.MessagingService interface.
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 ¶
type PGClient ¶
PGClient provies a 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.
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 ¶
func (m *RepositoryManager) Device() auth.DeviceRepository
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) WithAtomic ¶
func (m *RepositoryManager) WithAtomic(operation func() (interface{}, error)) (interface{}, error)
WithAtomic mock.
type ServerResp ¶
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) 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.
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) DisableOTP ¶
func (m *UserRepository) DisableOTP(ctx context.Context, userID string, method auth.DeliveryMethod) (*auth.User, error)
DisableOTP mock.
func (*UserRepository) GetForUpdate ¶
GetForUpdate mock.
func (*UserRepository) RemoveDeliveryMethod ¶
func (m *UserRepository) RemoveDeliveryMethod(ctx context.Context, userID string, method auth.DeliveryMethod) (*auth.User, error)
RemoveDeliveryMethod 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 ¶
func (m *WebAuthnLib) BeginLogin(user webauthnLib.User, opts ...webauthnLib.LoginOption) (*webauthnProto.CredentialAssertion, *webauthnLib.SessionData, error)
BeginLogin mock.
func (*WebAuthnLib) BeginRegistration ¶
func (m *WebAuthnLib) BeginRegistration(user webauthnLib.User, opts ...webauthnLib.RegistrationOption) (*webauthnProto.CredentialCreation, *webauthnLib.SessionData, error)
BeginRegistration mock.
func (*WebAuthnLib) FinishLogin ¶
func (m *WebAuthnLib) FinishLogin(user webauthnLib.User, session webauthnLib.SessionData, r *http.Request) (*webauthnLib.Credential, error)
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 ¶
BeginLogin mock.
func (*WebAuthnService) BeginSignUp ¶
BeginSignUp mock.
func (*WebAuthnService) FinishLogin ¶
FinishLogin mock.