MCPcopy
hub / github.com/ory/kratos / SubmitLoginFormCtx

Function SubmitLoginFormCtx

pkg/testhelpers/selfservice_login.go:323–362  ·  view source on GitHub ↗

SubmitLoginFormCtx 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

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

Source from the content-addressed store, hash-verified

321// the form values with `withValues`, and submits the form. Returns the body and checks for expectedStatusCode and
322// expectedURL on completion
323func SubmitLoginFormCtx(
324 ctx context.Context,
325 t *testing.T,
326 isAPI bool,
327 hc *http.Client,
328 publicTS *httptest.Server,
329 withValues func(v url.Values),
330 isSPA bool,
331 forced bool,
332 expectedStatusCode int,
333 expectedURL string,
334 opts ...InitFlowWithOption,
335) string {
336 if hc == nil {
337 hc = new(http.Client)
338 if !isAPI {
339 hc = NewClientWithCookies(t)
340 }
341 }
342
343 hc.Transport = NewTransportWithLogger(hc.Transport, t)
344 var f *kratos.LoginFlow
345 if isAPI {
346 f = InitializeLoginFlowViaAPICtx(ctx, t, hc, publicTS, forced, opts...)
347 } else {
348 f = InitializeLoginFlowViaBrowserCtx(ctx, t, hc, publicTS, forced, isSPA, false, false, opts...)
349 }
350
351 time.Sleep(time.Millisecond) // add a bit of delay to allow `1ns` to time out.
352
353 payload := SDKFormFieldsToURLValues(f.Ui.Nodes)
354 withValues(payload)
355 b, res := LoginMakeRequestCtx(ctx, t, isAPI, isSPA, f, hc, EncodeFormAsJSON(t, isAPI, payload))
356 assert.EqualValuesf(t, expectedStatusCode, res.StatusCode, "%s", b)
357 assert.Containsf(t, res.Request.URL.String(), expectedURL, "%+v\n\t%s", res.Request, b)
358
359 t.Logf("%+v", res.Header)
360
361 return b
362}

Callers 2

TestCompleteLoginFunction · 0.92
SubmitLoginFormFunction · 0.85

Calls 9

NewClientWithCookiesFunction · 0.85
NewTransportWithLoggerFunction · 0.85
SDKFormFieldsToURLValuesFunction · 0.85
LoginMakeRequestCtxFunction · 0.85
EncodeFormAsJSONFunction · 0.85
StringMethod · 0.65
LogfMethod · 0.45

Tested by 1

TestCompleteLoginFunction · 0.74