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

Function SubmitRecoveryForm

pkg/testhelpers/selfservice_verification.go:200–228  ·  view source on GitHub ↗

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,
)

Source from the content-addressed store, hash-verified

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.
200func 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
230func PersistNewRecoveryFlow(t *testing.T, strategies recovery.Strategies, conf *config.Config, reg *driver.RegistryDefault) *recovery.Flow {
231 t.Helper()

Calls 8

NewTransportWithLoggerFunction · 0.85
SDKFormFieldsToURLValuesFunction · 0.85
RecoveryMakeRequestFunction · 0.85
EncodeFormAsJSONFunction · 0.85
ContainsMethod · 0.80
StringMethod · 0.65