use noop email sender in tests

This commit is contained in:
tsmethurst 2021-10-17 16:59:57 +02:00
commit 8fdb3256e5
23 changed files with 110 additions and 88 deletions

View file

@ -31,6 +31,7 @@ type AccountStandardTestSuite struct {
federator federation.Federator
processor processing.Processor
emailSender email.Sender
sentEmails map[string]string
// standard suite models
testTokens map[string]*gtsmodel.Token
@ -61,7 +62,8 @@ func (suite *AccountStandardTestSuite) SetupTest() {
suite.storage = testrig.NewTestStorage()
testrig.InitTestLog()
suite.federator = testrig.NewTestFederator(suite.db, testrig.NewTestTransportController(testrig.NewMockHTTPClient(nil), suite.db), suite.storage)
suite.emailSender = testrig.NewEmailSender("../../../../web/template/")
suite.sentEmails = make(map[string]string)
suite.emailSender = testrig.NewEmailSender("../../../../web/template/", suite.sentEmails)
suite.processor = testrig.NewTestProcessor(suite.db, suite.storage, suite.federator, suite.emailSender)
suite.accountModule = account.New(suite.config, suite.processor).(*account.Module)
testrig.StandardDBSetup(suite.db, nil)

View file

@ -80,7 +80,7 @@ func (suite *ServeFileTestSuite) SetupSuite() {
testrig.InitTestLog()
suite.storage = testrig.NewTestStorage()
suite.federator = testrig.NewTestFederator(suite.db, testrig.NewTestTransportController(testrig.NewMockHTTPClient(nil), suite.db), suite.storage)
suite.emailSender = testrig.NewEmailSender("../../../../web/template/")
suite.emailSender = testrig.NewEmailSender("../../../../web/template/", nil)
suite.processor = testrig.NewTestProcessor(suite.db, suite.storage, suite.federator, suite.emailSender)
suite.tc = testrig.NewTestTypeConverter(suite.db)

View file

@ -75,7 +75,7 @@ func (suite *FollowRequestStandardTestSuite) SetupTest() {
suite.db = testrig.NewTestDB()
suite.storage = testrig.NewTestStorage()
suite.federator = testrig.NewTestFederator(suite.db, testrig.NewTestTransportController(testrig.NewMockHTTPClient(nil), suite.db), suite.storage)
suite.emailSender = testrig.NewEmailSender("../../../../web/template/")
suite.emailSender = testrig.NewEmailSender("../../../../web/template/", nil)
suite.processor = testrig.NewTestProcessor(suite.db, suite.storage, suite.federator, suite.emailSender)
suite.followRequestModule = followrequest.New(suite.config, suite.processor).(*followrequest.Module)
testrig.StandardDBSetup(suite.db, nil)

View file

@ -86,7 +86,7 @@ func (suite *MediaCreateTestSuite) SetupSuite() {
suite.mediaHandler = testrig.NewTestMediaHandler(suite.db, suite.storage)
suite.oauthServer = testrig.NewTestOauthServer(suite.db)
suite.federator = testrig.NewTestFederator(suite.db, testrig.NewTestTransportController(testrig.NewMockHTTPClient(nil), suite.db), suite.storage)
suite.emailSender = testrig.NewEmailSender("../../../../web/template/")
suite.emailSender = testrig.NewEmailSender("../../../../web/template/", nil)
suite.processor = testrig.NewTestProcessor(suite.db, suite.storage, suite.federator, suite.emailSender)
// setup module being tested

View file

@ -69,10 +69,11 @@ func (suite *StatusStandardTestSuite) SetupSuite() {
func (suite *StatusStandardTestSuite) SetupTest() {
suite.config = testrig.NewTestConfig()
suite.db = testrig.NewTestDB()
suite.tc = testrig.NewTestTypeConverter(suite.db)
suite.storage = testrig.NewTestStorage()
testrig.InitTestLog()
suite.federator = testrig.NewTestFederator(suite.db, testrig.NewTestTransportController(testrig.NewMockHTTPClient(nil), suite.db), suite.storage)
suite.emailSender = testrig.NewEmailSender("../../../../web/template/")
suite.emailSender = testrig.NewEmailSender("../../../../web/template/", nil)
suite.processor = testrig.NewTestProcessor(suite.db, suite.storage, suite.federator, suite.emailSender)
suite.statusModule = status.New(suite.config, suite.processor).(*status.Module)
testrig.StandardDBSetup(suite.db, nil)

View file

@ -48,6 +48,8 @@ type UserStandardTestSuite struct {
testUsers map[string]*gtsmodel.User
testAccounts map[string]*gtsmodel.Account
sentEmails map[string]string
userModule *user.Module
}
@ -63,7 +65,8 @@ func (suite *UserStandardTestSuite) SetupTest() {
testrig.InitTestLog()
suite.tc = testrig.NewTestTypeConverter(suite.db)
suite.federator = testrig.NewTestFederator(suite.db, testrig.NewTestTransportController(testrig.NewMockHTTPClient(nil), suite.db), suite.storage)
suite.emailSender = testrig.NewEmailSender("../../../../web/template/")
suite.sentEmails = make(map[string]string)
suite.emailSender = testrig.NewEmailSender("../../../../web/template/", suite.sentEmails)
suite.processor = testrig.NewTestProcessor(suite.db, suite.storage, suite.federator, suite.emailSender)
suite.userModule = user.New(suite.config, suite.processor).(*user.Module)
testrig.StandardDBSetup(suite.db, suite.testAccounts)

View file

@ -85,7 +85,7 @@ func (suite *InboxPostTestSuite) TestPostBlock() {
tc := testrig.NewTestTransportController(testrig.NewMockHTTPClient(nil), suite.db)
federator := testrig.NewTestFederator(suite.db, tc, suite.storage)
emailSender := testrig.NewEmailSender("../../../../web/template/")
emailSender := testrig.NewEmailSender("../../../../web/template/", nil)
processor := testrig.NewTestProcessor(suite.db, suite.storage, federator, emailSender)
userModule := user.New(suite.config, processor).(*user.Module)
@ -185,7 +185,7 @@ func (suite *InboxPostTestSuite) TestPostUnblock() {
tc := testrig.NewTestTransportController(testrig.NewMockHTTPClient(nil), suite.db)
federator := testrig.NewTestFederator(suite.db, tc, suite.storage)
emailSender := testrig.NewEmailSender("../../../../web/template/")
emailSender := testrig.NewEmailSender("../../../../web/template/", nil)
processor := testrig.NewTestProcessor(suite.db, suite.storage, federator, emailSender)
userModule := user.New(suite.config, processor).(*user.Module)
@ -275,7 +275,7 @@ func (suite *InboxPostTestSuite) TestPostUpdate() {
tc := testrig.NewTestTransportController(testrig.NewMockHTTPClient(nil), suite.db)
federator := testrig.NewTestFederator(suite.db, tc, suite.storage)
emailSender := testrig.NewEmailSender("../../../../web/template/")
emailSender := testrig.NewEmailSender("../../../../web/template/", nil)
processor := testrig.NewTestProcessor(suite.db, suite.storage, federator, emailSender)
userModule := user.New(suite.config, processor).(*user.Module)
@ -394,7 +394,7 @@ func (suite *InboxPostTestSuite) TestPostDelete() {
tc := testrig.NewTestTransportController(testrig.NewMockHTTPClient(nil), suite.db)
federator := testrig.NewTestFederator(suite.db, tc, suite.storage)
emailSender := testrig.NewEmailSender("../../../../web/template/")
emailSender := testrig.NewEmailSender("../../../../web/template/", nil)
processor := testrig.NewTestProcessor(suite.db, suite.storage, federator, emailSender)
err = processor.Start(context.Background())
suite.NoError(err)

View file

@ -49,7 +49,7 @@ func (suite *RepliesGetTestSuite) TestGetReplies() {
tc := testrig.NewTestTransportController(testrig.NewMockHTTPClient(nil), suite.db)
federator := testrig.NewTestFederator(suite.db, tc, suite.storage)
emailSender := testrig.NewEmailSender("../../../../web/template/")
emailSender := testrig.NewEmailSender("../../../../web/template/", nil)
processor := testrig.NewTestProcessor(suite.db, suite.storage, federator, emailSender)
userModule := user.New(suite.config, processor).(*user.Module)
@ -109,7 +109,7 @@ func (suite *RepliesGetTestSuite) TestGetRepliesNext() {
tc := testrig.NewTestTransportController(testrig.NewMockHTTPClient(nil), suite.db)
federator := testrig.NewTestFederator(suite.db, tc, suite.storage)
emailSender := testrig.NewEmailSender("../../../../web/template/")
emailSender := testrig.NewEmailSender("../../../../web/template/", nil)
processor := testrig.NewTestProcessor(suite.db, suite.storage, federator, emailSender)
userModule := user.New(suite.config, processor).(*user.Module)
@ -172,7 +172,7 @@ func (suite *RepliesGetTestSuite) TestGetRepliesLast() {
tc := testrig.NewTestTransportController(testrig.NewMockHTTPClient(nil), suite.db)
federator := testrig.NewTestFederator(suite.db, tc, suite.storage)
emailSender := testrig.NewEmailSender("../../../../web/template/")
emailSender := testrig.NewEmailSender("../../../../web/template/", nil)
processor := testrig.NewTestProcessor(suite.db, suite.storage, federator, emailSender)
userModule := user.New(suite.config, processor).(*user.Module)

View file

@ -77,7 +77,7 @@ func (suite *UserStandardTestSuite) SetupTest() {
suite.storage = testrig.NewTestStorage()
testrig.InitTestLog()
suite.federator = testrig.NewTestFederator(suite.db, testrig.NewTestTransportController(testrig.NewMockHTTPClient(nil), suite.db), suite.storage)
suite.emailSender = testrig.NewEmailSender("../../../../web/template/")
suite.emailSender = testrig.NewEmailSender("../../../../web/template/", nil)
suite.processor = testrig.NewTestProcessor(suite.db, suite.storage, suite.federator, suite.emailSender)
suite.userModule = user.New(suite.config, suite.processor).(*user.Module)
suite.securityModule = security.New(suite.config, suite.db).(*security.Module)

View file

@ -47,7 +47,7 @@ func (suite *UserGetTestSuite) TestGetUser() {
tc := testrig.NewTestTransportController(testrig.NewMockHTTPClient(nil), suite.db)
federator := testrig.NewTestFederator(suite.db, tc, suite.storage)
emailSender := testrig.NewEmailSender("../../../../web/template/")
emailSender := testrig.NewEmailSender("../../../../web/template/", nil)
processor := testrig.NewTestProcessor(suite.db, suite.storage, federator, emailSender)
userModule := user.New(suite.config, processor).(*user.Module)

View file

@ -80,7 +80,7 @@ func (suite *WebfingerStandardTestSuite) SetupTest() {
suite.storage = testrig.NewTestStorage()
testrig.InitTestLog()
suite.federator = testrig.NewTestFederator(suite.db, testrig.NewTestTransportController(testrig.NewMockHTTPClient(nil), suite.db), suite.storage)
suite.emailSender = testrig.NewEmailSender("../../../../web/template/")
suite.emailSender = testrig.NewEmailSender("../../../../web/template/", nil)
suite.processor = testrig.NewTestProcessor(suite.db, suite.storage, suite.federator, suite.emailSender)
suite.webfingerModule = webfinger.New(suite.config, suite.processor).(*webfinger.Module)
suite.securityModule = security.New(suite.config, suite.db).(*security.Module)

View file

@ -62,7 +62,7 @@ var Start cliactions.GTSAction = func(ctx context.Context, _ *config.Config) err
}), dbService)
federator := testrig.NewTestFederator(dbService, transportController, storageBackend)
emailSender := testrig.NewEmailSender("./web/template/")
emailSender := testrig.NewEmailSender("./web/template/", nil)
processor := testrig.NewTestProcessor(dbService, storageBackend, federator, emailSender)
if err := processor.Start(ctx); err != nil {

View file

@ -19,6 +19,7 @@
package email
import (
"bytes"
"net/smtp"
)
@ -28,12 +29,13 @@ const (
)
func (s *sender) SendConfirmEmail(toAddress string, data ConfirmData) error {
confirmBody, err := s.ExecuteTemplate(confirmTemplate, data)
if err != nil {
buf := &bytes.Buffer{}
if err := s.template.ExecuteTemplate(buf, confirmTemplate, data); err != nil {
return err
}
confirmBody := buf.String()
msg := s.AssembleMessage(confirmSubject, confirmBody, toAddress)
msg := assembleMessage(confirmSubject, confirmBody, toAddress, s.from)
return smtp.SendMail(s.hostAddress, s.auth, s.from, []string{toAddress}, msg)
}

View file

@ -18,40 +18,58 @@
package email
import (
"bytes"
"html/template"
)
// NewNoopSender returns a no-op email sender that will just execute the given sendCallback
// every time it would otherwise send an email.
//
// The 'data' parameter in the callback will be either a ConfirmData or a ResetData struct.
// every time it would otherwise send an email to the given toAddress with the given message value.
//
// Passing a nil function is also acceptable, in which case the send functions will just return nil.
func NewNoopSender(sendCallback func (toAddress string, data interface{})) Sender {
func NewNoopSender(templateBaseDir string, sendCallback func(toAddress string, message string)) (Sender, error) {
t, err := loadTemplates(templateBaseDir)
if err != nil {
return nil, err
}
return &noopSender{
sendCallback: sendCallback,
}
template: t,
}, nil
}
type noopSender struct {
sendCallback func (toAddress string, data interface{})
sendCallback func(toAddress string, message string)
template *template.Template
}
func (s *noopSender) SendConfirmEmail(toAddress string, data ConfirmData) error {
buf := &bytes.Buffer{}
if err := s.template.ExecuteTemplate(buf, confirmTemplate, data); err != nil {
return err
}
confirmBody := buf.String()
msg := assembleMessage(confirmSubject, confirmBody, toAddress, "test@example.org")
if s.sendCallback != nil {
s.sendCallback(toAddress, data)
s.sendCallback(toAddress, string(msg))
}
return nil
}
func (s *noopSender) SendResetEmail(toAddress string, data ResetData) error {
buf := &bytes.Buffer{}
if err := s.template.ExecuteTemplate(buf, resetTemplate, data); err != nil {
return err
}
resetBody := buf.String()
msg := assembleMessage(resetSubject, resetBody, toAddress, "test@example.org")
if s.sendCallback != nil {
s.sendCallback(toAddress, data)
s.sendCallback(toAddress, string(msg))
}
return nil
}
func (s *noopSender) ExecuteTemplate(templateName string, data interface{}) (string, error) {
return "", nil
}
func (s *noopSender) AssembleMessage(mailSubject string, mailBody string, mailTo string) []byte {
return []byte{}
}

View file

@ -19,6 +19,7 @@
package email
import (
"bytes"
"net/smtp"
)
@ -28,12 +29,13 @@ const (
)
func (s *sender) SendResetEmail(toAddress string, data ResetData) error {
resetBody, err := s.ExecuteTemplate(resetTemplate, data)
if err != nil {
buf := &bytes.Buffer{}
if err := s.template.ExecuteTemplate(buf, resetTemplate, data); err != nil {
return err
}
resetBody := buf.String()
msg := s.AssembleMessage(resetSubject, resetBody, toAddress)
msg := assembleMessage(resetSubject, resetBody, toAddress, s.from)
return smtp.SendMail(s.hostAddress, s.auth, s.from, []string{toAddress}, msg)
}

View file

@ -22,8 +22,6 @@ import (
"fmt"
"html/template"
"net/smtp"
"os"
"path/filepath"
"github.com/superseriousbusiness/gotosocial/internal/config"
)
@ -35,18 +33,11 @@ type Sender interface {
// SendResetEmail sends a 'reset your password' style email to the given toAddress, with the given data.
SendResetEmail(toAddress string, data ResetData) error
// ExecuteTemplate returns templated HTML using the given templateName and data. Mostly you won't need to call this,
// and can just call one of the 'Send' functions instead (which calls this under the hood anyway).
ExecuteTemplate(templateName string, data interface{}) (string, error)
// AssembleMessage concacenates the mailSubject, the mime header, mailTo, mailFrom and the mailBody in
// an appropriate format for sending via net/smtp. Mostly you won't need to call this, but it's provided just in case.
AssembleMessage(mailSubject string, mailBody string, mailTo string) []byte
}
// NewSender returns a new email Sender interface with the given configuration, or an error if something goes wrong.
func NewSender(cfg *config.Config) (Sender, error) {
t, err := loadTemplates(cfg)
t, err := loadTemplates(cfg.TemplateConfig.BaseDir)
if err != nil {
return nil, err
}
@ -67,15 +58,3 @@ type sender struct {
auth smtp.Auth
template *template.Template
}
// loadTemplates loads html templates for use in emails
func loadTemplates(cfg *config.Config) (*template.Template, error) {
cwd, err := os.Getwd()
if err != nil {
return nil, fmt.Errorf("error getting current working directory: %s", err)
}
// look for all templates that start with 'email_'
tmPath := filepath.Join(cwd, fmt.Sprintf("%semail_*", cfg.TemplateConfig.BaseDir))
return template.ParseGlob(tmPath)
}

View file

@ -28,9 +28,12 @@ type EmailTestSuite struct {
suite.Suite
sender email.Sender
sentEmails map[string]string
}
func (suite *EmailTestSuite) SetupTest() {
testrig.InitTestLog()
suite.sender = testrig.NewEmailSender("../../web/template/")
suite.sentEmails = make(map[string]string)
suite.sender = testrig.NewEmailSender("../../web/template/", suite.sentEmails)
}

View file

@ -19,8 +19,10 @@
package email
import (
"bytes"
"fmt"
"html/template"
"os"
"path/filepath"
)
const (
@ -28,16 +30,19 @@ const (
Content-Type: text/html;`
)
func (s *sender) ExecuteTemplate(templateName string, data interface{}) (string, error) {
buf := &bytes.Buffer{}
if err := s.template.ExecuteTemplate(buf, templateName, data); err != nil {
return "", err
func loadTemplates(templateBaseDir string) (*template.Template, error) {
cwd, err := os.Getwd()
if err != nil {
return nil, fmt.Errorf("error getting current working directory: %s", err)
}
return buf.String(), nil
// look for all templates that start with 'email_'
tmPath := filepath.Join(cwd, fmt.Sprintf("%semail_*", templateBaseDir))
return template.ParseGlob(tmPath)
}
func (s *sender) AssembleMessage(mailSubject string, mailBody string, mailTo string) []byte {
from := fmt.Sprintf("From: GoToSocial <%s>", s.from)
func assembleMessage(mailSubject string, mailBody string, mailTo string, mailFrom string) []byte {
from := fmt.Sprintf("From: GoToSocial <%s>", mailFrom)
to := fmt.Sprintf("To: %s", mailTo)
msg := []byte(

View file

@ -36,12 +36,10 @@ func (suite *UtilTestSuite) TestTemplateConfirm() {
InstanceName: "Test Instance",
ConfirmLink: "https://example.org/confirm_email?token=ee24f71d-e615-43f9-afae-385c0799b7fa",
}
mailBody, err := suite.sender.ExecuteTemplate("email_confirm.tmpl", confirmData)
suite.NoError(err)
suite.Equal("<!DOCTYPE html>\n<html>\n </head>\n <body>\n <div>\n <h1>\n Hello test!\n </h1>\n </div>\n <div>\n <p>\n You are receiving this mail because you've requested an account on <a href=\"https://example.org\">Test Instance</a>.\n </p>\n <p>\n We just need to confirm that this is your email address. To confirm your email, <a href=\"https://example.org/confirm_email?token=ee24f71d-e615-43f9-afae-385c0799b7fa\">click here</a> or paste the following in your browser's address bar:\n </p>\n <p>\n <code>\n https://example.org/confirm_email?token=ee24f71d-e615-43f9-afae-385c0799b7fa\n </code>\n </p>\n </div>\n <div>\n <p>\n If you believe you've been sent this email in error, feel free to ignore it, or contact the administrator of <a href=\"https://example.org\">Test Instance</a>.\n </p>\n </div>\n </body>\n</html>", mailBody)
message := suite.sender.AssembleMessage("Subject: something", mailBody, "user@example.org")
suite.Equal("Subject: something\r\nFrom: GoToSocial <GoToSocial>\r\nTo: user@example.org\r\nMIME-version: 1.0;\nContent-Type: text/html;\r\n<!DOCTYPE html>\n<html>\n </head>\n <body>\n <div>\n <h1>\n Hello test!\n </h1>\n </div>\n <div>\n <p>\n You are receiving this mail because you've requested an account on <a href=\"https://example.org\">Test Instance</a>.\n </p>\n <p>\n We just need to confirm that this is your email address. To confirm your email, <a href=\"https://example.org/confirm_email?token=ee24f71d-e615-43f9-afae-385c0799b7fa\">click here</a> or paste the following in your browser's address bar:\n </p>\n <p>\n <code>\n https://example.org/confirm_email?token=ee24f71d-e615-43f9-afae-385c0799b7fa\n </code>\n </p>\n </div>\n <div>\n <p>\n If you believe you've been sent this email in error, feel free to ignore it, or contact the administrator of <a href=\"https://example.org\">Test Instance</a>.\n </p>\n </div>\n </body>\n</html>\r\n", string(message))
suite.sender.SendConfirmEmail("user@example.org", confirmData)
suite.Len(suite.sentEmails, 1)
suite.Equal("Subject: GoToSocial Email Confirmation\r\nFrom: GoToSocial <test@example.org>\r\nTo: user@example.org\r\nMIME-version: 1.0;\nContent-Type: text/html;\r\n<!DOCTYPE html>\n<html>\n </head>\n <body>\n <div>\n <h1>\n Hello test!\n </h1>\n </div>\n <div>\n <p>\n You are receiving this mail because you've requested an account on <a href=\"https://example.org\">Test Instance</a>.\n </p>\n <p>\n We just need to confirm that this is your email address. To confirm your email, <a href=\"https://example.org/confirm_email?token=ee24f71d-e615-43f9-afae-385c0799b7fa\">click here</a> or paste the following in your browser's address bar:\n </p>\n <p>\n <code>\n https://example.org/confirm_email?token=ee24f71d-e615-43f9-afae-385c0799b7fa\n </code>\n </p>\n </div>\n <div>\n <p>\n If you believe you've been sent this email in error, feel free to ignore it, or contact the administrator of <a href=\"https://example.org\">Test Instance</a>.\n </p>\n </div>\n </body>\n</html>\r\n", suite.sentEmails["user@example.org"])
}
func (suite *UtilTestSuite) TestTemplateReset() {
@ -51,12 +49,10 @@ func (suite *UtilTestSuite) TestTemplateReset() {
InstanceName: "Test Instance",
ResetLink: "https://example.org/reset_email?token=ee24f71d-e615-43f9-afae-385c0799b7fa",
}
mailBody, err := suite.sender.ExecuteTemplate("email_reset.tmpl", resetData)
suite.NoError(err)
suite.Equal("<!DOCTYPE html>\n<html>\n </head>\n <body>\n <div>\n <h1>\n Hello test!\n </h1>\n </div>\n <div>\n <p>\n You are receiving this mail because a password reset has been requested for your account on <a href=\"https://example.org\">Test Instance</a>.\n </p>\n <p>\n To reset your password, <a href=\"https://example.org/reset_email?token=ee24f71d-e615-43f9-afae-385c0799b7fa\">click here</a> or paste the following in your browser's address bar:\n </p>\n <p>\n <code>\n https://example.org/reset_email?token=ee24f71d-e615-43f9-afae-385c0799b7fa\n </code>\n </p>\n </div>\n <div>\n <p>\n If you believe you've been sent this email in error, feel free to ignore it, or contact the administrator of <a href=\"https://example.org\">Test Instance</a>.\n </p>\n </div>\n </body>\n</html>", mailBody)
message := suite.sender.AssembleMessage("Subject: something", mailBody, "user@example.org")
suite.Equal("Subject: something\r\nFrom: GoToSocial <GoToSocial>\r\nTo: user@example.org\r\nMIME-version: 1.0;\nContent-Type: text/html;\r\n<!DOCTYPE html>\n<html>\n </head>\n <body>\n <div>\n <h1>\n Hello test!\n </h1>\n </div>\n <div>\n <p>\n You are receiving this mail because a password reset has been requested for your account on <a href=\"https://example.org\">Test Instance</a>.\n </p>\n <p>\n To reset your password, <a href=\"https://example.org/reset_email?token=ee24f71d-e615-43f9-afae-385c0799b7fa\">click here</a> or paste the following in your browser's address bar:\n </p>\n <p>\n <code>\n https://example.org/reset_email?token=ee24f71d-e615-43f9-afae-385c0799b7fa\n </code>\n </p>\n </div>\n <div>\n <p>\n If you believe you've been sent this email in error, feel free to ignore it, or contact the administrator of <a href=\"https://example.org\">Test Instance</a>.\n </p>\n </div>\n </body>\n</html>\r\n", string(message))
suite.sender.SendResetEmail("user@example.org", resetData)
suite.Len(suite.sentEmails, 1)
suite.Equal("Subject: GoToSocial Password Reset\r\nFrom: GoToSocial <test@example.org>\r\nTo: user@example.org\r\nMIME-version: 1.0;\nContent-Type: text/html;\r\n<!DOCTYPE html>\n<html>\n </head>\n <body>\n <div>\n <h1>\n Hello test!\n </h1>\n </div>\n <div>\n <p>\n You are receiving this mail because a password reset has been requested for your account on <a href=\"https://example.org\">Test Instance</a>.\n </p>\n <p>\n To reset your password, <a href=\"https://example.org/reset_email?token=ee24f71d-e615-43f9-afae-385c0799b7fa\">click here</a> or paste the following in your browser's address bar:\n </p>\n <p>\n <code>\n https://example.org/reset_email?token=ee24f71d-e615-43f9-afae-385c0799b7fa\n </code>\n </p>\n </div>\n <div>\n <p>\n If you believe you've been sent this email in error, feel free to ignore it, or contact the administrator of <a href=\"https://example.org\">Test Instance</a>.\n </p>\n </div>\n </body>\n</html>\r\n", suite.sentEmails["user@example.org"])
}
func TestUtilTestSuite(t *testing.T) {

View file

@ -50,6 +50,7 @@ type AccountStandardTestSuite struct {
transportController transport.Controller
federator federation.Federator
emailSender email.Sender
sentEmails map[string]string
// standard suite models
testTokens map[string]*gtsmodel.Token
@ -86,7 +87,8 @@ func (suite *AccountStandardTestSuite) SetupTest() {
suite.httpClient = testrig.NewMockHTTPClient(nil)
suite.transportController = testrig.NewTestTransportController(suite.httpClient, suite.db)
suite.federator = testrig.NewTestFederator(suite.db, suite.transportController, suite.storage)
suite.emailSender = testrig.NewEmailSender("../../../web/template/")
suite.sentEmails = make(map[string]string)
suite.emailSender = testrig.NewEmailSender("../../../web/template/", suite.sentEmails)
suite.accountProcessor = account.New(suite.db, suite.tc, suite.mediaHandler, suite.oauthServer, suite.fromClientAPIChan, suite.federator, suite.config)
testrig.StandardDBSetup(suite.db, nil)
testrig.StandardStorageSetup(suite.storage, "../../../testrig/media")

View file

@ -221,7 +221,7 @@ func (suite *ProcessingStandardTestSuite) SetupTest() {
suite.oauthServer = testrig.NewTestOauthServer(suite.db)
suite.mediaHandler = testrig.NewTestMediaHandler(suite.db, suite.storage)
suite.timelineManager = testrig.NewTestTimelineManager(suite.db)
suite.emailSender = testrig.NewEmailSender("../../web/template/")
suite.emailSender = testrig.NewEmailSender("../../web/template/", nil)
suite.processor = processing.NewProcessor(suite.config, suite.typeconverter, suite.federator, suite.oauthServer, suite.mediaHandler, suite.storage, suite.timelineManager, suite.db, suite.emailSender)

View file

@ -43,7 +43,7 @@ func (suite *UserStandardTestSuite) SetupTest() {
testrig.InitTestLog()
suite.config = testrig.NewTestConfig()
suite.db = testrig.NewTestDB()
suite.emailSender = testrig.NewEmailSender("../../../web/template/")
suite.emailSender = testrig.NewEmailSender("../../../web/template/", nil)
suite.testUsers = testrig.NewTestUsers()
suite.user = user.New(suite.db, suite.emailSender, suite.config)