Skip to content

Commit

Permalink
fix: verification redirect & continue label (#2905)
Browse files Browse the repository at this point in the history
This PR resolves an issue with the redirect after a successful verification, if not specified.
  • Loading branch information
jonas-jonas authored Nov 22, 2022
1 parent b6c212c commit e1119e8
Show file tree
Hide file tree
Showing 12 changed files with 45 additions and 42 deletions.
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,8 @@ test/e2e/hydra-kratos-login-consent/hydra-kratos-login-consent
*.log
test/e2e/proxy.json
test/e2e/kratos.*.yml

# Kratos executable
kratos
# VSCode debug artifact
__debug_bin
3 changes: 2 additions & 1 deletion cmd/clidoc/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ func init() {
"NewErrorValidationVerificationFlowExpired": text.NewErrorValidationVerificationFlowExpired(aSecondAgo),
"NewInfoSelfServiceVerificationSuccessful": text.NewInfoSelfServiceVerificationSuccessful(),
"NewVerificationEmailSent": text.NewVerificationEmailSent(),
"NewVerificationEmailWithCodeSent": text.NewVerificationEmailWithCodeSent(),
"NewErrorValidationVerificationTokenInvalidOrAlreadyUsed": text.NewErrorValidationVerificationTokenInvalidOrAlreadyUsed(),
"NewErrorValidationVerificationRetrySuccess": text.NewErrorValidationVerificationRetrySuccess(),
"NewErrorValidationVerificationStateFailure": text.NewErrorValidationVerificationStateFailure(),
Expand Down Expand Up @@ -122,7 +123,7 @@ func init() {
"NewErrorValidationRecoveryStateFailure": text.NewErrorValidationRecoveryStateFailure(),
"NewInfoNodeInputEmail": text.NewInfoNodeInputEmail(),
"NewInfoNodeResendOTP": text.NewInfoNodeResendOTP(),
"NewInfoNodeLabelReturn": text.NewInfoNodeLabelReturn(),
"NewInfoNodeLabelContinue": text.NewInfoNodeLabelContinue(),
"NewInfoSelfServiceSettingsRegisterWebAuthn": text.NewInfoSelfServiceSettingsRegisterWebAuthn(),
"NewInfoLoginWebAuthnPasswordless": text.NewInfoLoginWebAuthnPasswordless(),
"NewInfoSelfServiceRegistrationRegisterWebAuthn": text.NewInfoSelfServiceRegistrationRegisterWebAuthn(),
Expand Down
8 changes: 4 additions & 4 deletions selfservice/strategy/code/strategy_verification.go
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ func (s *Strategy) verificationHandleFormSubmission(w http.ResponseWriter, r *ht
f.State = verification.StateEmailSent

f.UI = s.createVerificationCodeForm(flow.AppendFlowTo(urlx.AppendPaths(s.deps.Config().SelfPublicURL(r.Context()), verification.RouteSubmitFlow), f.ID).String(), nil, &body.Email)
f.UI.Messages.Set(text.NewVerificationEmailSent())
f.UI.Messages.Set(text.NewVerificationEmailWithCodeSent())
f.UI.SetCSRF(s.deps.GenerateCSRFToken(r))

if err := s.deps.VerificationFlowPersister().UpdateVerificationFlow(r.Context(), f); err != nil {
Expand Down Expand Up @@ -290,8 +290,8 @@ func (s *Strategy) verificationUseCode(w http.ResponseWriter, r *http.Request, c
f.UI.Messages.Set(text.NewInfoSelfServiceVerificationSuccessful())
f.UI.
Nodes.
Append(node.NewAnchorField("go-back", returnTo.String(), node.CodeGroup, text.NewInfoNodeLabelReturn()).
WithMetaLabel(text.NewInfoNodeLabelReturn()))
Append(node.NewAnchorField("continue", returnTo.String(), node.CodeGroup, text.NewInfoNodeLabelContinue()).
WithMetaLabel(text.NewInfoNodeLabelContinue()))

if err := s.deps.VerificationFlowPersister().UpdateVerificationFlow(r.Context(), f); err != nil {
return s.retryVerificationFlowWithError(w, r, flow.TypeBrowser, err)
Expand All @@ -301,7 +301,7 @@ func (s *Strategy) verificationUseCode(w http.ResponseWriter, r *http.Request, c
}

func (s *Strategy) getRedirectURL(ctx context.Context, f *verification.Flow) *url.URL {
defaultRedirectURL := s.deps.Config().SelfServiceFlowVerificationReturnTo(ctx, f.AppendTo(s.deps.Config().SelfServiceFlowVerificationUI(ctx)))
defaultRedirectURL := s.deps.Config().SelfServiceBrowserDefaultReturnTo(ctx)

verificationRequestURL, err := urlx.Parse(f.GetRequestURL())
if err != nil {
Expand Down
6 changes: 3 additions & 3 deletions selfservice/strategy/code/strategy_verification_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ func TestVerification(t *testing.T) {
var check = func(t *testing.T, actual string) {
assert.EqualValues(t, string(node.CodeGroup), gjson.Get(actual, "active").String(), "%s", actual)
assert.EqualValues(t, email, gjson.Get(actual, "ui.nodes.#(attributes.name==email).attributes.value").String(), "%s", actual)
assertx.EqualAsJSON(t, text.NewVerificationEmailSent(), json.RawMessage(gjson.Get(actual, "ui.messages.0").Raw))
assertx.EqualAsJSON(t, text.NewVerificationEmailWithCodeSent(), json.RawMessage(gjson.Get(actual, "ui.messages.0").Raw))

message := testhelpers.CourierExpectMessage(t, reg, email, "Someone tried to verify this email address")
assert.Contains(t, message.Body, "If this was you, check if you signed up using a different address.")
Expand Down Expand Up @@ -292,7 +292,7 @@ func TestVerification(t *testing.T) {
var check = func(t *testing.T, actual string) {
assert.EqualValues(t, string(node.CodeGroup), gjson.Get(actual, "active").String(), "%s", actual)
assert.EqualValues(t, verificationEmail, gjson.Get(actual, "ui.nodes.#(attributes.name==email).attributes.value").String(), "%s", actual)
assertx.EqualAsJSON(t, text.NewVerificationEmailSent(), json.RawMessage(gjson.Get(actual, "ui.messages.0").Raw))
assertx.EqualAsJSON(t, text.NewVerificationEmailWithCodeSent(), json.RawMessage(gjson.Get(actual, "ui.messages.0").Raw))

message := testhelpers.CourierExpectMessage(t, reg, verificationEmail, "Please verify your email address")
assert.Contains(t, message.Body, "please verify your account by entering the following code")
Expand Down Expand Up @@ -405,7 +405,7 @@ func TestVerification(t *testing.T) {
require.NoError(t, err)
body := ioutilx.MustReadAll(res.Body)

assert.Equal(t, returnToURL, gjson.GetBytes(body, "ui.nodes.#(attributes.id==go-back).attributes.href").String())
assert.Equal(t, returnToURL, gjson.GetBytes(body, "ui.nodes.#(attributes.id==continue).attributes.href").String())
})

t.Run("case=should respond with replaced error if successful code is submitted again via api", func(t *testing.T) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,7 @@ context("Account Verification Registration Errors", () => {
cy.get(appPrefix(app) + 'input[name="email"]').should("be.empty")
cy.get('input[name="email"]').type(identity.email)
cy.get('button[value="code"]').click()
cy.get('[data-testid="ui/message/1080001"]').should(
"contain.text",
"An email containing a verification",
)
cy.contains("An email containing a verification")
cy.verifyEmail({
expect: { email: identity.email, password: identity.password },
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,10 +109,7 @@ context("Account Verification Error", () => {
cy.get('input[name="email"]').type(identity.email)
cy.get(`button[value="${s}"]`).click()

cy.get('[data-testid="ui/message/1080001"]').should(
"contain.text",
"An email containing a verification",
)
cy.contains("An email containing a verification")
cy.get(`[name="method"][value="${s}"]`).should("exist")
cy.verifyEmailButExpired({
expect: { email: identity.email },
Expand All @@ -124,10 +121,7 @@ context("Account Verification Error", () => {
cy.get('input[name="email"]').type(identity.email)
cy.get(`button[value="${s}"]`).click()

cy.get('[data-testid="ui/message/1080001"]').should(
"contain.text",
"An email containing a verification",
)
cy.contains("An email containing a verification")

cy.getMail().then((mail) => {
const link = parseHtml(mail.body).querySelector("a")
Expand Down Expand Up @@ -160,10 +154,7 @@ context("Account Verification Error", () => {
cy.get('input[name="email"]').type(identity.email)
cy.get(`button[value="${s}"]`).click()

cy.get('[data-testid="ui/message/1080001"]').should(
"contain.text",
"An email containing a verification",
)
cy.contains("An email containing a verification")

for (let i = 0; i < 5; i++) {
cy.get("input[name='code']").type((i + "").repeat(8)) // Invalid code
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,7 @@ context("Account Verification Settings Success", () => {
cy.get('input[name="email"]').type(identity.email)
cy.get(`button[value="${s}"]`).click()

cy.get('[data-testid="ui/message/1080001"]').should(
"contain.text",
"An email containing a verification",
)
cy.contains("An email containing a verification")

cy.get(`[name="method"][value="${s}"]`).should("exist")

Expand All @@ -59,10 +56,7 @@ context("Account Verification Settings Success", () => {
cy.get('input[name="email"]').type(email)
cy.get(`button[value="${s}"]`).click()

cy.get('[data-testid="ui/message/1080001"]').should(
"contain.text",
"An email containing a verification",
)
cy.contains("An email containing a verification")

cy.getMail().should((message) => {
expect(message.subject.trim()).to.equal(
Expand Down
4 changes: 2 additions & 2 deletions test/e2e/cypress/support/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1041,8 +1041,8 @@ Cypress.Commands.add(
cy.get(`button[name="method"][value="code"]`).click()

if (redirectTo) {
cy.get(`[data-testid="node/anchor/go-back"`)
.contains("Return")
cy.get(`[data-testid="node/anchor/continue"`)
.contains("Continue")
.click()
cy.url().should("be.equal", redirectTo)
}
Expand Down
9 changes: 5 additions & 4 deletions text/id.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,13 +80,14 @@ const (
InfoNodeLabelVerifyOTP // 1070006
InfoNodeLabelEmail // 1070007
InfoNodeLabelResendOTP // 1070008
InfoNodeLabelReturn // 1070009
InfoNodeLabelContinue // 1070009
)

const (
InfoSelfServiceVerification ID = 1080000 + iota // 1080000
InfoSelfServiceVerificationEmailSent // 1080001
InfoSelfServiceVerificationSuccessful // 1080002
InfoSelfServiceVerification ID = 1080000 + iota // 1080000
InfoSelfServiceVerificationEmailSent // 1080001
InfoSelfServiceVerificationSuccessful // 1080002
InfoSelfServiceVerificationEmailWithCodeSent // 1080003
)

const (
Expand Down
7 changes: 6 additions & 1 deletion text/id_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func TestIDs(t *testing.T) {
assert.Equal(t, 1070006, int(InfoNodeLabelVerifyOTP))
assert.Equal(t, 1070007, int(InfoNodeLabelEmail))
assert.Equal(t, 1070008, int(InfoNodeLabelResendOTP))
assert.Equal(t, 1070009, int(InfoNodeLabelReturn))
assert.Equal(t, 1070009, int(InfoNodeLabelContinue))

assert.Equal(t, 1080000, int(InfoSelfServiceVerification))

Expand Down Expand Up @@ -64,4 +64,9 @@ func TestIDs(t *testing.T) {

assert.Equal(t, 4060006, int(ErrorValidationRecoveryCodeInvalidOrAlreadyUsed))
assert.Equal(t, 4070006, int(ErrorValidationVerificationCodeInvalidOrAlreadyUsed))

assert.Equal(t, 1080000, int(InfoSelfServiceVerification))
assert.Equal(t, 1080001, int(InfoSelfServiceVerificationEmailSent))
assert.Equal(t, 1080002, int(InfoSelfServiceVerificationSuccessful))
assert.Equal(t, 1080003, int(InfoSelfServiceVerificationEmailWithCodeSent))
}
6 changes: 3 additions & 3 deletions text/message_node.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,10 @@ func NewInfoNodeLabelSubmit() *Message {
}
}

func NewInfoNodeLabelReturn() *Message {
func NewInfoNodeLabelContinue() *Message {
return &Message{
ID: InfoNodeLabelReturn,
Text: "Return",
ID: InfoNodeLabelContinue,
Text: "Continue",
Type: Info,
}
}
Expand Down
9 changes: 9 additions & 0 deletions text/message_verification.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,3 +71,12 @@ func NewErrorValidationVerificationCodeInvalidOrAlreadyUsed() *Message {
Context: context(nil),
}
}

func NewVerificationEmailWithCodeSent() *Message {
return &Message{
ID: InfoSelfServiceVerificationEmailWithCodeSent,
Type: Info,
Text: "An email containing a verification code has been sent to the email address you provided.",
Context: context(nil),
}
}

0 comments on commit e1119e8

Please sign in to comment.