Add implementation for POST /email/test apiV4 - Send Test Email (#5716)
Этот коммит содержится в:
коммит произвёл
George Goldberg
родитель
19c67d7fe3
Коммит
38958d9ac4
@@ -495,6 +495,21 @@ func CheckErrorMessage(t *testing.T, resp *model.Response, errorId string) {
|
||||
}
|
||||
}
|
||||
|
||||
func CheckInternalErrorStatus(t *testing.T, resp *model.Response) {
|
||||
if resp.Error == nil {
|
||||
debug.PrintStack()
|
||||
t.Fatal("should have errored with status:" + strconv.Itoa(http.StatusNotImplemented))
|
||||
return
|
||||
}
|
||||
|
||||
if resp.StatusCode != http.StatusInternalServerError {
|
||||
debug.PrintStack()
|
||||
t.Log("actual: " + strconv.Itoa(resp.StatusCode))
|
||||
t.Log("expected: " + strconv.Itoa(http.StatusNotImplemented))
|
||||
t.Fatal("wrong status code")
|
||||
}
|
||||
}
|
||||
|
||||
func readTestFile(name string) ([]byte, error) {
|
||||
path := utils.FindDir("tests")
|
||||
file, err := os.Open(path + "/" + name)
|
||||
|
||||
@@ -17,12 +17,29 @@ func InitSystem() {
|
||||
|
||||
BaseRoutes.System.Handle("/ping", ApiHandler(getSystemPing)).Methods("GET")
|
||||
BaseRoutes.ApiRoot.Handle("/config", ApiSessionRequired(getConfig)).Methods("GET")
|
||||
BaseRoutes.ApiRoot.Handle("/email/test", ApiSessionRequired(testEmail)).Methods("POST")
|
||||
}
|
||||
|
||||
func getSystemPing(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
ReturnStatusOK(w)
|
||||
}
|
||||
|
||||
func testEmail(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
if !app.SessionHasPermissionTo(c.Session, model.PERMISSION_MANAGE_SYSTEM) {
|
||||
c.SetPermissionError(model.PERMISSION_MANAGE_SYSTEM)
|
||||
return
|
||||
}
|
||||
|
||||
err := app.TestEmail(c.Session.UserId, utils.Cfg)
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
}
|
||||
|
||||
ReturnStatusOK(w)
|
||||
}
|
||||
|
||||
func getConfig(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
if !app.SessionHasPermissionTo(c.Session, model.PERMISSION_MANAGE_SYSTEM) {
|
||||
c.SetPermissionError(model.PERMISSION_MANAGE_SYSTEM)
|
||||
|
||||
@@ -5,6 +5,7 @@ import (
|
||||
"testing"
|
||||
|
||||
"github.com/mattermost/platform/model"
|
||||
"github.com/mattermost/platform/utils"
|
||||
)
|
||||
|
||||
func TestGetPing(t *testing.T) {
|
||||
@@ -64,3 +65,32 @@ func TestGetConfig(t *testing.T) {
|
||||
t.Fatal("did not sanitize properly")
|
||||
}
|
||||
}
|
||||
|
||||
func TestEmailTest(t *testing.T) {
|
||||
th := Setup().InitBasic().InitSystemAdmin()
|
||||
defer TearDown()
|
||||
Client := th.Client
|
||||
|
||||
SendEmailNotifications := utils.Cfg.EmailSettings.SendEmailNotifications
|
||||
SMTPServer := utils.Cfg.EmailSettings.SMTPServer
|
||||
SMTPPort := utils.Cfg.EmailSettings.SMTPPort
|
||||
FeedbackEmail := utils.Cfg.EmailSettings.FeedbackEmail
|
||||
defer func() {
|
||||
utils.Cfg.EmailSettings.SendEmailNotifications = SendEmailNotifications
|
||||
utils.Cfg.EmailSettings.SMTPServer = SMTPServer
|
||||
utils.Cfg.EmailSettings.SMTPPort = SMTPPort
|
||||
utils.Cfg.EmailSettings.FeedbackEmail = FeedbackEmail
|
||||
}()
|
||||
|
||||
utils.Cfg.EmailSettings.SendEmailNotifications = false
|
||||
utils.Cfg.EmailSettings.SMTPServer = ""
|
||||
utils.Cfg.EmailSettings.SMTPPort = ""
|
||||
utils.Cfg.EmailSettings.FeedbackEmail = ""
|
||||
|
||||
_, resp := Client.TestEmail()
|
||||
CheckForbiddenStatus(t, resp)
|
||||
|
||||
_, resp = th.SystemAdminClient.TestEmail()
|
||||
CheckErrorMessage(t, resp, "api.admin.test_email.missing_server")
|
||||
CheckInternalErrorStatus(t, resp)
|
||||
}
|
||||
|
||||
Ссылка в новой задаче
Block a user