envstest

package
v0.21.2 Latest Latest
Warning

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

Go to latest
Published: Feb 2, 2021 License: Apache-2.0 Imports: 40 Imported by: 0

Documentation

Overview

Package envstest defines global test helpers for the entire project.

Index

Constants

View Source
const (
	RealmName  = "e2e-test-realm"
	RegionCode = "e2e-test"

	AdminKeyPrefix  = "e2e-admin-key."
	DeviceKeyPrefix = "e2e-device-key."
	StatsKeyPrefix  = "e2e-stats-key."

	AndroidAppPrefix = "e2e-android-"
	IOSAppPrefix     = "e2e-ios-"
)

Variables

This section is empty.

Functions

func AutoConfirmDialogs added in v0.19.0

func AutoConfirmDialogs(ctx context.Context, b bool) <-chan error

AutoConfirmDialogs automatically clicks "confirm" on popup dialogs from window.Confirm prompts.

func CaptureJavascriptErrors added in v0.19.0

func CaptureJavascriptErrors(ctx context.Context) <-chan error

CaptureJavascriptErrors captures any console errors that occur.

func ENXRedirectAssetsPath added in v0.21.0

func ENXRedirectAssetsPath() string

ENXRedirectAssetsPath returns the path to the ENX redirector assets.

func ExerciseBadPagination added in v0.19.0

func ExerciseBadPagination(t *testing.T, membership *database.Membership, h http.Handler)

ExerciseBadPagination tests that the proper response code and HTML error page are rendered when the URL includes pagination parameters that fail to parse.

func ExerciseIDNotFound added in v0.19.0

func ExerciseIDNotFound(t *testing.T, membership *database.Membership, h http.Handler)

ExerciseIDNotFound tests that the proper response code and HTML error page are rendered when the route expects an "id" mux parameter, but the one given does not correspond to an actual record.

func ExerciseMembershipMissing added in v0.19.0

func ExerciseMembershipMissing(t *testing.T, h http.Handler)

ExerciseMembershipMissing tests that the proper response code and HTML error page are rendered with there is no membership in the context. It sets a session in the context.

func ExercisePermissionMissing added in v0.19.0

func ExercisePermissionMissing(t *testing.T, h http.Handler)

ExercisePermissionMissing tests that the proper response code and HTML error page are rendered when the requestor does not have permission to perform this action.

func ExerciseSessionMissing added in v0.19.0

func ExerciseSessionMissing(t *testing.T, h http.Handler)

ExerciseSessionMissing tests that the proper response code and HTML error page are rendered with the context has no session.

func LocalesPath added in v0.17.0

func LocalesPath() string

LocalesPath returns the path to the i18n locales.

func NewFailingDatabase added in v0.19.0

func NewFailingDatabase() *gorm.DB

NewFailingDatabase database creates a new database connection that fails all requests.

func NewHarnessServer added in v0.19.0

func NewHarnessServer(tb testing.TB, mux http.Handler) *server.Server

NewHarnessServer creates a new server for the mux on a random port. Cleanup is handled automatically.

func ServerAssetsPath

func ServerAssetsPath() string

ServerAssetsPath returns the path to the UI server assets.

Types

type APIServerConfigResponse added in v0.19.0

type APIServerConfigResponse struct {
	Config      *config.APIServerConfig
	Database    *database.Database
	Cacher      cache.Cacher
	KeyManager  keys.KeyManager
	RateLimiter limiter.Store
}

APIServerConfigResponse is the response from creating an API server config.

func NewAPIServerConfig added in v0.19.0

func NewAPIServerConfig(tb testing.TB, testDatabaseInstance *database.TestInstance) *APIServerConfigResponse

NewAPIServerConfig creates a new API server configuration.

func (*APIServerConfigResponse) NewServer added in v0.19.0

type APIServerResponse added in v0.19.0

type APIServerResponse struct {
	Config      *config.APIServerConfig
	Database    *database.Database
	Cacher      cache.Cacher
	KeyManager  keys.KeyManager
	RateLimiter limiter.Store
	Server      *server.Server
}

