testhelpers

package
v0.9.0-alpha.1.pre.0 Latest Latest
Warning

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

Go to latest
Published: Mar 21, 2022 License: Apache-2.0 Imports: 71 Imported by: 0

Documentation

Overview

nolint

nolint

nolint

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddAndLoginIdentities

func AddAndLoginIdentities(t *testing.T, reg *driver.RegistryDefault, public *httptest.Server, ids map[string]*identity.Identity) map[string]*http.Client

AddAndLoginIdentities adds the given identities to the store (like a registration flow) and returns http.Clients which contain their sessions.

func CheckE2EServerOnHTTP

func CheckE2EServerOnHTTP(t *testing.T, publicPort, adminPort int) (publicUrl, adminUrl string)

func CheckE2EServerOnHTTPS

func CheckE2EServerOnHTTPS(t *testing.T, publicPort, adminPort int) (publicUrl, adminUrl string)

func CourierExpectLinkInMessage

func CourierExpectLinkInMessage(t *testing.T, message *courier.Message, offset int) string

func CourierExpectMessage

func CourierExpectMessage(t *testing.T, reg interface {
	courier.PersistenceProvider
}, recipient, subject string) *courier.Message

func CreateSession

func CreateSession(t *testing.T, reg driver.Registry) *session.Session

func EncodeFormAsJSON

func EncodeFormAsJSON(t *testing.T, isApi bool, values url.Values) (payload string)

func EnsureAAL

func EnsureAAL(t *testing.T, c *http.Client, ts *httptest.Server, aal string, methods ...string)

func ExpectStatusCode

func ExpectStatusCode(isAPI bool, api, browser int) int

func ExpectURL

func ExpectURL(isAPI bool, api, browser string) string

func GenerateTLSCertificateFilesForTests

func GenerateTLSCertificateFilesForTests(t *testing.T, certPath, keyPath string)

func GetRecoveryFlow

func GetRecoveryFlow(t *testing.T, client *http.Client, ts *httptest.Server) *kratos.SelfServiceRecoveryFlow

func GetSelfServiceRedirectLocation

func GetSelfServiceRedirectLocation(t *testing.T, url string) string

func GetVerificationFlow

func GetVerificationFlow(t *testing.T, client *http.Client, ts *httptest.Server) *kratos.SelfServiceVerificationFlow

func HTTPPostForm

func HTTPPostForm(t *testing.T, client *http.Client, remote string, in *url.Values) ([]byte, *http.Response)

func HTTPRequestJSON

func HTTPRequestJSON(t *testing.T, client *http.Client, method string, url string, in interface{}) ([]byte, *http.Response)

func InitKratosServers

func InitKratosServers(t *testing.T, reg driver.Registry, public, admin *httptest.Server)

func InitializeLoginFlowViaAPI

func InitializeLoginFlowViaAPI(t *testing.T, client *http.Client, ts *httptest.Server, forced bool, opts ...InitFlowWithOption) *kratos.SelfServiceLoginFlow

func InitializeLoginFlowViaBrowser

func InitializeLoginFlowViaBrowser(t *testing.T, client *http.Client, ts *httptest.Server, forced bool, isSPA bool, opts ...InitFlowWithOption) *kratos.SelfServiceLoginFlow

func InitializeRecoveryFlowViaAPI

func InitializeRecoveryFlowViaAPI(t *testing.T, client *http.Client, ts *httptest.Server) *kratos.SelfServiceRecoveryFlow

func InitializeRecoveryFlowViaBrowser

func InitializeRecoveryFlowViaBrowser(t *testing.T, client *http.Client, isSPA bool, ts *httptest.Server, values url.Values) *kratos.SelfServiceRecoveryFlow

func InitializeRegistrationFlowViaAPI

func InitializeRegistrationFlowViaAPI(t *testing.T, client *http.Client, ts *httptest.Server) *kratos.SelfServiceRegistrationFlow

func InitializeRegistrationFlowViaBrowser

func InitializeRegistrationFlowViaBrowser(t *testing.T, client *http.Client, ts *httptest.Server, isSPA bool, opts ...InitFlowWithOption) *kratos.SelfServiceRegistrationFlow

func InitializeSettingsFlowViaAPI

func InitializeSettingsFlowViaAPI(t *testing.T, client *http.Client, ts *httptest.Server) *kratos.SelfServiceSettingsFlow

func InitializeSettingsFlowViaBrowser

func InitializeSettingsFlowViaBrowser(t *testing.T, client *http.Client, isSPA bool, ts *httptest.Server) *kratos.SelfServiceSettingsFlow

func InitializeVerificationFlowViaAPI

