Skip to content

Commit

Permalink
fix: add flow id when return_to is passed to the verification (#2482)
Browse files Browse the repository at this point in the history
  • Loading branch information
jhonatanhulse committed May 23, 2022
1 parent 083e67f commit c2b1c23
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 5 deletions.
4 changes: 3 additions & 1 deletion selfservice/flow/verification/flow.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,9 @@ func (f *Flow) Valid() error {
}

func (f *Flow) AppendTo(src *url.URL) *url.URL {
return urlx.CopyWithQuery(src, url.Values{"flow": {f.ID.String()}})
values := src.Query()
values.Set("flow", f.ID.String())
return urlx.CopyWithQuery(src, values)
}

func (f Flow) GetID() uuid.UUID {
Expand Down
2 changes: 1 addition & 1 deletion selfservice/strategy/link/strategy_verification.go
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ func (s *Strategy) verificationUseToken(w http.ResponseWriter, r *http.Request,
return errors.WithStack(flow.ErrCompletedByStrategy)
}

http.Redirect(w, r, returnTo.String(), http.StatusSeeOther)
http.Redirect(w, r, f.AppendTo(returnTo).String(), http.StatusSeeOther)
return errors.WithStack(flow.ErrCompletedByStrategy)
}

Expand Down
3 changes: 1 addition & 2 deletions selfservice/strategy/link/strategy_verification_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,6 @@ func TestVerification(t *testing.T) {
assert.Equal(t, http.StatusSeeOther, res.StatusCode)
redirectURL, err := res.Location()
require.NoError(t, err)
assert.Equal(t, returnToURL, redirectURL.String())

assert.Equal(t, returnToURL + "?flow=" + flow.ID.String(), redirectURL.String())
})
}
4 changes: 3 additions & 1 deletion test/e2e/cypress/support/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -873,14 +873,16 @@ Cypress.Commands.add(
expect(message.toAddresses[0].trim()).to.equal(email)

const link = parseHtml(message.body).querySelector('a')
const flow = new URL(link.href).searchParams.get('flow')

expect(link).to.not.be.null
expect(link.href).to.contain(APP_URL)

cy.request({ url: link.href, followRedirect: false }).should(
(response) => {
expect(response.status).to.eq(303)
if (redirectTo) {
expect(response.redirectedToUrl).to.eq(redirectTo)
expect(response.redirectedToUrl).to.eq(`${redirectTo}?flow=${flow}`)
} else {
expect(response.redirectedToUrl).to.not.contain('verification')
}
Expand Down

0 comments on commit c2b1c23

Please sign in to comment.