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, )
| 321 | // the form values with `withValues`, and submits the form. Returns the body and checks for expectedStatusCode and |
| 322 | // expectedURL on completion |
| 323 | func 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 | } |