APIServerResponse is the response from a test APIServer instance.

func NewAPIServer added in v0.19.0

func NewAPIServer(tb testing.TB, testDatabaseInstance *database.TestInstance) *APIServerResponse

NewAPIServer creates a new test APIServer server instance. See NewHarnessServer for more information.

type AdminAPIServerConfigResponse added in v0.19.0

type AdminAPIServerConfigResponse struct {
	Config      *config.AdminAPIServerConfig
	Database    *database.Database
	Cacher      cache.Cacher
	KeyManager  keys.KeyManager
	RateLimiter limiter.Store
}

AdminAPIServerConfigResponse is the response from creating an AdminAPI server config.

func NewAdminAPIServerConfig added in v0.19.0

func NewAdminAPIServerConfig(tb testing.TB, testDatabaseInstance *database.TestInstance) *AdminAPIServerConfigResponse

NewAdminAPIServerConfig creates a new API server configuration.

func (*AdminAPIServerConfigResponse) NewServer added in v0.19.0

NewServer creates a new server.

type AdminAPIServerResponse added in v0.19.0

type AdminAPIServerResponse struct {
	Config      *config.AdminAPIServerConfig
	Database    *database.Database
	Cacher      cache.Cacher
	KeyManager  keys.KeyManager
	RateLimiter limiter.Store
	Server      *server.Server
}

AdminAPIServerResponse is the response from a test AdminAPI instance.

func NewAdminAPIServer added in v0.19.0

func NewAdminAPIServer(tb testing.TB, testDatabaseInstance *database.TestInstance) *AdminAPIServerResponse

NewAdminAPIServer creates a new test AdminAPI server instance. See NewHarnessServer for more information.

type BootstrapResponse added in v0.20.0

type BootstrapResponse struct {
	Realm        *database.Realm
	AdminAPIKey  string
	DeviceAPIKey string
	StatsAPIKey  string
	// contains filtered or unexported fields
}

BootstrapResponse is the response from Bootstrap.

func Bootstrap added in v0.20.0

func Bootstrap(db *database.Database) (*BootstrapResponse, error)

Bootstrap configures the database with an e2e realm (or re-uses one that already exists), and provisions new authorized apps for accessing the admin apis, device apis, and stats apis.

Callers should always call Cleanup() on the response to ensure temporary resources are purged.

func (*BootstrapResponse) Cleanup added in v0.20.0

func (r *BootstrapResponse) Cleanup() error

Cleanup deletes temporary resources created by the bootstrap.

type ENXRedirectServerConfigResponse added in v0.21.0

type ENXRedirectServerConfigResponse struct {
	Config   *config.RedirectConfig
	Database *database.Database
	Cacher   cache.Cacher
}

ENXRedirectServerConfigResponse is the response from creating an Redirect server config.

func NewENXRedirectServerConfig added in v0.21.0

func NewENXRedirectServerConfig(tb testing.TB, testDatabaseInstance *database.TestInstance) *ENXRedirectServerConfigResponse

NewENXRedirectServerConfig creates a new ENX redirect server configuration.

func (*ENXRedirectServerConfigResponse) NewServer added in v0.21.0

NewServer creates a new server.

type ENXRedirectServerResponse added in v0.21.0

type ENXRedirectServerResponse struct {
	Config   *config.RedirectConfig
	Database *database.Database
	Cacher   cache.Cacher
	Server   *server.Server
}

ENXRedirectServerResponse is the response from a test ENX redirect instance.

func NewENXRedirectServer added in v0.21.0

func NewENXRedirectServer(tb testing.TB, testDatabaseInstance *database.TestInstance) *ENXRedirectServerResponse

NewENXRedirectServer creates a new test ENX redirect server instance. See NewHarnessServer for more information.

type IntegrationSuite added in v0.20.0

type IntegrationSuite struct {
	// contains filtered or unexported fields
}

IntegrationSuite encompasses a local API server and Admin API server for testing. Both servers run in-memory on the local machine.

func NewIntegrationSuite added in v0.20.0

