envstest

package
v0.15.1 Latest Latest
Warning

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

Go to latest
Published: Oct 29, 2020 License: Apache-2.0 Imports: 25 Imported by: 0

Documentation

Overview

Package envstest defines global test helpers for the entire project.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RandomBytes

func RandomBytes(tb testing.TB, length int) []byte

RandomBytes returns a byte slice of random values of the given length.

func RandomString

func RandomString(tb testing.TB, length int) string

RandomString returns a random hex-encoded string of the given length.

func ServerAssetsPath

func ServerAssetsPath(tb testing.TB) string

ServerAssetsPath returns the path to the UI server assets.

Types

type TestServerResponse

type TestServerResponse struct {
	AuthProvider auth.Provider
	Cacher       cache.Cacher
	Config       *config.ServerConfig
	Database     *database.Database
	KeyManager   keys.KeyManager
	RateLimiter  limiter.Store
	Server       *server.Server
}

TestServerResponse is used as the reply to creating a test UI server.

func NewServer

func NewServer(tb testing.TB) *TestServerResponse

NewServer creates a new test UI server instance. When this function returns, a full UI server will be running locally on a random port. Cleanup is handled automatically.

func (*TestServerResponse) LoggedInCookie

func (r *TestServerResponse) LoggedInCookie(email string) (*http.Cookie, error)

LoggedInCookie returns an encrypted cookie with the provided email address logged in. It also stores that email verification and MFA prompting have already occurred for a consistent post-login experience.

The provided email is marked as verified, has MFA enabled, and is not revoked. To test other journeys, manually build the session.

func (*TestServerResponse) SessionCookie

func (r *TestServerResponse) SessionCookie(session *sessions.Session) (*http.Cookie, error)

SessionCookie returns an encrypted cookie for the given session information, capable of being injected into the browser instance and read by the application. Since the cookie contains the session, it can be used to mutate any server state, including the currently-authenticated user.

Jump to

Keyboard shortcuts

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