func InitializeVerificationFlowViaAPI(t *testing.T, client *http.Client, ts *httptest.Server) *kratos.SelfServiceVerificationFlow

func InitializeVerificationFlowViaBrowser

func InitializeVerificationFlowViaBrowser(t *testing.T, client *http.Client, isSPA bool, ts *httptest.Server) *kratos.SelfServiceVerificationFlow

func JSONEq

func JSONEq(t *testing.T, expected, actual interface{}, messageAndArgs ...interface{})

func LogJSON

func LogJSON(t *testing.T, v interface{})

func LoginMakeRequest

func LoginMakeRequest(
	t *testing.T,
	isAPI bool,
	isSPA bool,
	f *kratos.SelfServiceLoginFlow,
	hc *http.Client,
	values string,
) (string, *http.Response)

func MockGetSession

func MockGetSession(t *testing.T, reg mockDeps) httprouter.Handle

func MockHydrateCookieClient

func MockHydrateCookieClient(t *testing.T, c *http.Client, u string)

func MockMakeAuthenticatedRequest

func MockMakeAuthenticatedRequest(t *testing.T, reg mockDeps, conf *config.Config, router *httprouter.Router, req *http.Request) ([]byte, *http.Response)

func MockSessionCreateHandler

func MockSessionCreateHandler(t *testing.T, reg mockDeps) (httprouter.Handle, *session.Session)

func MockSessionCreateHandlerWithIdentity

func MockSessionCreateHandlerWithIdentity(t *testing.T, reg mockDeps, i *identity.Identity) (httprouter.Handle, *session.Session)

func MockSessionCreateHandlerWithIdentityAndAMR

func MockSessionCreateHandlerWithIdentityAndAMR(t *testing.T, reg mockDeps, i *identity.Identity, methods []identity.CredentialsType) (httprouter.Handle, *session.Session)

func MockSetSession

func MockSetSession(t *testing.T, reg mockDeps, conf *config.Config) httprouter.Handle

func NewClientWithCookies

func NewClientWithCookies(t *testing.T) *http.Client

func NewDebugClient

func NewDebugClient(t *testing.T) *http.Client

func NewErrorTestServer

func NewErrorTestServer(t *testing.T, reg interface {
	errorx.PersistenceProvider
	config.Provider
}) *httptest.Server

func NewFakeCSRFNode

func NewFakeCSRFNode() *kratos.UiNode

func NewHTTPClientWithArbitrarySessionCookie

func NewHTTPClientWithArbitrarySessionCookie(t *testing.T, reg *driver.RegistryDefault) *http.Client

func NewHTTPClientWithArbitrarySessionToken

func NewHTTPClientWithArbitrarySessionToken(t *testing.T, reg *driver.RegistryDefault) *http.Client

func NewHTTPClientWithIdentitySessionCookie

func NewHTTPClientWithIdentitySessionCookie(t *testing.T, reg *driver.RegistryDefault, id *identity.Identity) *http.Client

func NewHTTPClientWithIdentitySessionToken

func NewHTTPClientWithIdentitySessionToken(t *testing.T, reg *driver.RegistryDefault, id *identity.Identity) *http.Client

func NewHTTPClientWithSessionCookie

func NewHTTPClientWithSessionCookie(t *testing.T, reg *driver.RegistryDefault, sess *session.Session) *http.Client

func NewHTTPClientWithSessionToken

func NewHTTPClientWithSessionToken(t *testing.T, reg *driver.RegistryDefault, sess *session.Session) *http.Client

func NewHTTPDeleteJSONRequest

func NewHTTPDeleteJSONRequest(t *testing.T, url string, in interface{}) *http.Request

func NewHTTPGetAJAXRequest

func NewHTTPGetAJAXRequest(t *testing.T, url string) *http.Request

func NewHTTPGetJSONRequest

func NewHTTPGetJSONRequest(t *testing.T, url string) *http.Request

func NewHTTPTestServer

func NewHTTPTestServer(t *testing.T, h http.Handler) *httptest.Server

func NewKratosServer

func NewKratosServer(t *testing.T, reg driver.Registry) (public, admin *httptest.Server)

func NewKratosServerWithCSRF

func NewKratosServerWithCSRF(t *testing.T, reg driver.Registry) (public, admin *httptest.Server)

func NewKratosServerWithCSRFAndRouters

func NewKratosServerWithCSRFAndRouters(t *testing.T, reg driver.Registry) (public, admin *httptest.Server, rp *x.RouterPublic, ra *x.RouterAdmin)

func NewKratosServerWithRouters

