From 56cca6be7cb3e15a99960c4e6c931081fd157d68 Mon Sep 17 00:00:00 2001 From: Corey Hulen Date: Thu, 26 May 2016 04:55:37 -0700 Subject: [PATCH] PLT-2976 Adding checkout for missing SMTP server when testing email connection (#3115) * PLT-2976 Adding checkout for missing SMTP server when testing email connection * Fixing unit test --- api/admin.go | 5 +++++ api/admin_test.go | 9 +++++++-- i18n/en.json | 4 ++++ 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/api/admin.go b/api/admin.go index 52e412976e..096235a650 100644 --- a/api/admin.go +++ b/api/admin.go @@ -184,6 +184,11 @@ func testEmail(c *Context, w http.ResponseWriter, r *http.Request) { return } + if len(utils.Cfg.EmailSettings.SMTPServer) == 0 { + c.Err = model.NewLocAppError("testEmail", "api.admin.test_email.missing_server", nil, utils.T("api.context.invalid_param.app_error", map[string]interface{}{"Name": "SMTPServer"})) + return + } + if result := <-Srv.Store.User().Get(c.Session.UserId); result.Err != nil { c.Err = result.Err return diff --git a/api/admin_test.go b/api/admin_test.go index 16ae62f7a3..2b45fd30ad 100644 --- a/api/admin_test.go +++ b/api/admin_test.go @@ -138,8 +138,13 @@ func TestEmailTest(t *testing.T) { t.Fatal("Shouldn't have permissions") } - if _, err := th.SystemAdminClient.TestEmail(utils.Cfg); err != nil { - t.Fatal(err) + if _, err := th.SystemAdminClient.TestEmail(utils.Cfg); err == nil { + t.Fatal("should have errored") + } else { + println(err.Id) + if err.Id != "api.admin.test_email.missing_server" { + t.Fatal(err) + } } } diff --git a/i18n/en.json b/i18n/en.json index dbdadfe7e1..b0b120b4ea 100644 --- a/i18n/en.json +++ b/i18n/en.json @@ -83,6 +83,10 @@ "id": "api.admin.test_email.subject", "translation": "Mattermost - Testing Email Settings" }, + { + "id": "api.admin.test_email.missing_server", + "translation": "SMTP Server is required" + }, { "id": "api.admin.upload_brand_image.array.app_error", "translation": "Empty array under 'image' in request"