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 ¶
RandomBytes returns a byte slice of random values of the given length.
func RandomString ¶
RandomString returns a random hex-encoded string of the given length.
func ServerAssetsPath ¶
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) LoggedInSession ¶ added in v0.16.0
func (r *TestServerResponse) LoggedInSession(session *sessions.Session, email string) (*sessions.Session, error)
LoggedInSession returns an session 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 ¶
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.