func NewKratosServerWithRouters(t *testing.T, reg driver.Registry, rp *x.RouterPublic, ra *x.RouterAdmin) (public, admin *httptest.Server)

func NewKratosServers

func NewKratosServers(t *testing.T) (public, admin *httptest.Server)

func NewLoginUIFlowEchoServer

func NewLoginUIFlowEchoServer(t *testing.T, reg driver.Registry) *httptest.Server

func NewLoginUIWith401Response

func NewLoginUIWith401Response(t *testing.T, c *config.Config) *httptest.Server

func NewMethodSubmit

func NewMethodSubmit(group, value string) *kratos.UiNode

func NewNoRedirectClientWithCookies

func NewNoRedirectClientWithCookies(t *testing.T) *http.Client

func NewNoRedirectHTTPClientWithArbitrarySessionCookie

func NewNoRedirectHTTPClientWithArbitrarySessionCookie(t *testing.T, reg *driver.RegistryDefault) *http.Client

func NewNoRedirectHTTPClientWithSessionCookie

func NewNoRedirectHTTPClientWithSessionCookie(t *testing.T, reg *driver.RegistryDefault, sess *session.Session) *http.Client

func NewPasswordNode

func NewPasswordNode() *kratos.UiNode

func NewRecoveryUIFlowEchoServer

func NewRecoveryUIFlowEchoServer(t *testing.T, reg driver.Registry) *httptest.Server

func NewRedirNoSessionTS

func NewRedirNoSessionTS(t *testing.T, reg interface {
	x.WriterProvider
	session.ManagementProvider
	config.Provider
}) *httptest.Server

func NewRedirSessionEchoTS

func NewRedirSessionEchoTS(t *testing.T, reg interface {
	x.WriterProvider
	session.ManagementProvider
	config.Provider
}) *httptest.Server

func NewRedirTS

func NewRedirTS(t *testing.T, body string, conf *config.Config) *httptest.Server

func NewRegistrationUIFlowEchoServer

func NewRegistrationUIFlowEchoServer(t *testing.T, reg driver.Registry) *httptest.Server

func NewRequest

func NewRequest(t *testing.T, isAPI bool, method string, url string, payload io.Reader) *http.Request

func NewSDKClient

func NewSDKClient(ts *httptest.Server) *kratos.APIClient

func NewSDKClientFromURL

func NewSDKClientFromURL(u string) *kratos.APIClient

func NewSDKCustomClient

func NewSDKCustomClient(ts *httptest.Server, client *http.Client) *kratos.APIClient

func NewSDKEmailNode

func NewSDKEmailNode(group string) *kratos.UiNode

func NewSDKOIDCNode

func NewSDKOIDCNode(name, provider string) *kratos.UiNode

func NewSessionClient

func NewSessionClient(t *testing.T, u string) *http.Client

func NewSettingsAPIServer

func NewSettingsAPIServer(t *testing.T, reg *driver.RegistryDefault, ids map[string]*identity.Identity) (*httptest.Server, *httptest.Server, map[string]*http.Client)

func NewSettingsLoginAcceptAPIServer

func NewSettingsLoginAcceptAPIServer(t *testing.T, publicClient *kratos.APIClient, conf *config.Config) *httptest.Server

func NewSettingsUIEchoServer

func NewSettingsUIEchoServer(t *testing.T, reg *driver.RegistryDefault) *httptest.Server

func NewSettingsUIFlowEchoServer

func NewSettingsUIFlowEchoServer(t *testing.T, reg driver.Registry) *httptest.Server

func NewSettingsUITestServer

func NewSettingsUITestServer(t *testing.T, conf *config.Config) *httptest.Server

func NewVerificationUIFlowEchoServer

func NewVerificationUIFlowEchoServer(t *testing.T, reg driver.Registry) *httptest.Server

func RandomEmail

func RandomEmail() string

func RecoveryMakeRequest

func RecoveryMakeRequest(
	t *testing.T,
	isAPI bool,
	f *kratos.SelfServiceRecoveryFlow,
	hc *http.Client,
	values string,
) (string, *http.Response)

func RegistrationMakeRequest

func RegistrationMakeRequest(
	t *testing.T,
	isAPI bool,
	isSPA bool,
	f *kratos.SelfServiceRegistrationFlow,
	hc *http.Client,
	values string,
) (string, *http.Response)

func SDKFormFieldsToURLValues

func SDKFormFieldsToURLValues(ff []kratos.UiNode) url.Values

func SelfServiceHookConfigReset

func SelfServiceHookConfigReset(t *testing.T, conf *config.Config) func()

func SelfServiceHookCreateFakeIdentity

