forked from umputun/remark42
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add subscription link support to notification email verification temp…
…late (umputun#573) * add subscription link support to notification email verification template * always show token for email subscription in verification email * hide SubscribeURL from users
- Loading branch information
Showing
3 changed files
with
63 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -189,7 +189,8 @@ func TestEmail_Send(t *testing.T) { | |
req := Request{ | ||
Comment: store.Comment{ID: "999", User: store.User{ID: "1", Name: "test_user"}, PostTitle: "test_title"}, | ||
parent: store.Comment{ID: "1", User: store.User{ID: "999", Name: "parent_user"}}, | ||
Email: "[email protected]"} | ||
Email: "[email protected]", | ||
} | ||
assert.NoError(t, email.Send(context.TODO(), req)) | ||
assert.Equal(t, "[email protected]", fakeSmtp.readMail()) | ||
assert.Equal(t, 1, fakeSmtp.readQuitCount()) | ||
|
@@ -208,6 +209,50 @@ List-Unsubscribe: <https://remark42.com/api/v1/email/unsubscribe?site=&tkn=token | |
Date: `) | ||
} | ||
|
||
func TestEmail_SendVerification(t *testing.T) { | ||
email, err := NewEmail(EmailParams{From: "[email protected]"}, SmtpParams{}) | ||
assert.NoError(t, err) | ||
assert.NotNil(t, email) | ||
fakeSmtp := fakeTestSMTP{} | ||
email.smtp = &fakeSmtp | ||
email.TokenGenFn = TokenGenFn | ||
req := Request{ | ||
Email: "[email protected]", | ||
Verification: VerificationMetadata{ | ||
SiteID: "remark", | ||
User: "test_username", | ||
Token: "secret_", | ||
}, | ||
} | ||
assert.NoError(t, email.Send(context.TODO(), req)) | ||
assert.Equal(t, "[email protected]", fakeSmtp.readMail()) | ||
assert.Equal(t, 1, fakeSmtp.readQuitCount()) | ||
assert.Equal(t, "[email protected]", fakeSmtp.readRcpt()) | ||
// test buildMessageFromRequest separately for message text | ||
res, err := email.buildVerificationMessage(req.Verification.User, req.Email, req.Verification.Token, req.Verification.SiteID) | ||
assert.NoError(t, err) | ||
assert.Contains(t, res, `From: [email protected] | ||
To: [email protected] | ||
Subject: Email verification | ||
Content-Transfer-Encoding: quoted-printable | ||
MIME-version: 1.0 | ||
Content-Type: text/html; charset="UTF-8" | ||
Date: `) | ||
assert.Contains(t, res, `secret_`) | ||
assert.NotContains(t, res, `https://example.org/`) | ||
email.SubscribeURL = "https://example.org/subscribe.html?token=" | ||
res, err = email.buildVerificationMessage(req.Verification.User, req.Email, req.Verification.Token, req.Verification.SiteID) | ||
assert.NoError(t, err) | ||
assert.Contains(t, res, `From: [email protected] | ||
To: [email protected] | ||
Subject: Email verification | ||
Content-Transfer-Encoding: quoted-printable | ||
MIME-version: 1.0 | ||
Content-Type: text/html; charset="UTF-8" | ||
Date: `) | ||
assert.Contains(t, res, `https://example.org/subscribe.html?token=3Dsecret_`) | ||
} | ||
|
||
func Test_emailClient_Create(t *testing.T) { | ||
creator := emailClient{} | ||
client, err := creator.Create(SmtpParams{}) | ||
|