mocks

package
v2.4.1+incompatible Latest Latest
Warning

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

Go to latest
Published: May 19, 2020 License: MIT Imports: 8 Imported by: 1

Documentation

Overview

Package mocks defines implemented interfaces for testing modules

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Request

func Request(method string, postKeyValues ...string) *http.Request

Request returns a new request with optional key-value body (form-post)

Types

type AfterCallback

type AfterCallback struct {
	HasBeenCalled bool
	Fn            authboss.EventHandler
}

AfterCallback is a callback that knows if it was called

func NewAfterCallback

func NewAfterCallback() *AfterCallback

NewAfterCallback constructs a new aftercallback.

type ArbValues

type ArbValues struct {
	Values map[string]string
	Errors []error
}

ArbValues is arbitrary value storage

func (ArbValues) GetPID

func (a ArbValues) GetPID() string

GetPID gets the pid

func (ArbValues) GetPassword

func (a ArbValues) GetPassword() string

GetPassword gets the password

func (ArbValues) GetValues

func (a ArbValues) GetValues() map[string]string

GetValues returns all values

func (ArbValues) Validate

func (a ArbValues) Validate() []error

Validate nothing

type BodyReader

type BodyReader struct {
	Return authboss.Validator
}

BodyReader reads the body of a request and returns some values

func (BodyReader) Read

func (b BodyReader) Read(page string, r *http.Request) (authboss.Validator, error)

Read the return values

type ClientState

type ClientState struct {
	Values        map[string]string
	GetShouldFail bool
}

ClientState is used for testing the client stores on context

func NewClientState

func NewClientState(data ...string) *ClientState

NewClientState constructs a ClientStorer

func (*ClientState) Del

func (m *ClientState) Del(key string)

Del a key/value pair

func (*ClientState) Get

func (m *ClientState) Get(key string) (string, bool)

Get a key's value

func (*ClientState) Put

func (m *ClientState) Put(key, val string)

Put a value

type ClientStateRW

type ClientStateRW struct {
	ClientValues map[string]string
}

ClientStateRW stores things that would originally go in a session, or a map, in memory!

func NewClientRW

func NewClientRW() *ClientStateRW

NewClientRW takes the data from a client state and returns.

func (*ClientStateRW) ReadState

func (c *ClientStateRW) ReadState(*http.Request) (authboss.ClientState, error)

ReadState from memory

func (*ClientStateRW) WriteState

WriteState to memory

type Emailer

type Emailer struct {
	Email authboss.Email
}

Emailer that holds the options it was given

func (*Emailer) Send

func (e *Emailer) Send(ctx context.Context, email authboss.Email) error

Send an e-mail

type ErrorHandler

type ErrorHandler struct {
	Error error
}

ErrorHandler just holds the last error

func (*ErrorHandler) Wrap

func (e *ErrorHandler) Wrap(handler func(w http.ResponseWriter, r *http.Request) error) http.Handler

Wrap an http method

type FailStorer

type FailStorer struct {
	User
}

FailStorer is used for testing module initialize functions that recover more than the base storer

func (FailStorer) Create

func (FailStorer) Create(context.Context) error

Create fails

func (FailStorer) Load

Load fails

func (FailStorer) Save

Save fails

type Logger

type Logger struct {
}

Logger logs to the void

func (Logger) Error

func (l Logger) Error(string)

Error logging

func (Logger) Info

func (l Logger) Info(string)

Info logging

type Mailer

type Mailer struct {
	Last    authboss.Email
	SendErr string
}

Mailer helps simplify mailer testing by storing the last sent email

func NewMailer

func NewMailer() *Mailer

NewMailer constructs a mailer

func (*Mailer) Send

func (m *Mailer) Send(ctx context.Context, email authboss.Email) error

Send an e-mail

type Redirector

type Redirector struct {
	Options authboss.RedirectOptions
}

Redirector stores the redirect options passed to it and writes the Code to the ResponseWriter.

func (*Redirector) Redirect

Redirect a request

type Renderer

type Renderer struct {
	Pages []string

	// Render call variables
	Context context.Context
	Page    string
	Data    authboss.HTMLData
}

Renderer mock

func (*Renderer) HasLoadedViews

func (r *Renderer) HasLoadedViews(pages ...string) error

HasLoadedViews ensures the views were loaded

func (*Renderer) Load

func (r *Renderer) Load(pages ...string) error

Load nothing but store the pages that were loaded

func (*Renderer) Render

func (r *Renderer) Render(ctx context.Context, page string, data authboss.HTMLData) ([]byte, string, error)

Render nothing, but record the arguments into the renderer

type Responder

type Responder struct {
	Status int
	Page   string
	Data   authboss.HTMLData
}

Responder records how a request was responded to

func (*Responder) Respond

func (r *Responder) Respond(w http.ResponseWriter, req *http.Request, code int, page string, data authboss.HTMLData) error

Respond stores the arguments in the struct

type Router

type Router struct {
	Gets    []string
	Posts   []string
	Deletes []string
}

Router records the routes that were registered

func (*Router) Delete