func SelfServiceHookCreateFakeIdentity(t *testing.T, reg driver.Registry) *identity.Identity

func SelfServiceHookErrorHandler

func SelfServiceHookErrorHandler(t *testing.T, w http.ResponseWriter, r *http.Request, abortErr error, actualErr error) bool

func SelfServiceHookFakeIdentity

func SelfServiceHookFakeIdentity(t *testing.T) *identity.Identity

func SelfServiceHookLoginErrorHandler

func SelfServiceHookLoginErrorHandler(t *testing.T, w http.ResponseWriter, r *http.Request, err error) bool

func SelfServiceHookLoginSetDefaultRedirectTo

func SelfServiceHookLoginSetDefaultRedirectTo(t *testing.T, conf *config.Config, value string)

func SelfServiceHookLoginSetDefaultRedirectToStrategy

func SelfServiceHookLoginSetDefaultRedirectToStrategy(t *testing.T, conf *config.Config, strategy, value string)

func SelfServiceHookLoginViperSetPost

func SelfServiceHookLoginViperSetPost(t *testing.T, conf *config.Config, strategy string, c []config.SelfServiceHook)

func SelfServiceHookRegistrationErrorHandler

func SelfServiceHookRegistrationErrorHandler(t *testing.T, w http.ResponseWriter, r *http.Request, err error) bool

func SelfServiceHookRegistrationSetDefaultRedirectTo

func SelfServiceHookRegistrationSetDefaultRedirectTo(t *testing.T, conf *config.Config, value string)

func SelfServiceHookRegistrationSetDefaultRedirectToStrategy

func SelfServiceHookRegistrationSetDefaultRedirectToStrategy(t *testing.T, conf *config.Config, strategy, value string)

func SelfServiceHookRegistrationViperSetPost

func SelfServiceHookRegistrationViperSetPost(t *testing.T, conf *config.Config, strategy string, c []config.SelfServiceHook)

func SelfServiceHookSettingsErrorHandler

func SelfServiceHookSettingsErrorHandler(t *testing.T, w http.ResponseWriter, r *http.Request, err error) bool

func SelfServiceHookSettingsSetDefaultRedirectTo

func SelfServiceHookSettingsSetDefaultRedirectTo(t *testing.T, conf *config.Config, value string)

func SelfServiceHookSettingsSetDefaultRedirectToStrategy

func SelfServiceHookSettingsSetDefaultRedirectToStrategy(t *testing.T, conf *config.Config, strategy, value string)

func SelfServiceMakeHookRequest

func SelfServiceMakeHookRequest(t *testing.T, ts *httptest.Server, suffix string, asAPI bool, query url.Values) (*http.Response, string)

func SelfServiceMakeLoginPostHookRequest

func SelfServiceMakeLoginPostHookRequest(t *testing.T, ts *httptest.Server, asAPI bool, query url.Values) (*http.Response, string)

func SelfServiceMakeLoginPreHookRequest

func SelfServiceMakeLoginPreHookRequest(t *testing.T, ts *httptest.Server) (*http.Response, string)

func SelfServiceMakeRegistrationPostHookRequest

func SelfServiceMakeRegistrationPostHookRequest(t *testing.T, ts *httptest.Server, asAPI bool, query url.Values) (*http.Response, string)

func SelfServiceMakeRegistrationPreHookRequest

func SelfServiceMakeRegistrationPreHookRequest(t *testing.T, ts *httptest.Server) (*http.Response, string)

func SelfServiceMakeSettingsPostHookRequest

func SelfServiceMakeSettingsPostHookRequest(t *testing.T, ts *httptest.Server, asAPI bool, query url.Values) (*http.Response, string)

func SetDefaultIdentitySchema

func SetDefaultIdentitySchema(conf *config.Config, url string)

func SetDefaultIdentitySchemaFromRaw

func SetDefaultIdentitySchemaFromRaw(conf *config.Config, schema []byte)

SetDefaultIdentitySchemaFromRaw allows setting the default identity schema from a raw JSON string.

func SetIdentitySchemas

func SetIdentitySchemas(t *testing.T, conf *config.Config, schemas map[string]string)

SetIdentitySchemas sets the identity schemas in viper config:

testhelpers.SetIdentitySchemas(map[string]string{"customer": "file://customer.json"})

func SettingsMakeRequest

func SettingsMakeRequest(
	t *testing.T,
	isAPI bool,
	isSPA bool,
	f *kratos.SelfServiceSettingsFlow,
	hc *http.Client,
	values string,
) (string, *http.Response)

func SkipIfNetworkContext

func SkipIfNetworkContext(t *testing.T, ctx context.Context)

