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.
( t *testing.T, isAPI bool, isSPA bool, hc *http.Client, publicTS *httptest.Server, withValues func(v url.Values), expectedStatusCode int, expectedURL string, )
| 198 | // SubmitRecoveryForm initiates a registration flow (for Browser and API!), fills out the form and modifies |
| 199 | // the form values with `withValues`, and submits the form. If completed, it will return the flow as JSON. |
| 200 | func SubmitRecoveryForm( |
| 201 | t *testing.T, |
| 202 | isAPI bool, |
| 203 | isSPA bool, |
| 204 | hc *http.Client, |
| 205 | publicTS *httptest.Server, |
| 206 | withValues func(v url.Values), |
| 207 | expectedStatusCode int, |
| 208 | expectedURL string, |
| 209 | ) string { |
| 210 | hc.Transport = NewTransportWithLogger(hc.Transport, t) |
| 211 | var f *kratos.RecoveryFlow |
| 212 | if isAPI { |
| 213 | f = InitializeRecoveryFlowViaAPI(t, hc, publicTS) |
| 214 | } else { |
| 215 | f = InitializeRecoveryFlowViaBrowser(t, hc, isSPA, publicTS, nil) |
| 216 | } |
| 217 | |
| 218 | time.Sleep(time.Millisecond) // add a bit of delay to allow `1ns` to time out. |
| 219 | |
| 220 | formPayload := SDKFormFieldsToURLValues(f.Ui.Nodes) |
| 221 | withValues(formPayload) |
| 222 | |
| 223 | b, res := RecoveryMakeRequest(t, isAPI || isSPA, f, hc, EncodeFormAsJSON(t, isAPI || isSPA, formPayload)) |
| 224 | assert.EqualValues(t, expectedStatusCode, res.StatusCode, "%s", b) |
| 225 | assert.Contains(t, res.Request.URL.String(), expectedURL, "%+v\n\t%s", res.Request, b) |
| 226 | |
| 227 | return b |
| 228 | } |
| 229 | |
| 230 | func PersistNewRecoveryFlow(t *testing.T, strategies recovery.Strategies, conf *config.Config, reg *driver.RegistryDefault) *recovery.Flow { |
| 231 | t.Helper() |