Skip to content

Commit 5ac7553

Browse files
authored
fix: missing usage to recovery_code_invalid template (#2798)
1 parent 84ea0cf commit 5ac7553

File tree

6 files changed

+72
-12
lines changed

6 files changed

+72
-12
lines changed

courier/email_templates.go

+12
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,18 @@ func NewEmailTemplateFromMessage(d template.Dependencies, msg Message) (EmailTem
6969
return nil, err
7070
}
7171
return email.NewRecoveryValid(d, &t), nil
72+
case TypeRecoveryCodeInvalid:
73+
var t email.RecoveryCodeInvalidModel
74+
if err := json.Unmarshal(msg.TemplateData, &t); err != nil {
75+
return nil, err
76+
}
77+
return email.NewRecoveryCodeInvalid(d, &t), nil
78+
case TypeRecoveryCodeValid:
79+
var t email.RecoveryCodeValidModel
80+
if err := json.Unmarshal(msg.TemplateData, &t); err != nil {
81+
return nil, err
82+
}
83+
return email.NewRecoveryCodeValid(d, &t), nil
7284
case TypeVerificationInvalid:
7385
var t email.VerificationInvalidModel
7486
if err := json.Unmarshal(msg.TemplateData, &t); err != nil {

courier/email_templates_test.go

+2
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ func TestNewEmailTemplateFromMessage(t *testing.T) {
3636
for tmplType, expectedTmpl := range map[courier.TemplateType]courier.EmailTemplate{
3737
courier.TypeRecoveryInvalid: email.NewRecoveryInvalid(reg, &email.RecoveryInvalidModel{To: "foo"}),
3838
courier.TypeRecoveryValid: email.NewRecoveryValid(reg, &email.RecoveryValidModel{To: "bar", RecoveryURL: "http://foo.bar"}),
39+
courier.TypeRecoveryCodeValid: email.NewRecoveryCodeValid(reg, &email.RecoveryCodeValidModel{To: "bar", RecoveryCode: "12345678"}),
40+
courier.TypeRecoveryCodeInvalid: email.NewRecoveryCodeInvalid(reg, &email.RecoveryCodeInvalidModel{To: "bar"}),
3941
courier.TypeVerificationInvalid: email.NewVerificationInvalid(reg, &email.VerificationInvalidModel{To: "baz"}),
4042
courier.TypeVerificationValid: email.NewVerificationValid(reg, &email.VerificationValidModel{To: "faz", VerificationURL: "http://bar.foo"}),
4143
courier.TypeTestStub: email.NewTestStub(reg, &email.TestStubModel{To: "far", Subject: "test subject", Body: "test body"}),

selfservice/strategy/code/sender.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ func (s *RecoveryCodeSender) SendRecoveryCode(ctx context.Context, r *http.Reque
6060

6161
address, err := s.deps.IdentityPool().FindRecoveryAddressByValue(ctx, identity.RecoveryAddressTypeEmail, to)
6262
if err != nil {
63-
if err := s.send(ctx, string(via), email.NewRecoveryInvalid(s.deps, &email.RecoveryInvalidModel{To: to})); err != nil {
63+
if err := s.send(ctx, string(via), email.NewRecoveryCodeInvalid(s.deps, &email.RecoveryCodeInvalidModel{To: to})); err != nil {
6464
return err
6565
}
6666
return ErrUnknownAddress

test/e2e/cypress/integration/profiles/recovery/code/errors.spec.ts

+18-5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { extractRecoveryCode, appPrefix, gen } from "../../../../helpers"
1+
import { extractRecoveryCode, appPrefix, gen, email } from "../../../../helpers"
22
import { routes as react } from "../../../../helpers/react"
33
import { routes as express } from "../../../../helpers/express"
44

@@ -162,7 +162,7 @@ context("Account Recovery Errors", () => {
162162
cy.get('[name="method"][value="code"]').should("exist")
163163
})
164164

165-
it("invalid remote recovery email template", () => {
165+
it("remote recovery email template (recovery_code_valid)", () => {
166166
cy.remoteCourierRecoveryCodeTemplates()
167167
const identity = gen.identityWithWebsite()
168168
cy.registerApi(identity)
@@ -175,9 +175,22 @@ context("Account Recovery Errors", () => {
175175
)
176176

177177
cy.getMail().then((mail) => {
178-
expect(mail.body).to.include(
179-
"this is a remote invalid recovery template",
180-
)
178+
expect(mail.body).to.include("recovery_code_valid REMOTE TEMPLATE")
179+
})
180+
})
181+
182+
it("remote recovery email template (recovery_code_invalid)", () => {
183+
cy.remoteCourierRecoveryCodeTemplates()
184+
cy.visit(recovery)
185+
cy.get(appPrefix(app) + "input[name='email']").type(email())
186+
cy.get("button[value='code']").click()
187+
cy.get('[data-testid="ui/message/1060003"]').should(
188+
"have.text",
189+
"An email containing a recovery code has been sent to the email address you provided.",
190+
)
191+
192+
cy.getMail().then((mail) => {
193+
expect(mail.body).to.include("recovery_code_invalid REMOTE TEMPLATE")
181194
})
182195
})
183196
})

test/e2e/cypress/support/commands.ts

+32-6
Original file line numberDiff line numberDiff line change
@@ -682,21 +682,47 @@ Cypress.Commands.add("remoteCourierRecoveryCodeTemplates", ({} = {}) => {
682682
invalid: {
683683
email: {
684684
body: {
685-
html: "base64://SGksCgp0aGlzIGlzIGEgcmVtb3RlIGludmFsaWQgcmVjb3ZlcnkgdGVtcGxhdGU=",
685+
html: "base64://cmVjb3ZlcnlfY29kZV9pbnZhbGlkIFJFTU9URSBURU1QTEFURSBIVE1M", // only
686686
plaintext:
687-
"base64://SGksCgp0aGlzIGlzIGEgcmVtb3RlIGludmFsaWQgcmVjb3ZlcnkgdGVtcGxhdGU=",
687+
"base64://cmVjb3ZlcnlfY29kZV9pbnZhbGlkIFJFTU9URSBURU1QTEFURSBUWFQ=",
688688
},
689-
subject: "base64://QWNjb3VudCBBY2Nlc3MgQXR0ZW1wdGVk",
689+
subject:
690+
"base64://cmVjb3ZlcnlfY29kZV9pbnZhbGlkIFJFTU9URSBURU1QTEFURSBTVUJKRUNU",
690691
},
691692
},
692693
valid: {
693694
email: {
694695
body: {
695-
html: "base64://SGksCgp0aGlzIGlzIGEgcmVtb3RlIGludmFsaWQgcmVjb3ZlcnkgdGVtcGxhdGUKcGxlYXNlIHJlY292ZXIgYWNjZXNzIHRvIHlvdXIgYWNjb3VudCBieSBlbnRlcmluZyB0aGUgZm9sbG93aW5nIGNvZGU6Cgp7eyAuUmVjb3ZlcnlDb2RlIH19Cg==",
696+
html: "base://cmVjb3ZlcnlfY29kZV92YWxpZCBSRU1PVEUgVEVNUExBVEUgSFRNTA==",
696697
plaintext:
697-
"base64://SGksCgp0aGlzIGlzIGEgcmVtb3RlIGludmFsaWQgcmVjb3ZlcnkgdGVtcGxhdGUKcGxlYXNlIHJlY292ZXIgYWNjZXNzIHRvIHlvdXIgYWNjb3VudCBieSBlbnRlcmluZyB0aGUgZm9sbG93aW5nIGNvZGU6Cgp7eyAuUmVjb3ZlcnlDb2RlIH19Cg==",
698+
"base64://cmVjb3ZlcnlfY29kZV92YWxpZCBSRU1PVEUgVEVNUExBVEUgVFhU",
699+
},
700+
subject:
701+
"base64://cmVjb3ZlcnlfY29kZV92YWxpZCBSRU1PVEUgVEVNUExBVEUgU1VCSkVDVA==",
702+
},
703+
},
704+
},
705+
}
706+
return config
707+
})
708+
})
709+
710+
Cypress.Commands.add("resetCourierTemplates", (type) => {
711+
updateConfigFile((config) => {
712+
config.courier.templates = {
713+
[type]: {
714+
invalid: {
715+
email: {
716+
body: {},
717+
subject: "",
718+
},
719+
},
720+
valid: {
721+
email: {
722+
body: {
723+
body: {},
724+
subject: "",
698725
},
699-
subject: "base64://UmVjb3ZlciBhY2Nlc3MgdG8geW91ciBhY2NvdW50",
700726
},
701727
},
702728
},

test/e2e/cypress/support/index.d.ts

+7
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,13 @@ declare global {
183183
*/
184184
remoteCourierRecoveryTemplates(): Chainable<void>
185185

186+
/**
187+
* Resets the remote courier templates for the given template type to their default values
188+
*/
189+
resetCourierTemplates(
190+
type: "recovery_code" | "recovery" | "verification",
191+
): Chainable<void>
192+
186193
/**
187194
* Change the courier recovery code invalid and valid templates to remote base64 strings
188195
*/

0 commit comments

Comments
 (0)