Skip to content

Commit

Permalink
Add test for the return_to fix
Browse files Browse the repository at this point in the history
  • Loading branch information
supercairos committed Dec 15, 2022
1 parent 9ebdc45 commit 63c2673
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions selfservice/flow/registration/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ func TestHandlerRedirectOnAuthenticated(t *testing.T) {
router := x.NewRouterPublic()
ts, _ := testhelpers.NewKratosServerWithRouters(t, reg, router, x.NewRouterAdmin())

// Set it first as otherwise it will overwrite the ViperKeySelfServiceBrowserDefaultReturnTo key;
returnToTS := testhelpers.NewRedirTS(t, "return_to", conf)
conf.MustSet(ctx, config.ViperKeyURLsAllowedReturnToDomains, []string{returnToTS.URL})

redirTS := testhelpers.NewRedirTS(t, "already authenticated", conf)
conf.MustSet(ctx, config.ViperKeySelfServiceRegistrationEnabled, true)
testhelpers.SetDefaultIdentitySchema(conf, "file://./stub/identity.schema.json")
Expand All @@ -58,6 +62,12 @@ func TestHandlerRedirectOnAuthenticated(t *testing.T) {
assert.Contains(t, res.Request.URL.String(), registration.RouteInitAPIFlow)
assertx.EqualAsJSON(t, registration.ErrAlreadyLoggedIn, json.RawMessage(gjson.GetBytes(body, "error").Raw))
})

t.Run("does redirect to return_to url on authenticated request", func(t *testing.T) {
body, res := testhelpers.MockMakeAuthenticatedRequest(t, reg, conf, router.Router, x.NewTestHTTPRequest(t, "GET", ts.URL+registration.RouteInitBrowserFlow+"?return_to="+returnToTS.URL, nil))
assert.Contains(t, res.Request.URL.String(), returnToTS.URL)
assert.EqualValues(t, "return_to", string(body))
})
}

func TestInitFlow(t *testing.T) {
Expand Down

0 comments on commit 63c2673

Please sign in to comment.