func (r *Router) Delete(path string, _ http.Handler)

Delete records the path in the router

func (*Router) Get

func (r *Router) Get(path string, _ http.Handler)

Get records the path in the router

func (*Router) HasDeletes

func (r *Router) HasDeletes(deletes ...string) error

HasDeletes ensures all gets routes are present

func (*Router) HasGets

func (r *Router) HasGets(gets ...string) error

HasGets ensures all gets routes are present

func (*Router) HasPosts

func (r *Router) HasPosts(posts ...string) error

HasPosts ensures all gets routes are present

func (*Router) Post

func (r *Router) Post(path string, _ http.Handler)

Post records the path in the router

func (Router) ServeHTTP

func (Router) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP does nothing

type ServerStorer

type ServerStorer struct {
	Users    map[string]*User
	RMTokens map[string][]string
}

ServerStorer should be valid for any module storer defined in authboss.

func NewServerStorer

func NewServerStorer() *ServerStorer

NewServerStorer constructor

func (*ServerStorer) AddRememberToken

func (s *ServerStorer) AddRememberToken(ctx context.Context, key, token string) error

AddRememberToken for remember me

func (*ServerStorer) Create

func (s *ServerStorer) Create(ctx context.Context, user authboss.User) error

Create a user

func (*ServerStorer) DelRememberTokens

func (s *ServerStorer) DelRememberTokens(ctx context.Context, key string) error

DelRememberTokens for a user

func (*ServerStorer) Load

func (s *ServerStorer) Load(ctx context.Context, key string) (authboss.User, error)

Load a user

func (*ServerStorer) LoadByConfirmSelector

func (s *ServerStorer) LoadByConfirmSelector(ctx context.Context, selector string) (authboss.ConfirmableUser, error)

LoadByConfirmSelector finds a user by his confirm selector

func (*ServerStorer) LoadByRecoverSelector

func (s *ServerStorer) LoadByRecoverSelector(ctx context.Context, selector string) (authboss.RecoverableUser, error)

LoadByRecoverSelector finds a user by his recover token

func (*ServerStorer) New

New constructs a blank user to later be created

func (*ServerStorer) NewFromOAuth2

func (s *ServerStorer) NewFromOAuth2(ctx context.Context, provider string, details map[string]string) (authboss.OAuth2User, error)

NewFromOAuth2 finds a user with the given details, or returns a new one

func (*ServerStorer) Save

func (s *ServerStorer) Save(ctx context.Context, user authboss.User) error

Save a user

func (*ServerStorer) SaveOAuth2

func (s *ServerStorer) SaveOAuth2(ctx context.Context, user authboss.OAuth2User) error

SaveOAuth2 creates a user if not found, or updates one that exists.

func (*ServerStorer) UseRememberToken

func (s *ServerStorer) UseRememberToken(ctx context.Context, givenKey, token string) (err error)

UseRememberToken if it exists, deleting it in the process

type User

type User struct {
	Username           string
	Email              string
	Password           string
	RecoverSelector    string
	RecoverVerifier    string
	RecoverTokenExpiry time.Time
	ConfirmSelector    string
	ConfirmVerifier    string
	Confirmed          bool
	AttemptCount       int
	LastAttempt        time.Time
	Locked             time.Time

	OAuth2UID      string
	OAuth2Provider string
	OAuth2Token    string
	OAuth2Refresh  string
	OAuth2Expiry   time.Time

	OTPs           string
	TOTPSecretKey  string
	SMSPhoneNumber string
	RecoveryCodes  string

	SMSPhoneNumberSeed string

	Arbitrary map[string]string
}

User represents all possible fields a authboss User may have

func (User) GetArbitrary

func (u User) GetArbitrary() map[string]string

GetArbitrary from user

func (User) GetAttemptCount

func (u User) GetAttemptCount() int

GetAttemptCount from user

func (User) GetConfirmSelector

func (u User) GetConfirmSelector() string

GetConfirmSelector from user

func (User) GetConfirmVerifier

func (u User) GetConfirmVerifier() string

GetConfirmVerifier from user

func (User) GetConfirmed

func (u User) GetConfirmed() bool

GetConfirmed from user

func (User) GetEmail

func (u User) GetEmail() string

GetEmail from user

func (User) GetLastAttempt

func (u User) GetLastAttempt() time.Time

GetLastAttempt from user

func (User) GetLocked

func (u User) GetLocked() time.Time

GetLocked from user

func (User) GetOAuth2AccessToken

func (u User) GetOAuth2AccessToken() string

GetOAuth2AccessToken from user

func (User) GetOAuth2Expiry

func (u User) GetOAuth2Expiry() time.Time

GetOAuth2Expiry from user

func (User) GetOAuth2Provider

func (u User) GetOAuth2Provider() string

GetOAuth2Provider from user

func (User) GetOAuth2RefreshToken

func (u User) GetOAuth2RefreshToken() string

GetOAuth2RefreshToken from user

func (User) GetOAuth2UID

func (u User) GetOAuth2UID() string

GetOAuth2UID from user

func (User) GetOTPs

func (u User) GetOTPs() string

