summaryrefslogtreecommitdiff
path: root/internal/email/email_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'internal/email/email_test.go')
-rw-r--r--internal/email/email_test.go152
1 files changed, 152 insertions, 0 deletions
diff --git a/internal/email/email_test.go b/internal/email/email_test.go
index 2fa52ec4a..91d128ef8 100644
--- a/internal/email/email_test.go
+++ b/internal/email/email_test.go
@@ -18,7 +18,10 @@
package email_test
import (
+ "testing"
+
"github.com/stretchr/testify/suite"
+ "github.com/superseriousbusiness/gotosocial/internal/config"
"github.com/superseriousbusiness/gotosocial/internal/email"
"github.com/superseriousbusiness/gotosocial/testrig"
)
@@ -36,3 +39,152 @@ func (suite *EmailTestSuite) SetupTest() {
suite.sentEmails = make(map[string]string)
suite.sender = testrig.NewEmailSender("../../web/template/", suite.sentEmails)
}
+
+func (suite *EmailTestSuite) TestTemplateConfirm() {
+ confirmData := email.ConfirmData{
+ Username: "test",
+ InstanceURL: "https://example.org",
+ InstanceName: "Test Instance",
+ ConfirmLink: "https://example.org/confirm_email?token=ee24f71d-e615-43f9-afae-385c0799b7fa",
+ }
+
+ suite.sender.SendConfirmEmail("user@example.org", confirmData)
+ suite.Len(suite.sentEmails, 1)
+ suite.Equal("To: user@example.org\r\nSubject: GoToSocial Email Confirmation\r\n\r\nHello test!\r\n\r\nYou are receiving this mail because you've requested an account on https://example.org.\r\n\r\nWe just need to confirm that this is your email address. To confirm your email, paste the following in your browser's address bar:\r\n\r\nhttps://example.org/confirm_email?token=ee24f71d-e615-43f9-afae-385c0799b7fa\r\n\r\nIf you believe you've been sent this email in error, feel free to ignore it, or contact the administrator of https://example.org\r\n\r\n", suite.sentEmails["user@example.org"])
+}
+
+func (suite *EmailTestSuite) TestTemplateReset() {
+ resetData := email.ResetData{
+ Username: "test",
+ InstanceURL: "https://example.org",
+ InstanceName: "Test Instance",
+ ResetLink: "https://example.org/reset_email?token=ee24f71d-e615-43f9-afae-385c0799b7fa",
+ }
+
+ suite.sender.SendResetEmail("user@example.org", resetData)
+ suite.Len(suite.sentEmails, 1)
+ suite.Equal("To: user@example.org\r\nSubject: GoToSocial Password Reset\r\n\r\nHello test!\r\n\r\nYou are receiving this mail because a password reset has been requested for your account on https://example.org.\r\n\r\nTo reset your password, paste the following in your browser's address bar:\r\n\r\nhttps://example.org/reset_email?token=ee24f71d-e615-43f9-afae-385c0799b7fa\r\n\r\nIf you believe you've been sent this email in error, feel free to ignore it, or contact the administrator of https://example.org.\r\n\r\n", suite.sentEmails["user@example.org"])
+}
+
+func (suite *EmailTestSuite) TestTemplateReportRemoteToLocal() {
+ // Someone from a remote instance has reported one of our users.
+ reportData := email.NewReportData{
+ InstanceURL: "https://example.org",
+ InstanceName: "Test Instance",
+ ReportURL: "https://example.org/settings/admin/reports/01GVJHN1RTYZCZTCXVPPPKBX6R",
+ ReportDomain: "fossbros-anonymous.io",
+ ReportTargetDomain: "",
+ }
+
+ if err := suite.sender.SendNewReportEmail([]string{"user@example.org"}, reportData); err != nil {
+ suite.FailNow(err.Error())
+ }
+ suite.Len(suite.sentEmails, 1)
+ suite.Equal("To: user@example.org\r\nSubject: GoToSocial New Report\r\n\r\nHello moderator of Test Instance (https://example.org)!\r\n\r\nSomeone from fossbros-anonymous.io has reported a user from your instance.\r\n\r\nTo view the report, paste the following link into your browser: https://example.org/settings/admin/reports/01GVJHN1RTYZCZTCXVPPPKBX6R\r\n\r\n", suite.sentEmails["user@example.org"])
+}
+
+func (suite *EmailTestSuite) TestTemplateReportLocalToRemote() {
+ // Someone from our instance has reported a remote user.
+ reportData := email.NewReportData{
+ InstanceURL: "https://example.org",
+ InstanceName: "Test Instance",
+ ReportURL: "https://example.org/settings/admin/reports/01GVJHN1RTYZCZTCXVPPPKBX6R",
+ ReportDomain: "",
+ ReportTargetDomain: "fossbros-anonymous.io",
+ }
+
+ if err := suite.sender.SendNewReportEmail([]string{"user@example.org"}, reportData); err != nil {
+ suite.FailNow(err.Error())
+ }
+ suite.Len(suite.sentEmails, 1)
+ suite.Equal("To: user@example.org\r\nSubject: GoToSocial New Report\r\n\r\nHello moderator of Test Instance (https://example.org)!\r\n\r\nSomeone from your instance has reported a user from fossbros-anonymous.io.\r\n\r\nTo view the report, paste the following link into your browser: https://example.org/settings/admin/reports/01GVJHN1RTYZCZTCXVPPPKBX6R\r\n\r\n", suite.sentEmails["user@example.org"])
+}
+
+func (suite *EmailTestSuite) TestTemplateReportLocalToLocal() {
+ // Someone from our instance has reported another user on our instance.
+ reportData := email.NewReportData{
+ InstanceURL: "https://example.org",
+ InstanceName: "Test Instance",
+ ReportURL: "https://example.org/settings/admin/reports/01GVJHN1RTYZCZTCXVPPPKBX6R",
+ ReportDomain: "",
+ ReportTargetDomain: "",
+ }
+
+ if err := suite.sender.SendNewReportEmail([]string{"user@example.org"}, reportData); err != nil {
+ suite.FailNow(err.Error())
+ }
+ suite.Len(suite.sentEmails, 1)
+ suite.Equal("To: user@example.org\r\nSubject: GoToSocial New Report\r\n\r\nHello moderator of Test Instance (https://example.org)!\r\n\r\nSomeone from your instance has reported another user from your instance.\r\n\r\nTo view the report, paste the following link into your browser: https://example.org/settings/admin/reports/01GVJHN1RTYZCZTCXVPPPKBX6R\r\n\r\n", suite.sentEmails["user@example.org"])
+}
+
+func (suite *EmailTestSuite) TestTemplateReportMoreThanOneModeratorAddress() {
+ reportData := email.NewReportData{
+ InstanceURL: "https://example.org",
+ InstanceName: "Test Instance",
+ ReportURL: "https://example.org/settings/admin/reports/01GVJHN1RTYZCZTCXVPPPKBX6R",
+ ReportDomain: "fossbros-anonymous.io",
+ ReportTargetDomain: "",
+ }
+
+ // Send the email to multiple addresses
+ if err := suite.sender.SendNewReportEmail([]string{"user@example.org", "admin@example.org"}, reportData); err != nil {
+ suite.FailNow(err.Error())
+ }
+ suite.Len(suite.sentEmails, 1)
+ suite.Equal("To: Undisclosed Recipients:;\r\nSubject: GoToSocial New Report\r\n\r\nHello moderator of Test Instance (https://example.org)!\r\n\r\nSomeone from fossbros-anonymous.io has reported a user from your instance.\r\n\r\nTo view the report, paste the following link into your browser: https://example.org/settings/admin/reports/01GVJHN1RTYZCZTCXVPPPKBX6R\r\n\r\n", suite.sentEmails["user@example.org"])
+}
+
+func (suite *EmailTestSuite) TestTemplateReportMoreThanOneModeratorAddressDisclose() {
+ config.SetSMTPDiscloseRecipients(true)
+
+ reportData := email.NewReportData{
+ InstanceURL: "https://example.org",
+ InstanceName: "Test Instance",
+ ReportURL: "https://example.org/settings/admin/reports/01GVJHN1RTYZCZTCXVPPPKBX6R",
+ ReportDomain: "fossbros-anonymous.io",
+ ReportTargetDomain: "",
+ }
+
+ // Send the email to multiple addresses
+ if err := suite.sender.SendNewReportEmail([]string{"user@example.org", "admin@example.org"}, reportData); err != nil {
+ suite.FailNow(err.Error())
+ }
+ suite.Len(suite.sentEmails, 1)
+ suite.Equal("To: user@example.org, admin@example.org\r\nSubject: GoToSocial New Report\r\n\r\nHello moderator of Test Instance (https://example.org)!\r\n\r\nSomeone from fossbros-anonymous.io has reported a user from your instance.\r\n\r\nTo view the report, paste the following link into your browser: https://example.org/settings/admin/reports/01GVJHN1RTYZCZTCXVPPPKBX6R\r\n\r\n", suite.sentEmails["user@example.org"])
+}
+
+func (suite *EmailTestSuite) TestTemplateReportClosedOK() {
+ reportClosedData := email.ReportClosedData{
+ InstanceURL: "https://example.org",
+ InstanceName: "Test Instance",
+ ReportTargetUsername: "foss_satan",
+ ReportTargetDomain: "fossbros-anonymous.io",
+ ActionTakenComment: "User was yeeted. Thank you for reporting!",
+ }
+
+ if err := suite.sender.SendReportClosedEmail("user@example.org", reportClosedData); err != nil {
+ suite.FailNow(err.Error())
+ }
+ suite.Len(suite.sentEmails, 1)
+ suite.Equal("To: user@example.org\r\nSubject: GoToSocial Report Closed\r\n\r\nHello !\r\n\r\nYou recently reported the account @foss_satan@fossbros-anonymous.io to the moderator(s) of Test Instance (https://example.org).\r\n\r\nThe report you submitted has now been closed.\r\n\r\nThe moderator who closed the report left the following comment: User was yeeted. Thank you for reporting!\r\n\r\n", suite.sentEmails["user@example.org"])
+}
+
+func (suite *EmailTestSuite) TestTemplateReportClosedLocalAccountNoComment() {
+ reportClosedData := email.ReportClosedData{
+ InstanceURL: "https://example.org",
+ InstanceName: "Test Instance",
+ ReportTargetUsername: "1happyturtle",
+ ReportTargetDomain: "",
+ ActionTakenComment: "",
+ }
+
+ if err := suite.sender.SendReportClosedEmail("user@example.org", reportClosedData); err != nil {
+ suite.FailNow(err.Error())
+ }
+ suite.Len(suite.sentEmails, 1)
+ suite.Equal("To: user@example.org\r\nSubject: GoToSocial Report Closed\r\n\r\nHello !\r\n\r\nYou recently reported the account @1happyturtle to the moderator(s) of Test Instance (https://example.org).\r\n\r\nThe report you submitted has now been closed.\r\n\r\nThe moderator who closed the report did not leave a comment.\r\n\r\n", suite.sentEmails["user@example.org"])
+}
+
+func TestEmailTestSuite(t *testing.T) {
+ suite.Run(t, new(EmailTestSuite))
+}