func SnapshotTExcept

func SnapshotTExcept(t *testing.T, actual interface{}, except []string)

func StartE2EServer

func StartE2EServer(t *testing.T, configFile string, configOptions ConfigOptions) (publicUrl, adminUrl string)

func StartE2EServerOnly

func StartE2EServerOnly(t *testing.T, configFile string, isTLS bool, configOptions ConfigOptions) (publicPort, adminPort int)

func StrategyEnable

func StrategyEnable(t *testing.T, c *config.Config, strategy string, enable bool)

func SubmitLoginForm

func SubmitLoginForm(
	t *testing.T,
	isAPI bool,
	hc *http.Client,
	publicTS *httptest.Server,
	withValues func(v url.Values),
	isSPA bool,
	forced bool,
	expectedStatusCode int,
	expectedURL string,
) string

SubmitLoginForm initiates a login flow (for Browser and API!), fills out the form and modifies the form values with `withValues`, and submits the form. Returns the body and checks for expectedStatusCode and expectedURL on completion

func SubmitRecoveryForm

func SubmitRecoveryForm(
	t *testing.T,
	isAPI bool,
	isSPA bool,
	hc *http.Client,
	publicTS *httptest.Server,
	withValues func(v url.Values),
	expectedStatusCode int,
	expectedURL string,
) string

SubmitRecoveryForm initiates a registration flow (for Browser and API!), fills out the form and modifies the form values with `withValues`, and submits the form. If completed, it will return the flow as JSON.

func SubmitRegistrationForm

func SubmitRegistrationForm(
	t *testing.T,
	isAPI bool,
	hc *http.Client,
	publicTS *httptest.Server,
	withValues func(v url.Values),
	isSPA bool,
	expectedStatusCode int,
	expectedURL string,
) string

SubmitRegistrationForm (for Browser and API!), fills out the form and modifies // the form values with `withValues`, and submits the form. Returns the body and checks for expectedStatusCode and // expectedURL on completion

func SubmitSettingsForm

func SubmitSettingsForm(
	t *testing.T,
	isAPI bool,
	isSPA bool,
	hc *http.Client,
	publicTS *httptest.Server,
	withValues func(v url.Values),
	expectedStatusCode int,
	expectedURL string,
) string

SubmitSettingsForm initiates a settings flow (for Browser and API!), fills out the form and modifies the form values with `withValues`, and submits the form. If completed, it will return the flow as JSON.

func SubmitVerificationForm

func SubmitVerificationForm(
	t *testing.T,
	isAPI bool,
	isSPA bool,
	hc *http.Client,
	publicTS *httptest.Server,
	withValues func(v url.Values),
	expectedStatusCode int,
	expectedURL string,
) string

SubmitVerificationForm initiates a registration flow (for Browser and API!), fills out the form and modifies the form values with `withValues`, and submits the form. If completed, it will return the flow as JSON.

func TestSelfServicePreHook

func TestSelfServicePreHook(
	configKey string,
	makeRequestPre func(t *testing.T, ts *httptest.Server) (*http.Response, string),
	newServer func(t *testing.T) *httptest.Server,
	conf *config.Config,
) func(t *testing.T)

func UseConfigFile

func UseConfigFile(t *testing.T, path string) *pflag.FlagSet

func VerificationMakeRequest

func VerificationMakeRequest(
	t *testing.T,
	isAPI bool,
	f *kratos.SelfServiceVerificationFlow,
	hc *http.Client,
	values string,
) (string, *http.Response)

Types

type ConfigOptions

type ConfigOptions map[string]interface{}

type InitFlowWithOption

type InitFlowWithOption func(*initFlowOptions)

func InitFlowWithRefresh

func InitFlowWithRefresh() InitFlowWithOption

func InitFlowWithReturnTo

func InitFlowWithReturnTo(returnTo string) InitFlowWithOption

type SessionLifespanProvider

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

func NewSessionLifespanProvider

func NewSessionLifespanProvider(expiresIn time.Duration) *SessionLifespanProvider

func (*SessionLifespanProvider) SessionLifespan

func (p *SessionLifespanProvider) SessionLifespan() time.Duration

type TransportWithLogger

type TransportWithLogger struct {
	http.RoundTripper
	// contains filtered or unexported fields
}

func NewTransportWithLogger

func NewTransportWithLogger(parent http.RoundTripper, t *testing.T) *TransportWithLogger

func (*TransportWithLogger) RoundTrip

func (ct *TransportWithLogger) RoundTrip(req *http.Request) (*http.Response, error)

Jump to

Keyboard shortcuts

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