func NewIntegrationSuite(tb testing.TB, testDatabaseInstance *database.TestInstance) *IntegrationSuite

NewIntegrationSuite creates a new test suite for local integration testing.

func (*IntegrationSuite) APIServerClient added in v0.20.0

func (i *IntegrationSuite) APIServerClient() *clients.APIServerClient

APIServerClient returns the API server client.

func (*IntegrationSuite) AdminAPIServerClient added in v0.20.0

func (i *IntegrationSuite) AdminAPIServerClient() *clients.AdminAPIServerClient

AdminAPIServerClient returns the Admin API client.

type SQLConn added in v0.19.0

type SQLConn struct{}

func (*SQLConn) Begin added in v0.19.0

func (c *SQLConn) Begin() (driver.Tx, error)

func (*SQLConn) BeginTx added in v0.19.0

func (c *SQLConn) BeginTx() (driver.Tx, error)

func (*SQLConn) Close added in v0.19.0

func (c *SQLConn) Close() error

func (*SQLConn) Commit added in v0.19.0

func (c *SQLConn) Commit() error

func (*SQLConn) Exec added in v0.19.0

func (c *SQLConn) Exec(query string, args []driver.Value) (driver.Result, error)

func (*SQLConn) Prepare added in v0.19.0

func (c *SQLConn) Prepare(query string) (driver.Stmt, error)

func (*SQLConn) PrepareContext added in v0.19.0

func (c *SQLConn) PrepareContext(ctx context.Context, query string) (driver.Stmt, error)

func (*SQLConn) Query added in v0.19.0

func (c *SQLConn) Query(query string, args []driver.Value) (driver.Rows, error)

func (*SQLConn) QueryContext added in v0.19.0

func (c *SQLConn) QueryContext(ctx context.Context, query string, args []driver.NamedValue) (driver.Rows, error)

func (*SQLConn) Rollback added in v0.19.0

func (c *SQLConn) Rollback() error

type SQLDriver added in v0.19.0

type SQLDriver struct{}

SQLDriver is a test SQL driver implementation that returns an error for most queries and operations. It's used to test how the system behaves under connection errors or other database-level failures.

func (*SQLDriver) Connect added in v0.19.0

func (d *SQLDriver) Connect(ctx context.Context) (driver.Conn, error)

func (*SQLDriver) Driver added in v0.19.0

func (d *SQLDriver) Driver() driver.Driver

func (*SQLDriver) Open added in v0.19.0

func (d *SQLDriver) Open(name string) (driver.Conn, error)

type ServerConfigResponse added in v0.19.0

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

ServerConfigResponse is the response from creating a server config.

func NewServerConfig added in v0.19.0

func NewServerConfig(tb testing.TB, testDatabaseInstance *database.TestInstance) *ServerConfigResponse

NewServerConfig creates a new server configuration. It creates all the keys, databases, and cacher, but does not actually start the server. All cleanup is scheduled by t.Cleanup.

func (*ServerConfigResponse) NewServer added in v0.19.0

type TestHarnessResponse added in v0.19.0

type TestHarnessResponse struct {
	Cacher      cache.Cacher
	CacheConfig *cache.Config

	Database       *database.Database
	DatabaseConfig *database.Config

	ObservabilityConfig *observability.Config

	KeyManager       keys.KeyManager
	KeyManagerConfig *keys.Config

	RateLimiter       limiter.Store
	RateLimiterConfig *ratelimit.Config
}

func NewTestHarness added in v0.19.0

func NewTestHarness(tb testing.TB, testDatabaseInstance *database.TestInstance) *TestHarnessResponse

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, testDatabaseInstance *database.TestInstance) *TestServerResponse

NewServer creates a new test UI server instance. See NewHarnessServer for more information.

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) ProvisionAndLogin added in v0.19.0

func (r *TestServerResponse) ProvisionAndLogin() (*database.Realm, *database.User, *sessions.Session, error)

ProvisionAndLogin provisions and authenticates the initial user, realm, permissions on the realm, and session cookie.

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