GetOTPs from user

func (User) GetPID

func (u User) GetPID() string

GetPID from user

func (User) GetPassword

func (u User) GetPassword() string

GetPassword from user

func (User) GetRecoverExpiry

func (u User) GetRecoverExpiry() time.Time

GetRecoverExpiry from user

func (User) GetRecoverSelector

func (u User) GetRecoverSelector() string

GetRecoverSelector from user

func (User) GetRecoverVerifier

func (u User) GetRecoverVerifier() string

GetRecoverVerifier from user

func (User) GetRecoveryCodes

func (u User) GetRecoveryCodes() string

GetRecoveryCodes from user

func (User) GetSMSPhoneNumber

func (u User) GetSMSPhoneNumber() string

GetSMSPhoneNumber from user

func (User) GetSMSPhoneNumberSeed

func (u User) GetSMSPhoneNumberSeed() string

GetSMSPhoneNumber from user

func (User) GetTOTPSecretKey

func (u User) GetTOTPSecretKey() string

GetTOTPSecretKey from user

func (User) GetUsername

func (u User) GetUsername() string

GetUsername from user

func (User) IsOAuth2User

func (u User) IsOAuth2User() bool

IsOAuth2User returns true if the user is an oauth2 user

func (*User) PutArbitrary

func (u *User) PutArbitrary(arb map[string]string)

PutArbitrary into user

func (*User) PutAttemptCount

func (u *User) PutAttemptCount(attemptCount int)

PutAttemptCount into user

func (*User) PutConfirmSelector

func (u *User) PutConfirmSelector(confirmSelector string)

PutConfirmSelector into user

func (*User) PutConfirmVerifier

func (u *User) PutConfirmVerifier(confirmVerifier string)

PutConfirmVerifier into user

func (*User) PutConfirmed

func (u *User) PutConfirmed(confirmed bool)

PutConfirmed into user

func (*User) PutEmail

func (u *User) PutEmail(email string)

PutEmail into user

func (*User) PutLastAttempt

func (u *User) PutLastAttempt(attemptTime time.Time)

PutLastAttempt into user

func (*User) PutLocked

func (u *User) PutLocked(locked time.Time)

PutLocked into user

func (*User) PutOAuth2AccessToken

func (u *User) PutOAuth2AccessToken(token string)

PutOAuth2AccessToken into user

func (*User) PutOAuth2Expiry

func (u *User) PutOAuth2Expiry(expiry time.Time)

PutOAuth2Expiry into user

func (*User) PutOAuth2Provider

func (u *User) PutOAuth2Provider(provider string)

PutOAuth2Provider into user

func (*User) PutOAuth2RefreshToken

func (u *User) PutOAuth2RefreshToken(refresh string)

PutOAuth2RefreshToken into user

func (*User) PutOAuth2UID

func (u *User) PutOAuth2UID(uid string)

PutOAuth2UID into user

func (*User) PutOTPs

func (u *User) PutOTPs(otps string)

PutOTPs into user

func (*User) PutPID

func (u *User) PutPID(email string)

PutPID into user

func (*User) PutPassword

func (u *User) PutPassword(password string)

PutPassword into user

func (*User) PutRecoverExpiry

func (u *User) PutRecoverExpiry(recoverTokenExpiry time.Time)

PutRecoverExpiry into user

func (*User) PutRecoverSelector

func (u *User) PutRecoverSelector(recoverSelector string)

PutRecoverSelector into user

func (*User) PutRecoverVerifier

func (u *User) PutRecoverVerifier(recoverVerifier string)

PutRecoverVerifier into user

func (*User) PutRecoveryCodes

func (u *User) PutRecoveryCodes(codes string)

PutRecoveryCodes into user

func (*User) PutSMSPhoneNumber

func (u *User) PutSMSPhoneNumber(number string)

PutSMSPhoneNumber into user

func (*User) PutTOTPSecretKey

func (u *User) PutTOTPSecretKey(key string)

PutTOTPSecretKey into user

func (*User) PutUsername

func (u *User) PutUsername(username string)

PutUsername into user

type Values

type Values struct {
	PID         string
	Password    string
	Token       string
	Code        string
	Recovery    string
	PhoneNumber string
	Remember    bool

	Errors []error
}

Values is returned from the BodyReader

func (Values) GetCode

func (v Values) GetCode() string

GetCode from values

func (Values) GetPID

func (v Values) GetPID() string

GetPID from values

func (Values) GetPassword

func (v Values) GetPassword() string

GetPassword from values

func (Values) GetPhoneNumber

func (v Values) GetPhoneNumber() string

GetPhoneNumber from values

func (Values) GetRecoveryCode

func (v Values) GetRecoveryCode() string

GetRecoveryCode from values

func (Values) GetShouldRemember

func (v Values) GetShouldRemember() bool

GetShouldRemember gets the value that tells the remember module if it should remember the user

func (Values) GetToken

func (v Values) GetToken() string

GetToken from values

func (Values) Validate

func (v Values) Validate() []error

Validate the values

Jump to

Keyboard shortcuts

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