Skip to content

Commit

Permalink
feat: extend recovery flow by adding the FlowID
Browse files Browse the repository at this point in the history
  • Loading branch information
matthiastz committed Dec 1, 2023
1 parent 7c0e02e commit f7c4575
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 0 deletions.
1 change: 1 addition & 0 deletions courier/template/email/recovery_code_valid.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ type (
}
RecoveryCodeValidModel struct {
To string
FlowID string
RecoveryCode string
Identity map[string]interface{}
}
Expand Down
1 change: 1 addition & 0 deletions selfservice/strategy/code/code_sender.go
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,7 @@ func (s *Sender) SendRecoveryCodeTo(ctx context.Context, i *identity.Identity, c

emailModel := email.RecoveryCodeValidModel{
To: code.RecoveryAddress.Value,
FlowID: code.FlowID.String(),
RecoveryCode: codeString,
Identity: model,
}
Expand Down
12 changes: 12 additions & 0 deletions selfservice/strategy/code/code_sender_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@ package code_test
import (
"context"
"encoding/base64"
"encoding/json"
"fmt"
"net/http"
"testing"
"time"

"github.com/ory/kratos/courier"
"github.com/ory/kratos/courier/template/email"
"github.com/ory/kratos/internal/testhelpers"

"github.com/stretchr/testify/assert"
Expand Down Expand Up @@ -65,6 +67,16 @@ func TestSender(t *testing.T) {
require.NoError(t, err)
require.Len(t, messages, 2)

// verify correct templateData
var templateData = string(messages[0].TemplateData[:])
var data = email.RecoveryCodeValidModel{}
err = json.Unmarshal([]byte(templateData), &data)
require.NoError(t, err)
require.NotEmpty(t, data.To)
require.NotEmpty(t, data.FlowID)
require.NotEmpty(t, data.RecoveryCode)
require.NotEmpty(t, data.Identity)

assert.EqualValues(t, "[email protected]", messages[0].Recipient)
assert.Contains(t, messages[0].Subject, "Recover access to your account")

Expand Down

0 comments on commit f7c4575

Please sign in to comment.