forked from ory/kratos
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(selfservice): recovery self service flow passes on return_to URL (o…
- Loading branch information
1 parent
ba038d0
commit da6e50c
Showing
8 changed files
with
102 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -382,7 +382,7 @@ func TestRecovery(t *testing.T) { | |
}) | ||
|
||
t.Run("description=should recover an account", func(t *testing.T) { | ||
var check = func(t *testing.T, recoverySubmissionResponse, recoveryEmail string) { | ||
var check = func(t *testing.T, recoverySubmissionResponse, recoveryEmail, returnTo string) { | ||
addr, err := reg.IdentityPool().FindVerifiableAddressByValue(context.Background(), identity.VerifiableAddressTypeEmail, recoveryEmail) | ||
assert.NoError(t, err) | ||
assert.False(t, addr.Verified) | ||
|
@@ -413,6 +413,7 @@ func TestRecovery(t *testing.T) { | |
body := ioutilx.MustReadAll(res.Body) | ||
assert.Equal(t, text.NewRecoverySuccessful(time.Now().Add(time.Hour)).Text, | ||
gjson.GetBytes(body, "ui.messages.0.text").String()) | ||
assert.Equal(t, returnTo, gjson.GetBytes(body, "return_to").String()) | ||
|
||
addr, err = reg.IdentityPool().FindVerifiableAddressByValue(context.Background(), identity.VerifiableAddressTypeEmail, recoveryEmail) | ||
assert.NoError(t, err) | ||
|
@@ -433,23 +434,46 @@ func TestRecovery(t *testing.T) { | |
createIdentityToRecover(email) | ||
check(t, expectSuccess(t, nil, false, false, func(v url.Values) { | ||
v.Set("email", email) | ||
}), email) | ||
}), email, "") | ||
}) | ||
|
||
t.Run("type=spa", func(t *testing.T) { | ||
t.Run("type=browser set return_to", func(t *testing.T) { | ||
email := "[email protected]" | ||
returnTo := "https://www.ory.sh" | ||
createIdentityToRecover(email) | ||
|
||
hc := testhelpers.NewClientWithCookies(t) | ||
hc.Transport = testhelpers.NewTransportWithLogger(http.DefaultTransport, t).RoundTripper | ||
|
||
f := testhelpers.InitializeRecoveryFlowViaBrowser(t, hc, false, public, url.Values{"return_to": []string{returnTo}}) | ||
|
||
time.Sleep(time.Millisecond) // add a bit of delay to allow `1ns` to time out. | ||
|
||
formPayload := testhelpers.SDKFormFieldsToURLValues(f.Ui.Nodes) | ||
formPayload.Set("email", email) | ||
|
||
b, res := testhelpers.RecoveryMakeRequest(t, false, f, hc, testhelpers.EncodeFormAsJSON(t, false, formPayload)) | ||
assert.EqualValues(t, http.StatusOK, res.StatusCode, "%s", b) | ||
expectedURL := testhelpers.ExpectURL(false, public.URL+recovery.RouteSubmitFlow, conf.SelfServiceFlowRecoveryUI().String()) | ||
assert.Contains(t, res.Request.URL.String(), expectedURL, "%+v\n\t%s", res.Request, b) | ||
|
||
check(t, b, email, returnTo) | ||
}) | ||
|
||
t.Run("type=spa", func(t *testing.T) { | ||
email := "[email protected]" | ||
createIdentityToRecover(email) | ||
check(t, expectSuccess(t, nil, true, true, func(v url.Values) { | ||
v.Set("email", email) | ||
}), email) | ||
}), email, "") | ||
}) | ||
|
||
t.Run("type=api", func(t *testing.T) { | ||
email := "recoverme3@ory.sh" | ||
email := "recoverme4@ory.sh" | ||
createIdentityToRecover(email) | ||
check(t, expectSuccess(t, nil, true, false, func(v url.Values) { | ||
v.Set("email", email) | ||
}), email) | ||
}), email, "") | ||
}) | ||
}) | ||
|
||
|
@@ -490,7 +514,7 @@ func TestRecovery(t *testing.T) { | |
|
||
t.Run("description=should not be able to use an invalid link", func(t *testing.T) { | ||
c := testhelpers.NewClientWithCookies(t) | ||
f := testhelpers.InitializeRecoveryFlowViaBrowser(t, c, false, public) | ||
f := testhelpers.InitializeRecoveryFlowViaBrowser(t, c, false, public, nil) | ||
res, err := c.Get(f.Ui.Action + "&token=i-do-not-exist") | ||
require.NoError(t, err) | ||
assert.Equal(t, http.StatusOK, res.StatusCode) | ||
|
@@ -504,7 +528,7 @@ func TestRecovery(t *testing.T) { | |
}) | ||
|
||
t.Run("description=should not be able to use an outdated link", func(t *testing.T) { | ||
recoveryEmail := "recoverme4@ory.sh" | ||
recoveryEmail := "recoverme5@ory.sh" | ||
createIdentityToRecover(recoveryEmail) | ||
conf.MustSet(config.ViperKeySelfServiceRecoveryRequestLifespan, time.Millisecond*200) | ||
t.Cleanup(func() { | ||
|
@@ -530,7 +554,7 @@ func TestRecovery(t *testing.T) { | |
}) | ||
|
||
t.Run("description=should not be able to use an outdated flow", func(t *testing.T) { | ||
recoveryEmail := "recoverme5@ory.sh" | ||
recoveryEmail := "recoverme6@ory.sh" | ||
createIdentityToRecover(recoveryEmail) | ||
conf.MustSet(config.ViperKeySelfServiceRecoveryRequestLifespan, time.Millisecond*200) | ||
t.Cleanup(func() { | ||
|
@@ -601,7 +625,7 @@ func TestDisabledEndpoint(t *testing.T) { | |
c := testhelpers.NewClientWithCookies(t) | ||
|
||
t.Run("description=can not recover an account by get request when link method is disabled", func(t *testing.T) { | ||
f := testhelpers.InitializeRecoveryFlowViaBrowser(t, c, false, publicTS) | ||
f := testhelpers.InitializeRecoveryFlowViaBrowser(t, c, false, publicTS, nil) | ||
u := publicTS.URL + recovery.RouteSubmitFlow + "?flow=" + f.Id + "&token=endpoint-disabled" | ||
res, err := c.Get(u) | ||
require.NoError(t, err) | ||
|
@@ -612,7 +636,7 @@ func TestDisabledEndpoint(t *testing.T) { | |
}) | ||
|
||
t.Run("description=can not recover an account by post request when link method is disabled", func(t *testing.T) { | ||
f := testhelpers.InitializeRecoveryFlowViaBrowser(t, c, false, publicTS) | ||
f := testhelpers.InitializeRecoveryFlowViaBrowser(t, c, false, publicTS, nil) | ||
u := publicTS.URL + recovery.RouteSubmitFlow + "?flow=" + f.Id | ||
res, err := c.PostForm(u, url.Values{"email": {"[email protected]"}, "method": {"link"}}) | ||
require.NoError(t, err) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters