From 4752a5b8e0a34a0f348eee582372d5a673d024c2 Mon Sep 17 00:00:00 2001 From: Julien Tant <785518+JulienTant@users.noreply.github.com> Date: Thu, 9 Feb 2023 09:37:40 -0700 Subject: [PATCH] [MM-50080] Limit max length for the name field (#22282) --- app/work_templates.go | 6 ++++++ app/work_templates_test.go | 8 ++++++++ i18n/en.json | 4 ++++ 3 files changed, 18 insertions(+) diff --git a/app/work_templates.go b/app/work_templates.go index 5ff8abe14e..5a748b2c2c 100644 --- a/app/work_templates.go +++ b/app/work_templates.go @@ -68,6 +68,12 @@ func (a *App) executeWorkTemplate( ChannelIDs: []string{}, } + if wtcr.Name != "" { + if len(wtcr.Name) > model.ChannelNameMaxLength { + return res, model.NewAppError("ExecuteWorkTemplate", "app.worktemplates.execute_work_template.name_too_long", nil, "", http.StatusBadRequest) + } + } + contentByType := map[string][]model.WorkTemplateContent{ "channel": {}, "board": {}, diff --git a/app/work_templates_test.go b/app/work_templates_test.go index 5f3ce83296..f5761c3a2b 100644 --- a/app/work_templates_test.go +++ b/app/work_templates_test.go @@ -4,6 +4,8 @@ package app import ( + "net/http" + "strings" "testing" "time" @@ -228,4 +230,10 @@ func TestExecuteWorkTemplate(t *testing.T) { executorMock.AssertExpectations(t) }) + t.Run("with name too long", func(t *testing.T) { + req.Name = strings.Repeat("a", model.ChannelNameMaxLength+1) + _, appErr := th.App.executeWorkTemplate(c, req, nil, false) + assert.NotNil(t, appErr) + assert.Equal(t, http.StatusBadRequest, appErr.StatusCode) + }) } diff --git a/i18n/en.json b/i18n/en.json index 11e34e5cfb..dd65c2cbfd 100644 --- a/i18n/en.json +++ b/i18n/en.json @@ -7127,6 +7127,10 @@ "id": "app.worktemplates.execute_work_template.channels.create_error", "translation": "Error while creating a channel." }, + { + "id": "app.worktemplates.execute_work_template.name_too_long", + "translation": "The name field cannot contain more than 64 characters." + }, { "id": "app.worktemplates.execute_work_template.playbooks.create_error", "translation": "Error while creating a playbook."